So I have to plot the movement of a spring once let go for -2<t<20 given yo=5(distance the spring is stretched initially), w=5(angular frequency), k=0.1/s. It has to be done using a for loop and if statements.
I am new to matlab so I don't know what to do from here. Thank you.
Here's the code I have:
t = -2;yo = 5;w = 5;k = 0.1;for t = -2:20if t < 0y = -yo;elseif t < 10y = -yo*(cos(w*t));elsey = -yo*(cos(w*t))*exp(-k*(t-10));endt = t + 0.1;end