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!

 Accepted Answer

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 Comments

Thank you, now I have got the value, but how do I plot t vs z?
Actually I have figured it out! Thank you!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!