Advertisement
Guest User

Untitled

a guest
Sep 10th, 2013
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.79 KB | None | 0 0
  1. %%
  2. % Problem constants
  3. m = 1;
  4. c = 2;
  5. k = 5;
  6. g = 9.8;
  7.  
  8. % Time vector for ODE45
  9. tstep = 0.01;
  10. tspan = 0:tstep:20;
  11.  
  12. % seismic
  13. %---with function
  14. %groundfunc = @(t) ground_step_tanh(t);   %Seismic
  15. %ground = groundfunc(tspan);
  16. %---random ground
  17. %ground = smooth(cumsum(normrnd(0,0.005,length(tspan),1)),10);
  18. %---flat ground, y(t) = 0
  19. %ground = zeros(length(tspan),1);
  20. %---explicit
  21. ground = 0.1*sin(5*t);
  22. % y prime
  23. groundp = gradient(ground,t);
  24.  
  25. % ODE function
  26. odefunc = @(t, x) bot_susp_1d(t, x, m, k, c, tspan, ground, groundp); %for ode45 syntax
  27.  
  28. % State vector: [x(t) x'(t)]
  29. initial_x = - m * g / k;
  30. initial_xp = 0;
  31.  
  32. % initial_yp = 0;
  33. initial = [initial_x initial_xp];
  34.  
  35. %% ode45 execution
  36. tic
  37. [t,xres] = ode45(odefunc,tspan, initial);
  38. toc
  39.  
  40. %% Plotting
  41. plot(t, xres(:,1));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement