Solving recurrence relation using Mathematica
-
27-10-2019 - |
Question
Good evening, experts
I want to solve recurrence equation using mathematica,
x(n) = x(n − 1) + n
for n > 0,
x(0) = 0
And i need to find x(1), x(2), x,(3)
This is my input and it gives me errors
n > 0
a[0] := 0
RSolve[x == a[n - 1] + n, a[n], n]
How can I rewrite the equation using the mathematica? Thanks in advance
Solution
An example of this very pattern is the 2nd example in the documentation for RSolve:
Include a boundary condition:
In[1]:= RSolve[{a[n + 1] - 2 a[n] == 1, a[0] == 1}, a[n], n] Out[1]= {{a[n] -> -1 + 2^(1 + n)}}
For your problem, that'd be:
In[1]:= RSolve[{a[n] == a[n - 1] + n, a[0] == 0}, a[n], n]
Out[1]= {{a[n] -> 1/2 n (1 + n)}}
OTHER TIPS
Simply use
RSolve[{a[n] == a[n - 1] + n, a[0] == 0}, a[n], n]
Remove the following:
n > 0
a[0] := 0
a[0] := 0
is a function definition. a
must not have associated definitions in order to work in RSolve
If you want to find x(1), x(2), x(3), you can use RecurrenceTable
:
RecurrenceTable[{x[n] == x[n - 1] + n, x[0] == 0}, x[n], {n, 3}]
{0,1,3,6}
x(1)=1, x(2)=3, x(3)=6
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow