How to define a recurrence relation in Maple?

You have to define the recurrence relation, for example:

eqn1 $:=a(n) = 2*a(n-1) + 3*a(n-2);$

Then you have to give the initial values:

init1 $:=a(0)=1,a(1)=2;$

Then use rsolve to solve it for $a$:

soln1[n]:=rsolve({eqn1,init1},a);

If you want to evaluate the solution for $n = 1,2,3,4$, then just write (for example, $n=4$)

eval(soln1[n], $n=4$);

Here is a reference sheet if you have further questions. Hope, that helped.


What you want is the makeproc option to rsolve.

A:= rsolve({a(n)=2*a(n-1)+3*a(n-2), a(0)=1, a(1)=2}, a(n), makeproc):

A(n);

                     1     n   3  n
                     - (-1)  + - 3 
                     4         4   

'A(n)' $ n= 1..4;

                      2, 7, 20, 61