Guest User

Untitled

a guest
Jan 17th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. f = 0.05;
  2. t_f = 10;
  3. tspan = [0 t_f];
  4. z0 = [0 ; 0];
  5.  
  6. options = odeset('stats','on');
  7.  
  8. [t, z] = ode23s(@(t,z) sys_13(t, z, f), tspan, z0, options);
  9.  
  10. figure(1)
  11. set(gcf,'units','normalized','outerposition',[0 0 1 1])
  12.  
  13. subplot(2,1,1);
  14. plot(t,z(:,1),'b');
  15. title(['Time history of $y(t),,(ddot{u}_{gx}=-(2pi f)^2sin(2pi f t)) ,, f=, $' num2str(f) ' $ $'],'interpreter','latex','fontsize',20)
  16. ylabel('$y$','interpreter','latex','fontsize',15)
  17. xlabel('$t$','interpreter','latex','fontsize',15)
  18. xlim(tspan)
  19.  
  20. grid on
  21. hold on
  22.  
  23. subplot(2,1,2);
  24. plot(t,z(:,2),'b')
  25. ylabel('$dot{y}$','interpreter','latex','fontsize',15)
  26. xlabel('$t$','interpreter','latex','fontsize',15)
  27. xlim(tspan)
  28.  
  29. grid on
  30. hold on
  31.  
  32. figure(2)
  33. plot(t,z(:,1).*z(:,2),'b')
  34.  
  35. grid on
  36. grid minor
  37. hold on
  38.  
  39. function dz = sys_13(t, z , f)
  40. dz = zeros(2,1);
  41.  
  42. m = 1;
  43. k0 = 4;
  44. % tol = 1e-6;
  45. % if abs(z(1)*z(2)) > tol && z(1)*z(2) > 0
  46. % k1 = 4;
  47. % else
  48. % k1 = 0;
  49. % end
  50.  
  51. if z(1)*z(2) > 0
  52. k1 = 4;
  53. else
  54. k1 = 0;
  55. end
  56.  
  57. finput = ( -(2*pi*f)^2 )*sin( 2*pi*f*t );
  58.  
  59. dz(1) = z(2);
  60. dz(2) = - finput - ((k0 + k1)/m)*z(1);
  61. end
Add Comment
Please, Sign In to add comment