I'm trying to plot the evolution of a simple harmonic oscillator using MATLAB but I'm getting non-sense result and I have no idea what's wrong!(adsbygoogle = window.adsbygoogle || []).push({});

Here's my code:

And this is what I get:Code (Text):

clear

clc

x(1)=0;

v(1)=10;

h=.001;

k=100;

m=.1;

t=[0:h:10];

n=length(t);

for i=2:n

F(i-1)=-k*x(i-1);

v(i)=(h/m)*F(i-1)+v(i-1);

x(i)=h*v(i-1)+x(i-1);

end

plot(t(1:n),x);

http://www.cvberry.com/octave/graphs/graph1395294146456.jpg [Broken]

What's wrong?

Thanks

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# SHO using MATLAB

Tags:

Loading...

Similar Threads - using MATLAB | Date |
---|---|

Matlab Solving equation with integration using MATLAB | Aug 4, 2017 |

Matlab Working out an equation on MATLAB using co-ordinates | Mar 8, 2017 |

Matlab Arduino-MATLAB communication using SerialEvent() for PID Loop | Oct 28, 2016 |

Matlab -- how can i use a FOR loop if I have 2 variables changing | Oct 12, 2016 |

Matlab Number formats in Matlab [not to use e symbol] | Jun 10, 2016 |

**Physics Forums - The Fusion of Science and Community**