# Tag Info

4

You don't need to loop, you can just do the recursion directly: Clear[y, f, g, h]; y[0, x_] := x; y[n_, x_] /; 0 <= x < a1 := f[n, x]; y[n_, x_] /; a1 <= x <= a2 := g[n, x]; y[n_, x_] := h[n, x]; f[n_, x_] := b1 y[n - 1, x/a1]; g[n_, x_] := (b2 - b1) y[n - 1, (x - a1)/(a2 - a1)] + b1; h[n_, x_] := (1 - b2) y[n - 1, (x - a2)/(1 - a2)] + b2; The ...

0

I am very late to this but another (not very pretty) interative approach: f[n_] := First@Nest[{#[[2]], Join[#[[2]], #[[1]]]} &, {{1}, {1, 0}}, n] It handles f[0] and f[1] automatically...

0

This number is amazing. When it comes to Fibonacci, we cannot get rid of golden ratio. Just compare the count of zeros and ones: Remove[fibjoin] fibjoin[1]={1}; fibjoin[2] = {1,0}; fibjoin[n_] := fibjoin[n] = Join[fibjoin[n-1], fibjoin[n-2]] N@Table[Count[fibjoin[k],0]/Count[fibjoin[k],1] , {k,1,20}]

5

Here is an iterative approach: f1 = Flatten @ Nest[{#, #[[1]]} &, {1, 0}, # - 1] &; f1 @ 5 {1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0} I find this nice and clean, but it doesn't handle a zero argument, and it's not particularly efficient. Here is a variation to address both points: f2 = First @ Nest[{Join @@ #, #[[1]]} &, ...

1

Pluto[n_Integer] := Block[{s1 = {1}, s2 = {1, 0},s3 = {}}, {Table[{s3 = {s2, s1} // Flatten, s1 = s2, s2 = s3}, {n}]}; s3] Call as Pluto[4] {1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0}

13

It is so-called Rabbit sequence. One can notice that at each step $$0 \to 1, \quad 1 \to 10.$$ The substitution $0\to1$ corresponds to young rabbits growing old, and $1\to10$ corresponds to old rabbits producing young rabbits. fib[n_] := Nest[Flatten[# /. {0 -> {1}, 1 -> {1, 0}}] &, {1}, n] fib[5] (* {1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0} *) ...

2

If you want a Do-based solution: Block[{a = {1, 0}, b = {1}, n = 5}, Do[ {a, b} = {a~Join~b, a}, {n - 1}]; a] will return the nth term, for n >= 1. (I'm feeling too lazy to package this into a function, but you can do that.)

12

Why not just use a recursive definition like you would for a regular Fibonnaci function? ClearAll[fibjoin] fibjoin[0] = {1}; fibjoin[1] = {1, 0}; mem : fibjoin[n_] := mem = Join[fibjoin[n - 1], fibjoin[n - 2]] fibjoin[5] (* {1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0} *)

2

Using @ubpdqn's answer for getting a closed expression for the dependence of the integral on the dimension n. vol[n_] := vol[n] = FullSimplify[Nest[Integrate[# /. r -> Sqrt[r^2 - x^2], {x, -r, r}] &, 2 r, n], Element[r, Reals] && r > 0] ...

5

Edit You changed your equations after accepting this answer. The same method works: First we modify your functions to get some speed: Y1[0] = 2 + r; Y2[0] = 4 - r; Y3[0] = 2 + r; Y4[0] = 4 - r; Y1[k_] := Y1[k] = FullSimplify[(k - 1)!/(k!)*(Y3[k - 1])]; Y2[k_] := Y2[k] = FullSimplify[(k - 1)!/(k!)*(Y4[k - 1])]; Y3[k_] := Y3[k] = FullSimplify[(k - ...

1

Are you not satisfied with difference root objects? I think that @belisarius has given the most general solution. If you want to give your sequence values and see how it behaves there's no reason to use RSolve. You can define the n-th term recursively and build the sequence from the bottom up (in what follows, I changed l to q): ClearAll[a, g, data, data2, ...

1

EDIT In the following the role of f and g have been inadvertently exchanged,i.e. $f(n)=f(n-1)^2+2 g(n-1)^2$ and $g(n)=2 f(n-1)g(n-1)$ Therefore, just exchange. The values can be obtained by defining the recursive functions with suitable starting values for f and g. I present alternatives. It is relatively straightforward to uncouple the relations: ...

5

After a change of Variable s[k_]:= s[k]= RSolve[{a[p + m] == ((1 + p) (m + 2 p a[p] + p (-1 + m + p) a[-1 + m + p]))/(m + p) /. m -> k, Sequence @@ Array[a@# == 0 &, k - 1, 0]}, a, p] Which give DifferenceRoot solutions. So: Grid[Table[a[n] /. s[m][[1]], {n, 1, 5}, {m, 1, 5}]] /. C[1] -> 0 Gives the same table as in ...

1

Rest on a list gives you another list. Even Rest[{1}] gives you a list, i.e. the empty list {}. Therefore, in your first code, the second term with the rest in it will always make another call using the definition for mus[x__], which produces another second term, which makes at another call to mus[x__] ad infinitum. Maybe you were thinking of a function ...

2

This is not an analytic solution of the recurrence. I generate a table based on the recurrence relation (if I interpret it correctly). I have change l to m as difficult to discriminate from one. If the values are wrong I have obviously made an error but perhaps can motivate other approaches. f[m_, n_, mat_] := 1/n(1 - m + n) (m + (-1 + n) (-m + n) mat[[m, ...

Top 50 recent answers are included