How to Solve recurrence equation
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
採用された回答
Star Strider
2022 年 9 月 17 日
Try something like this —
h(1) = rand; % Initial Condition
h(2) = rand; % Initial Condition
N = 50;
for n = 3:N
h(n)=-0.36*h(n-2)+1.2*h(n-1);
end
nv = 1:N;
figure
plot(nv, h, '.-')
grid
xlabel('n')
ylabel('h')

Experiment to get the result you want.
.
14 件のコメント
Walter Roberson
2022 年 9 月 17 日
"solving" a recurrance equation means coming up with a non-recursive closed form expression for the function.
Thank you! This helps me a lot!!
So if the question is to plot for M-file recur with T=0.4, compute the approximation to y(t) for the equation
y[n-2][1+T^2-2T]+y[n-1][2T-2]+y[n]=0
y[n-2][-0.36]+y[n-1][1.2]=y[n]
Star Strider
2022 年 9 月 17 日
As always, my pleasure!
That appears to me to be correct.
T = 0.4;
y(1) = 0.95;
y(2) = 0.35;
N = 50;
coeffv = [(1+T^2-2*T) (2*T-2)]
coeffv = 1×2
0.3600 -1.2000
for n = 3:N
y(n) = -y(n-2)*(1+T^2-2*T)-y(n-1)*(2*T-2);
end
nv = 1:N;
figure
plot(nv, y, '.-')
grid
xlabel('n')
ylabel('h')

.
Jiby
2022 年 9 月 17 日
I have trying to solve the 2.27 c,d,e in matlab [attached screenshot].
Jiby
2022 年 9 月 17 日
y(1) = 0.95;
y(2) = 0.35;
From where do we get these two values?
Star Strider
2022 年 9 月 17 日
編集済み: Star Strider
2022 年 9 月 17 日
The current code appears to be (c). Part (d) is the same with a different value for ‘T’, and the analytic solution for the differential equation is given in (a), so you simply need to code it and run all of them together.
EDIT — I did not previously see your last Comment. Those are random numbers, since I needed something to define the first two elements of ‘y’ in order to test my code.
Jiby
2022 年 9 月 18 日
syms h
T = 0.4; % T = 0.4 sec
h(1) = 0.95; %h(1)=arbitrary value
h(2) = 0.35; %h(2)=arbitrary value
N = 10;
coeff1 = [(1+T^2-2*T) (2*T-2)]
for n = 3:N
h(n) = -h(n-2)*(1+T^2-2*T)-h(n-1)*(2*T-2);
end
h
nv = 1:N;
figure
plot(nv, h, '.-')
grid
title ('T = 0.4 Sec')
xlabel('n')
ylabel('h')
syms h1
R = 0.1; % T2 = R = 0.1 sec
h1(1) = 0.95; %h(1)=arbitrary value
h1(2) = 0.35; %h(2)=arbitrary value
N = 10;
coeff2 = [(1+R^2-2*R) (2*R-2)]
for n = 3:N
h1(n) = -h1(n-2)*(1+R^2-2*R)-h1(n-1)*(2*R-2);
end
h1
nv = 1:N;
figure
plot(nv, h1, '.-')
grid
title ('T = 0.1 Sec')
xlabel('n')
ylabel('h')
t = linspace(1, 10);
y = (2 .* exp(-t))+ (t .*exp(-t));
figure(1)
plot(t, x)
grid
title ('Exponential Graph')
xlabel('t')
ylabel('y')
plot(t, x)
hold on
plot(nv, h, '.-')
hold on
plot(nv, h1, '.-')
hold off
legend('Exponential','T 0.4 Sec','T 0.1 Sec')
Star Strider
2022 年 9 月 18 日
I did not run any of that, howewver it appears to be correct.
h(1) = y(0) and h(2) must be an approximation to y(T) obtained from Euler's method.
Maybe h(2) = y(0) + T*y'(0).
They are not arbitrary values.
And the t-values at which the y values are computed are not nv = 1:N, but nv = T*(0:N-1).
Jiby
2022 年 9 月 18 日
h(n) = -h(n-2)*(1+T^2-2*T)-h(n-1)*(2*T-2);
h(1) = y(0) and h(2) must be an approximation to y(T) obtained from Euler's method.
Maybe h(2) = y(0) + T*y'(0).
could you please explain the statement with the above h(n)
h(n) is an approximation of the solution of your differential equation y at t = (n-1)*T.
Thus h(1) = y(t=0) and h(2) = y(t=T).
An approximation for h(2) = y(T) with Euler forward is y(T) = y(0) + T*y'(0) = 2 + T*(-1).
yexact = @(t) (2+t).*exp(-t);
T = 0.4; % T = 0.4 sec
h(1) = 2; %h(1)=y(0)
h(2) = 2+T*(-1); %h(2)=y(0)+T*y'(0)
N = 10/T+1;
for n = 3:N
h(n) = -h(n-2)*(1+T^2-2*T)-h(n-1)*(2*T-2);
end
nv = 0:T:(N-1)*T;
figure
hold on
plot(nv, h, '.-')
plot(nv, yexact(nv))
hold off
grid
title ('T = 0.4 Sec')
xlabel('n')
ylabel('h')

Thanks a lot for your response @Torsten
When i tried plotting this, it showed h & nv doesnot have same vector length with 101*26 respectively
I don't know your code, but as you can see above, plotting is possible.
nv and h are both vectors of size 1 x (10/T+1) (1 x 26 for T = 0.4).
101 smells like T = 0.1 while 26 smells like T = 0.4. I think you somehow mixed the two stepsizes for T in the h and nv arrays.
その他の回答 (1 件)
Walter Roberson
2022 年 9 月 17 日
See https://www.mathworks.com/matlabcentral/answers/1805355-how-do-i-translate-rec-from-mupad-to-matlab-symbolic-math-toolbox#answer_1053500 for solving recurrance equations using ztrans()
カテゴリ
ヘルプ センター および File Exchange で Solver Outputs and Iterative Display についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- 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)
