Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. %solve dv/dt
  2. n=1;
  3.  
  4. function xdot = f(x,t)
  5. c1 = 0.25;
  6. m = 0.5;
  7. % x(2)=x, x(1)=v
  8. xdot(1) = x(2);
  9. xdot(2) = -(c1/m)*x(2);
  10. endfunction
  11.  
  12. function ydot = g(y,t)
  13. c2 = 0.50;
  14. m = 0.5;
  15. % y(2)=y, y(1)=v
  16. ydot(1) = y(2);
  17. ydot(2) = -(c2/m)*y(2);
  18. endfunction
  19.  
  20. function zdot = h(z,t)
  21. g = 9.81;
  22. c3 = 0.9;
  23. m = 0.5;
  24. %z(1) = z, z(2) = zdot(1) = vz, zdot(2) = az
  25. zdot(1) = z(2);
  26. zdot(2) = ((-c3*z(2))-m*g)/m;
  27. endfunction
  28.  
  29. g=9.81;
  30. m=0.5;
  31. c3=0.9;
  32. c2=0.5;
  33. c1=0.25;
  34. k=m/c3;
  35. vx0 = 25; vy0 = 15; vz0 = 10;
  36. x0 = 0; y0 = 0; z0 = 0;
  37.  
  38.  
  39. x0vx0=[0,25];
  40. y0vy0=[0,15];
  41. z0vz0=[,10];
  42. t=linspace(0,2.5,50);
  43.  
  44.  
  45. xt=vx0*e.^(-c1*t/m);
  46. yt=vy0*e.^(-c2*t/m);
  47. xt=vx0*e.^(-t/k)-k*g*e.^(-t/k)-k*g;;
  48.  
  49. xxt=lsode("f",x0vx0,t);
  50. yyt=lsode("g",y0vy0,t);
  51. zzt=lsode("h",z0vz0,t);
  52.  
  53.  
  54. figure(1);
  55. plot3(xxt(:,1),yyt(:,1),zzt(:,1),'-r','linewidth',2);
  56. grid on;
  57. title(" Projectile Motion ", 'fontsize',14);
  58. xlabel("x position (m)",'fontsize',14);
  59. ylabel("y position (m)",'fontsize',14);
  60. zlabel("z position (m)",'fontsize',14);
  61. axis([-1 5 5 1 0 20]);
  62.  
  63.  
  64.  
  65. figure(2);
  66. plot3(xt(:,1),yt(:,1),zt(:,1),'-r','linewidth',2);
  67. grid on;
  68. title(" Projectile Motion ", 'fontsize',14);
  69. xlabel("x position (m)",'fontsize',14);
  70. ylabel("y position (m)",'fontsize',14);
  71. zlabel("z position (m)",'fontsize',14);
  72. axis([-1 5 5 1 0 20]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement