Advertisement
Guest User

4B

a guest
Mar 28th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. a = 1;
  2. gam = 0;
  3. om0 = 5;
  4. tmax = 10;
  5. c = 1;
  6.  
  7. a1 = 0.5;
  8. I1 = @(t) Impulse(t,c,a1);
  9. options1 = odeset( 'MaxStep', a1 );
  10. a2 = 0.25;
  11. I2 = @(t) Impulse(t,c,a2);
  12. options2 = odeset( 'MaxStep', a2 );
  13. a3 = 0.05;
  14. I3 = @(t) Impulse(t,c,a3);
  15. options3 = odeset( 'MaxStep', a3 );
  16. % a4 = 0.01;
  17. % I4 = @(t) Impulse(t,c,a4);
  18. % options4 = odeset( 'MaxStep', a4 );
  19.  
  20. [t15a,x15a] = ode15s( @(t,x) [x(2); I1(t) - om0^2*x(1) - 2*gam*x(2)], [0 tmax], [0; 0], options1 );
  21. [t15b,x15b] = ode15s( @(t,x) [x(2); I2(t) - om0^2*x(1) - 2*gam*x(2)], [0 tmax], [0; 0], options2 );
  22. [t15c,x15c] = ode15s( @(t,x) [x(2); I3(t) - om0^2*x(1) - 2*gam*x(2)], [0 tmax], [0; 0], options3 );
  23. % [t15d,x15d] = ode15s( @(t,x) [x(2); I4(t) - om0^2*x(1) - 2*gam*x(2)], [0 tmax], [0; 0], options4 );
  24.  
  25. figure();
  26. plot( t15a,x15a(:,1), t15b,x15b(:,1), t15c,x15c(:,1));
  27. xlabel('t');
  28. ylabel('y');
  29. legend( 'a = 0.5', 'a = 0.25', 'a = 0.05');
  30.  
  31. %% 2
  32.  
  33. tsol = [0:.1:8];
  34. [tsol,xsol]= ode45( @(t,x) [x(2); I1(t) - 2*gam*x(2)], [tsol], [0; 0] );
  35. plot(tsol,xsol)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement