How to Solve recurrence equation
显示 更早的评论
How to solve the recurrence equation
h[n]=-0.36*h[n-2]+1.2*h[n-1]
1 个评论
采纳的回答
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 个评论
"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]
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')

.
I have trying to solve the 2.27 c,d,e in matlab [attached screenshot].
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.
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')
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).
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')

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.
I tried with T=0.1 without clearing workspace.
Thank you @Torsten
更多回答(1 个)
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 中查找有关 Scripts 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 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)
