# Values of a recurrence relation or a system: seqsolve

### 5.13.2 Values of a recurrence relation or a system: seqsolve

(See also Section 5.13.3.)

The seqsolve command finds the terms of a recurrence relation.

- seqsolve takes three arguments:
  - exprs, an expression or list of expressions that define the recurrence relation.
  - vars, a list of the variables used.
  - a, the starting value.
- seqsolve(exprs,vars,a) returns a formula for the nth term of the sequence.

For example, if a recurrence relation is defined by un+1 = f(un,n) with u0 = a, the arguments to seqsolve will be f(x,n), [x,n] and a. If the recurrence relation is defined by un+2 = g(un,un+1,n) with u0 = a and u1 = b, the arguments to seqsolve will be g(x,y,n), [x,y,n] and [a,b].

The recurrence relation must have a homogeneous linear part, the nonhomogeneous part must be a linear combination of a polynomials in n times geometric terms in n.

#### Examples.

- Find un, given that un+1 = 2un + n and u0=3.
  Input:
  seqsolve(2x+n,[x,n],3)
  Output:

  −n−1+4· 2n

- Find un, given that un+1 = 2un + n 3n and u0=3.
  Input:
  seqsolve(2x+n*3^n,[x,n],3)
  Output:

  ⎛ ⎝ | n−3 | ⎞ ⎠ | · 3n+6· 2n

- Find un, given that un+1 = un + un−1, u0 = 0 and u1=1.
  Input:
  seqsolve(x+y,[x,y,n],[0,1])
  Output:

  5

  ⎛
  ⎜
  ⎜
  ⎝

  −

  √

  5

  +1

  2

  ⎞
  ⎟
  ⎟
  ⎠

  n

  −4

  ⎛
  ⎜
  ⎜
  ⎝

  −

  √

  5

  +1

  2

  ⎞
  ⎟
  ⎟
  ⎠

  n

  √

  5

  −5

  ⎛
  ⎜
  ⎜
  ⎝

  −

  √

  5

  +1

  2

  ⎞
  ⎟
  ⎟
  ⎠

  n

  +5

  ⎛
  ⎜
  ⎜
  ⎝

  √

  5

  +1

  2

  ⎞
  ⎟
  ⎟
  ⎠

  n

  +4

  ⎛
  ⎜
  ⎜
  ⎝

  √

  5

  +1

  2

  ⎞
  ⎟
  ⎟
  ⎠

  n

  √

  5

  −5

  ⎛
  ⎜
  ⎜
  ⎝

  √

  5

  +1

  2

  ⎞
  ⎟
  ⎟
  ⎠

  n

  20

- Find un and vn, given that un+1=un + 2vn, vn+1 = un + n + 1 with u0 = 1, v0 = 1.
  Input:
  seqsolve([x+2*y,n+1+x],[x,y,n],[0,1])
  Output:

  ⎡
  ⎢
  ⎢
  ⎣

  −2 n− | ⎛ ⎝ | −1 | ⎞ ⎠ | n+4· 2n−3

  2

  ,

  ⎛ ⎝ | −1 | ⎞ ⎠ | n+2· 2n−1

  2

  ⎤
  ⎥
  ⎥
  ⎦