# Tag Info

## New answers tagged recursion

5

This sort of thing is handled by RSolve. RSolve[{f[n] - 2 f[n - 1] - 1 == 0, f[1] == 1}, f[n], n] (* Out[115]= {{f[n] -> -1 + 2^n}} *)

5

f[x_] := If[x > 1, 2*f[x - 1] + 1, 1]; f[#] & /@ {1, 2, 3, 4, 5, 6, 7, 8, 9} (* {1, 3, 7, 15, 31, 63, 127, 255, 511} *) FindSequenceFunction[{1, 3, 7, 15, 31, 63, 127, 255, 511}] (* -1 + 2^#1 & *) The above is the inferred expression uses all the information of the recursive definition and can be written $f(j) = -1 + 2^j$. Check: -1 + ...

7

Just as a quick an dirty start, I would try this: $maxStep = 3; (* or what you believe necessary *)$eps = 0.001; (* some limit to tell that l and m are now sufficiently close *) ClearAll[f]; f[l_, m_, d_, $maxStep ] = l / (l + d); (* end by maxStep *) f[l_, leps_, d_, _ ] /; l <= leps < l +$eps = l / (l + d) (* end by l approx equal m *) ...

1

Try Code: ClearAll["Global`*"] RSolve[{f[n + 1] == f[n] + 2 n + 1, f[1] == -3}, f[n], n] Output: {{f[n] -> -4 + n^2}}

7

You can get it through Compile as below. Note that I have not tested for correctness. myFncC = Compile[{{X, _Real, 2}}, Block[ {n, val}, n = Length[X]; If[n == 1, Return[{2., 1.}]]; val = Total[ Table[ Block[ {XmT = Total[X[[1 ;; m]]], XmnT = Total[X[[m + 1 ;; n]]], mFm = myFncC[X[[1 ;; m]]], mFmn = myFncC[X[[m ...

Top 50 recent answers are included