How to solve the difference equation for
yn+1 =5/2 yn +yn-1 ,y0 =y1 =1 in terms of the roots of its characteristic equation in MATLAB ?

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 7 日
編集済み: Ameer Hamza 2020 年 10 月 7 日

0 投票

An alternative is to use filter()
a = [1 -5/2 -1];
b = 0;
ic = [1 1];
n = 50; % 50 terms
y1 = [ic(1) filter(b, a, ones(1, n-1), ic)];

3 件のコメント

Betty Johnson
Betty Johnson 2020 年 10 月 7 日
Thanks for your response.It gives the following error "Unrecognized function or variable 'Y'."
Ameer Hamza
Ameer Hamza 2020 年 10 月 7 日
Sorry! There was a typo. Try again.
Betty Johnson
Betty Johnson 2020 年 10 月 7 日
Thank you for your help.After finding y1 according to your code,I am trying to check the behavior of the sequence {yn} as n → infinity based on following code but it doesn't look right.
clear all
close all
%function for fixed point iteration
yn=@(y1,y0) (5/2)*y1+y0;
%all initial guess
yy0=1; yy1=1;
y_val(1)=yy0; y_val(2)=yy1;
cnt=2; tt(1)=0;tt(2)=1;
%loop for all y
for i=1:10
cnt=cnt+1;
y_val(cnt)=yn(yy1,yy0);
yy0=yy1; yy1=y_val(cnt);
tt(cnt)=cnt-1;
end
%plotting the result
plot(tt,y_val)
xlabel('iterations')
ylabel('y_n')
title('y_n vs. iteration plot')
fprintf('The solution is diverging and tends to infinity at t tends to infinite.\n')

サインインしてコメントする。

その他の回答 (2 件)

KSSV
KSSV 2020 年 10 月 7 日

1 投票

n = 50 ;
y = zeros(1,n) ;
y(1:2) = 1 ;
for i = 2:n-1
y(i+1) =5/2*y(i) +y(i-1) ;
end

3 件のコメント

Betty Johnson
Betty Johnson 2020 年 10 月 7 日
Thank you for your response.I am trying to check the behavior of the sequence {yn} as n → infinity based on your code.It gives me error.
Walter Roberson
Walter Roberson 2020 年 10 月 7 日
No error in the KSSV posted.
n = 50 ;
y = zeros(1,n) ;
y(1:2) = 1 ;
for i = 2:n-1
y(i+1) =5/2*y(i) +y(i-1) ;
end
disp(y(end-4:end))
1.0e+21 * 0.1255 0.3577 1.0198 2.9073 8.2881
You cannot, of course, run this out to infinity.
Walter Roberson
Walter Roberson 2023 年 8 月 29 日
There are no negative coefficients, and no coefficients with absolute value less than one, and the initial values are positive. Each value is at least 5/2 times the previous one, so a lower bound would be (5/2)^(n-1) and therefore the bound to infinity is infinite

サインインしてコメントする。

mohammed hussain
mohammed hussain 2023 年 8 月 29 日

0 投票

a = [1 -5/2 -1];
b = 0;
ic = [1 1];
n = 50; % 50 terms
y1 = [ic(1) filter(b, a, ones(1, n-1), ic)];

1 件のコメント

Walter Roberson
Walter Roberson 2023 年 8 月 29 日
how does this differ from the accepted answer?

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeNumerical Integration and Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by