Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear all
- clc
- x(1) = 0.0; // initial position
- v(1) = 2.0; // initial velocity
- del_t = 0.2; // time increment
- k = 0.1; // spring constant
- m = 1.0; // mass
- Tf = 100.0; // Final time
- t = 0:del_t:Tf;
- N = length(t);
- v_hlf(1)=v(1)+(0.5*del_t*(-k/m)*x(1));
- for j=2:N
- x(j)=x(j-1)+v_hlf(j-1)*del_t;
- v(j)=v_hlf(j-1)+0.5*(del_t*(-k/m)*x(j));
- v_hlf(j)=v(j-1)+0.5*(del_t*(-k/m)*x(j));
- end
- figure; plot(t, x);
- grid on;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement