Solving difference equation with its initial conditions

조회 수: 13 (최근 30일)
Ben Le
Ben Le 2017년 2월 19일
편집: Ben Le 2017년 2월 21일
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
John D'Errico
John D'Errico 2017년 2월 19일
Surely you can use a loop? Why not make an effort? You have the first two values, so a simple loop will suffice.
More importantly, you need to spend some time learning MATLAB. Read the getting started tutorials. It is apparent that you don't know how to even use indexing in MATLAB, nor how to use a for loop.
You will need to recognize that MATLAB does NOT allow zero or negative indices.
Walter Roberson
Walter Roberson 2017년 2월 19일
I would call this a recurrence equation, not a difference equation.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2017년 2월 21일
편집: Jan 2017년 2월 21일
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).
  댓글 수: 1
Ben Le
Ben Le 2017년 2월 21일
편집: Ben Le 2017년 2월 21일
Thank you so much, Jan!!!!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

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

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by