# what y(2) ,y(3), y(4) , y(5) ,by using matlab ?

14 views (last 30 days)
majed alharbi on 19 Sep 2020
Commented: Rena Berman on 8 Oct 2020 at 15:49
y(0)=1 y(2)=5
y(n+2)=3y(n+1)-5y(n)
what y(2) ,y(3), y(4) , y(5) ,by using matlab ?

Show 1 older comment
Walter Roberson on 19 Sep 2020
Are you sure you are given y0 and y2 but not y1? If so then you can indeed calculate y1 but it will be 10/3 not an integer.
Stephen Cobeldick on 19 Sep 2020
"what y(2) ,y(3), y(4) , y(5) ,by using matlab ?"
y(0)=1 y(2)=5
y(n+2)=3y(n+1)-5y(n)
what y(2) ,y(3), y(4) , y(5) ,by using matlab ?
Rena Berman on 8 Oct 2020 at 15:49

Alan Stevens on 19 Sep 2020
You need to start with y(1) = 1, not y(0) = 1. Then with y(2) = 5, you can use a for loop:
for n=1:3, y(n+2) = 3*y(n+1)-5*y(n); end

majed alharbi on 19 Sep 2020
still
majed alharbi on 19 Sep 2020
Walter Roberson on 19 Sep 2020
you did not loop like I suggested. You tried to vectorize.
The function can only be vectorized after a bunch of mathematical calculations to figure out the general form. I recommend looping, it is much easier.