How to Solve recurrence equation
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
채택된 답변
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]
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.
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일
0 개 추천
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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
