0
$\begingroup$

I think this is basic question, but I can't find it in Help... (I am begginer :P)

I have this expression RSolve[{a[n + 2] - 12542 a[n + 1] + a[n] == 0, a[0] == 82, a[1] == 1028302}, a[n], n]

and it returns list with solution as rule a[n]-> etc How do I use and evaluate this function? I need it do that a[3] returns its value at 3?

$\endgroup$
  • $\begingroup$ Look up /..${}$ $\endgroup$ – J. M. will be back soon Apr 2 '16 at 16:52
  • $\begingroup$ I need whole function, because I need to use it for more values in loop? $\endgroup$ – Meow Apr 2 '16 at 16:53
  • $\begingroup$ Yes, so did you look up /. as well as the docs for RSolve[]? $\endgroup$ – J. M. will be back soon Apr 2 '16 at 16:55
  • $\begingroup$ (1) Use soln=RSolve[...]; a[n]/. soln /. n->3 or (2) Change the second argument of RSolve to a (instead of a[n]) to get a pure function and use a[3]. $\endgroup$ – kglr Apr 2 '16 at 16:57
  • $\begingroup$ @kglr Thank you, it worked for me, but value is in braces, as part of list. How could I have it without being part of list, (I set` f[n_]=a[n] /. soln` and for f[0.] I got {82.}. How could I get values without braces? $\endgroup$ – Meow Apr 2 '16 at 17:06
3
$\begingroup$
ClearAll[f,a,n]
(* solve for `a` instead of `a[n]` *)
soln = RSolve[{a[n + 2] - 12542 a[n + 1] + a[n] == 0, a[0] == 82, 
    a[1] == 1028302}, a, n];
(* assign to `f` if you wish *)
f = a /. First@soln;
(* use `f` *)
f[3.]
$\endgroup$
1
$\begingroup$

I only post this as RSolve does provide the desired formula but application produces expressions with radicals that require simplification. As this is a linear recursive relation it may be simpler to just produce values recursively, e.g.

m = {{12542, -1}, {0, 1}};
v = {1028302, 82};
a[0] = v[[2]];
a[1] = v[[1]];

a[n_?(# > 1 &)] := First@MatrixPower[m, n - 1].v;
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.