Finite difference problem with matlab 2014

Let's say I have a problem like this: det_t = 0.02, t = [0 : det_t : 1], z(t+det_t) = 3 * z(t) + 2* z(t-det_t), where z(t-det_t) is the value of z initially, z(t) is value of z after one time step and z(t+det_t) is the value of z after two time step. Now I have the values of z(0) = 1 and z(-det_t) = 0, how can I calculate z(1) without having to substitute the new value of z for 50 times? I am very new to matlab so please explain with very basic language, thank you the help!

 채택된 답변

Massimo Zanetti
Massimo Zanetti 2016년 10월 8일
편집: Massimo Zanetti 2016년 10월 8일

3 개 추천

Your problem is equaivalent to this (without the variable t, which redundant here as it is used only for indexing purposes). Since your vector t has 51 elements and you are meant to find the last value of the sequence, you want to implement this:
%you are given the first two elements of a sequence
z(1)=0;
z(2)=1;
%to determine the k-th value of the sequence (k>2)
%you need z(k)=3*z(k-1)+2*z(k-2), therefore:
for k=3:51
z(k)=3*z(k-1)+2*z(k-2);
end
% your solution is
z(51)

댓글 수: 2

Jimmy W
Jimmy W 2016년 10월 8일
Thank you, now I have got the value, but how do I plot t vs z?
Jimmy W
Jimmy W 2016년 10월 8일
Actually I have figured it out! Thank you!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2016년 10월 8일

댓글:

2016년 10월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by