Tag Info

New answers tagged

1

With your definition, you have yhat[1] u[1] - f2 yhat[-1] - f1 yhat[0] But you haven't defined yhat for negative numbers! The function then jumps the termination clause and would go to -Infinityif it weren't for $RecursionLimit. You can fix it by applying the recursion clause only to positive numbers Clear[yhat]; yhat[n_?Positive] := -f1 yhat[n - ...


3

Could it be that you're looking for the function Fold rather than Nest? Fold[f[n - #2, #1] &, a, Range[5]] f[-5 + n, f[-4 + n, f[-3 + n, f[-2 + n, f[-1 + n, a]]]]]


1

Last @ Nest[{ #[[1]] - 1, f1[ ff[ #[[1]], #[[2]] ] ] } &, {n, list}, 3] f1[ff[-2 + n, f1[ff[-1 + n, f1[ff[n, list]]]]]]


3

Here's general approach, which I primarily show in order to give an answer that includes the Neville-Aitken algorithm. It peculiarly works from the bottom of the triangle up, that is $T_k^{(n)}$ or t[k, n] are generated in the order shown in the table: One of the distinctions to make clear is whether the function $f$ in the recursion ...


1

One thing to look into to better understand MMA programming is how to define functions with variable arity (number of arguments). The normal way to define a function of x is f[x_]:=.... Functions of two variables are f[x_,y_]:=... etc. However when you don't know the number of arguments beforehand you can use __ (two underscores) and ___ (three underscores) ...


10

In this answer, I will use the Functional Paradigm to deal with triangular recursive formula in a uniform manner. For the triangular recursive formula $$T_k^{(n)}=f(T_{k-1}^{(n)},T_{k-1}^{(n+1)})$$ In general, $f(x)=a x+b$, so the triangular recurisive formula can be denoted as below: $$T_k^{(n)}=\alpha(k,n) T_{k-1}^{(n)}+\beta(k,n)T_{k-1}^{(n+1)}$$ ...


1

You want to find the value of n for which a[n] == 17160 Clear[a]; a[n_] = a[n] /. RSolve[{a[n + 1] == (n + 1)*a[n], a[10] == 10}, a[n], n][[1]] Pochhammer[1, n]/362880 LogPlot[{a[n], 10, 17160}, {n, 1, 14}] FindRoot[a[n] == 17160, {n, 12}] {n -> 13.} a[13] 17160


6

The problem The main problem seems that you have been using exact numbers for computations, since your delta is de facto an exact number. This led to generation of very large symbolic expressions, which also contributed to the slow-down. To solve this, one simply needs to use numerical values from the start, increasing precision if needed. So, you can ...


3

Here is a way using delayed evaluation and recursive pure function. It allows to only use one variable: ClearAll[var]; var := Function[Null, With[{res = ! #2}, # := #0[#, res]; res], HoldFirst][var, False] So that: var (* True *) var (* False *) var (* True *)


12

flip = True; var := flip = Not[flip] var (*False*) var (*True*) var (*False*)


2

josephus[nu_, list_] := NestList[Rest@RotateLeft[#, nu - 1] &, list, Length[list] - 1] josephus[6, Range[15]] (* {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5}, {13, 14, 15, 1, 2, 3, 4, 5, 7, 8, 9, 10, 11}, {4, 5, 7, 8, 9, 10, 11, 13, 14, 15, 1, 2}, {11, 13, 14, 15, 1, 2, 4, 5, 7, 8, 9}, {4, ...


3

g[list_, incr_] := Module[{i = 1}, NestWhileList[ Delete[#, i = Mod[i+incr-1, Length@#, 1]] &, list, Length@# > 1 &]] g[Range@15, 6] // Column (*{ {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 13, 14, 15}, {1, 2, 4, 5, 7, 8, 9, 10, 11, ...


4

Let's find out if I understand the problem and if this works: fn[nu_][{o_, a_}] := {# - 1, Delete[a, #]} & @ Mod[nu + o, Length@a, 1] NestList[fn[6], {0, Range@15}, 14][[All, 2]] // Column {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15} {1,2,3,4,5,7,8,9,10,11,12,13,14,15} {1,2,3,4,5,7,8,9,10,11,13,14,15} {1,2,4,5,7,8,9,10,11,13,14,15} ...


0

I wrote my thesis "Implementation of an algorithm for verifying the non-negativity of a multilinear function in a hypercube" about this here (password is "sal" and username "sal"). The key algorithm is not specified in the publication, focusing only on the key implementation idea with the hypercubes -- this was a requirement by my instructor. Shortly I ...


0

One way to approach this is to write the equation recursively: a[n_] := a[n] = (1 + a[n - 1] + a[n - 2]^3)/3; a[1] = a1; a[0] = a0; This leaves the initial conditions in terms of two generic parameters a0 and a1. For example, a[3] gives 1/3 (1 + a1^3 + 1/3 (1 + a0^3 + a1)) FullSimplify[a[4]] is: 1/81 (27 + (1 + a0^3 + a1)^3 + 3 (4 + a0^3 + a1 + 3 ...


2

In my process of learning, I am always encountering many recursive formular. The answer as shown below is my summarization about dealing with these recursive formular in Mathematica's functional paradigm. For the general formular $$a_{n+1}=func(a_{n-1},a_n)$$ you can use the a general solution # & @@@NestList[{#2, $func$[#1,#2]} & @@ # &, ...


2

Not paticularly elegant for reading but with minimal programming effort we can write f[0] = a; f[1] = b; f[k_] := HoldForm[f[k - 1] + f[k - 2]] ff[n_] := NestList[ReleaseHold, f[n], n - 1] Example ff[7] // Column $\begin{array}{l} f[7-1]+f[7-2] \\ (f[5-1]+f[5-2])+(f[6-1]+f[6-2]) \\ (f[3-1]+f[3-2])+2 (f[4-1]+f[4-2])+(f[5-1]+f[5-2]) \\ b+3 ...



Top 50 recent answers are included