How to define a recurrence relation in Maple?

6.5k Views Asked by At

I'm new with Maple and want to define a recurrence relation. I want to 1) have Maple solve it to the explicit formula 2)have Maple output a few evaluations of it for various values of n

For example if I have $a_n=2a_{n-1}+3a_{n-2}$ with $a_0=1$ and $a_1=2$ how would I use Maple to solve for an explicit formula and output the evaluated $a_1, a_2, a_3, a_4$?

In terms of Maple commands, do I want to define a function or does a recurrence sequence have it's on "type"? I know I want to use rsolve but I haven't got the commands right. Could someone please give me an example?

EDIT: the given solutions don't seem to work if you do a second recurrence realtion, that is having $a(n)$ equal to something else and try solving it.

2

There are 2 best solutions below

6
On BEST ANSWER

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
6
On

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.