### 5.14.3 Values of a recurrence relation or a system: rsolve

See also section 5.14.2

The rsolve command takes three arguments; an equation or list of equations that define a recurrence relation, the functions (with their variables) used, and equations for the starting values. For example, if a recurrence relation is defined by un+1 = f(un,n) with u0 = a, the arguments to rsolve will be u(n+1) = f(u(n),n), u(n) and u(0)=a. The recurrence relation must either be a homogeneous linear part with a nonhomogeneous part being a linear combination of polynomials in n times geometric terms in n (such as un+1 = 2 un + n 3n), or a linear fractional transformation (such as un+1 = (un−1)/(un−2)).
rsolve returns a matrix whose rows are the values of the sequence as functions of n.

Note that rsolve is more flexible than seqsolve since:

- the sequence doesn’t have to start with u0.
- the sequence can have several starting values, such as initial condition u02 = 1, which is why rsolve returns a list.
- the notation for the recurrence relation is similar to how it is written in mathematics.

Examples:

- To find un, given that un+1 = 2un + n and u0=3: Input:
  rsolve(u(n+1) = 2*u(n) + n, u(n), u(0)=3)
  Output:
  [-n+4*2^n-1]
- To find un, given that un+1 = 2un + n and u12 = 1: Input:
  rsolve(u(n+1) = 2*u(n) + n, u(n), u(1)^2 = 1)
  Output:
  [-n+3/2*2^n-1,-n+1/2*2^n-1]
- To find un, given that un+1 = 2un + n 3n and u0=3: Input:
  rsolve(u(n+1) = 2*u(n) + n*3^n,u(n), u(0)=3)
  Output:
  [n*3^n+6*2^n-3*3^n]
- To find un, given that un+1 = (un − 1)/(un −2) and u0 = 4:
  Input:
  rsolve(u(n+1) = (u(n)-1)/(u(n)-2),u(n), u(0)=4)
  Output:
  [((10*sqrt(5)+30)*((sqrt(5)-3)/2)^n+30*sqrt(5)-70)/(20*((sqrt(5)-3)/2)^n+10*sqrt(5)-30)]
- To find un given that un+1 = un + un−1 with u0 = 0, u1=1:
  Input:
  rsolve(u(n+1) = u(n) + u(n-1), u(n), u(0) = 0, u(1) = 1)
  Output:
  [(-sqrt(5)/5)*((-sqrt(5)+1)/2)^n+sqrt(5)/5*((sqrt(5)+1)/2)^n]
- To find un and vn, given that un+1=un + vn, vn+1 = un − vn with u0 = 0, v0 = 1:
  Input:
  rsolve([u(n+1) = u(n) + v(n), v(n+1) = u(n) - v(n)], [u(n),v(n)], [u(0)=1, v(0)=1])
  Output:
  [[(-sqrt(2)+1)/2*(-sqrt(2))^(n+1-1)+(sqrt(2)+1)/2*2^(1/2*(n+1-1)),
  1/2*(-sqrt(2))^(n+1-1)+1/2*2^(1/2*(n+1-1))]]