5

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.

Celeritas
  • 2,839
  • 7
  • 37
  • 62

3 Answers3

4

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
Carl Love
  • 1,193
  • In A:= rsolve({a(n)=2*a(n-1)+3*a(n-2), a(0)=1, a(1)=2}, a(n), makeproc): why do you have : instead of ; at the end? Also what difference does it make that the second argument is a(n) instead of just a? – Celeritas Dec 01 '13 at 01:19
  • The colon at the end of a command is to suppress the printed output of that command. Using a or a(n) as the second argument makes no difference as far as I can tell. I was not aware that it could be abbreviated to a. – Carl Love Dec 01 '13 at 03:25
  • This only works the first time. See edit to question. – Celeritas Dec 02 '13 at 08:24
  • You've probably made an assignment to one of the variables involved in the problem. I can't diagnose further without seeing your code. – Carl Love Dec 02 '13 at 18:03
  • 1
    Is it Maple able to solve this recurrence https://mathematica.stackexchange.com/questions/140338/how-to-solve-this-multivariate-recurrence-with-mathematica not solved by Mathematica? – skan Mar 18 '17 at 13:08
  • Maple cannot solve recurrences with more than one independent variable. – Carl Love Mar 26 '20 at 06:32
3

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.

BIS HD
  • 2,668
  • You're missing a big part of what I was trying to ask. How can I plug in just one number, for example how would I do a(3)? I already red the link and I don't think it's right because the defines an "equation" and in Maple you can't plug values into an equation, only "functions". But what do I know I'm just learning. – Celeritas Nov 30 '13 at 10:50
  • 1
    @Celeritas Sorry, I assumed that you know how to evaluate a function in Maple ;-) Edited my post. – BIS HD Nov 30 '13 at 10:58
  • This only works the first time. See edit to question. – Celeritas Dec 02 '13 at 08:24
  • @Celeritas My answer is right to your question. If you extend the question, my answer is still right. ;-) Anynway, why don't you just rename the second a(n) to b(n) or rename the eqn1 to eqn2 and so on? – BIS HD Dec 02 '13 at 10:27
  • So I need to rename both $eqn1$ and $a(n)$? The reason I'm suppressed is because I didn't realize we were actually defining $a(n)$ permanently since we didn't use the $:=$ operator. – Celeritas Dec 02 '13 at 11:05
  • If you face any problems with names, I suggest you to rename everything. – BIS HD Dec 02 '13 at 13:31
0

Here is a shorter version:

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