Solving difference equation with its initial conditions

223 views (last 30 days)
Hi,
Consider a difference equation:
8*y[n] - 6*y[n-1] + 2*y[n-2] = 1
with initial conditions
y[0]= 0 and y[-1]=2
How can I determine its plot y(n) in Matlab? Thank you in advance for your help!
  2 Comments
Walter Roberson
Walter Roberson on 19 Feb 2017
I would call this a recurrence equation, not a difference equation.

Sign in to comment.

Accepted Answer

Jan
Jan on 21 Feb 2017
Edited: Jan on 21 Feb 2017
Resort the terms:
8*y[n] - 6*y[n-1] + 2*y[n-2] = 1
y[n] = (1 + 6*y[n-1] - 2*y[n-2]) / 8
or in Matlab:
y(n) = (1 + 6*y(n-1) - 2*y(n-2)) / 8;
Now the indices cannot start at -1, because in Matlab indices are greater than 0. This can be done by a simple translation:
y = zeros(1, 100); % Pre-allocate
y(1:2) = [2, 0];
for k = 3:100
y(k) = (1 + 6*y(k-1) - 2*y(k-2)) / 8;
end
Now you get the y[i] by y(i+2).

More Answers (1)

Sindhuja Parimalarangan
Sindhuja Parimalarangan on 21 Feb 2017
This link discusses solving recurrence equations using MATLAB. The discrete solution for "y" can be plotted using the stem function.

Tags

No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!