solveRecurrence
Description
Examples
Find the solution of the recurrence relation for the gamma function.
Create a symbolic function f(n) and a symbolic equation eqn to represent the recurrence relation.
syms f(n)
eqn = f(n) == n*f(n-1);Find the solution. The result is the gamma function with a constant multiplier.
sol = solveRecurrence(eqn,f)
sol =
Create a symbolic function f(n) and a symbolic equation eqn to represent the recurrence relation for the Fibonacci and Lucas sequences.
syms f(n)
eqn = f(n) == f(n-1) + f(n-2)eqn =
Specify the initial conditions for the Fibonacci sequence.
cond = [f(0) == 0, f(1) == 1]
cond =
Solve the recurrence relation using these initial conditions.
sol = solveRecurrence(eqn,f,cond)
sol =
Find the 10th Fibonacci number.
sol10 = simplify(subs(sol,n,10))
sol10 =
Next, specify the initial conditions for the Lucas sequence.
cond = [f(0) == 2, f(1) == 1]
cond =
Solve the recurrence relation using these initial conditions.
sol = solveRecurrence(eqn,f,cond)
sol =
Find the 10th Lucas number.
sol10 = simplify(subs(sol,n,10))
sol10 =
Create a system of linear recurrence relations.
syms a(n) b(n) eqn = [a(n+1) == a(n) + 2*b(n); ... b(n+1) == 3*a(n) + b(n)]
eqn =
Specify the initial conditions for the functions a(0) and b(0).
cond = [a(0) == 2; b(0) == 3]
cond =
Solve the system of recurrence relations using these initial conditions.
sol = solveRecurrence(eqn,[a b],cond)
sol =
Check if the solutions for a(n) and b(n) satisfy the recurrence relations. Substitute [a; b] with sol, and use isAlways to determine if both sides of the recurrence relations are equal.
tf = isAlways(subs(eqn,[a; b],sol))
tf = 2×1 logical array
1
1
Check if the solutions also satisfy the initial conditions.
tf = isAlways(subs(cond,[a; b],sol))
tf = 2×1 logical array
1
1
Create a recurrence relation for the Bessel functions.
syms J(n) z eqn = J(n+1) == 2*n/z*J(n) - J(n-1)
eqn =
Specify the initial conditions using the Bessel function of the first kind.
cond = [J(0) == besselj(0,z); J(1) == besselj(1,z)]
cond =
solveRecurrence cannot always solve recurrence relations with variable coefficients. In this case, the function returns an unevaluated call.
sol = solveRecurrence(eqn,J,cond)
sol =
However, if you substitute a specific value for the indexing parameter into the solution, the solver might be able to return an analytic solution. For example, substitute . The analytic solution is in terms of the variable and the initial conditions and .
soln4 = subs(sol,n,4)
soln4 =
Check if this solution is equal to the Bessel function of the first kind of order 4.
tf = isAlways(soln4 == besselj(4,z))
tf = logical
1
Input Arguments
Recurrence relations to solve, specified as a symbolic equation or vector of symbolic equations. The symbolic equations must contain symbolic functions that depend on a single indexing parameter, or the function argument must have only one independent variable.
The solveRecurrence function consistently solves symbolic
equations that define a system of linear recurrence relations with constant
coefficients. In some cases, solveRecurrence can also solve linear
recurrence relations with nonconstant coefficients or a system of nonlinear recurrence
relations.
Example: syms f(n); eqn = f(n) == 3*f(n-1) - f(n-2)
Example: syms f(n); eqn = f(n+1)*f(n) == 2*f(n) + 1
Functions to solve for, specified as a symbolic function or vector of symbolic functions.
Initial conditions, specified as a symbolic equation or vector of symbolic equations.
Output Arguments
Solution of the recurrence relations, returned as a symbolic expression or vector of symbolic expressions.
If the solveRecurrence function cannot solve the recurrence
relations, then it returns an unevaluated call.
More About
Recurrence relations are equations that relate the next term in a sequence to the previous terms in the sequence . These relations contain functions that depend on an indexing parameter .
The solveRecurrence function solves in linear recurrence relations (or linear difference equations) with
constant coefficients that have the form
This form is considered homogeneous if and nonhomogeneous if . In some cases, the solveRecurrence function can also
solve linear recurrence relations with nonconstant coefficients that depend on or nonlinear recurrence relations, such as
The solveRecurrence function also solves a system of linear
recurrence relations that has the form
Version History
Introduced in R2026a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.
Americhe
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)