# RSolve - basic question about using rules as functions

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 == 82, a == 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 returns its value at 3?

• Look up /..${}$ – J. M. will be back soon Apr 2 '16 at 16:52
• I need whole function, because I need to use it for more values in loop? – Meow Apr 2 '16 at 16:53
• Yes, so did you look up /. as well as the docs for RSolve[]? – J. M. will be back soon Apr 2 '16 at 16:55
• (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. – kglr Apr 2 '16 at 16:57
• @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? – Meow Apr 2 '16 at 17:06

ClearAll[f,a,n]
(* solve for a instead of a[n] *)
soln = RSolve[{a[n + 2] - 12542 a[n + 1] + a[n] == 0, a == 82,
a == 1028302}, a, n];
(* assign to f if you wish *)
f = a /. First@soln;
(* use f *)
f[3.]


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 = v[];
a = v[];

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