Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. %% Problem 1
  2. % 1 b)
  3. syms l k l0
  4. k(l) = (k/3)*((l-(l0^3/l^2))/(l-l0));
  5. T = taylor(k(l), 'ExpansionPoint', l0,'Order', 3);
  6.  
  7. % 1c)
  8. k0 = 16;
  9. l0 = .2;
  10.  
  11. syms k(l)
  12.  
  13. k(l) = (k/3)*((l-(l0^3/l^2))/(l-l0));
  14. l = linspace(0,0.5);
  15. linear = k0*(l-l0);
  16. nonlinear = -(k0/3)*((l-(l0^3./l.^2))./(l-l0));
  17.  
  18. figure(1)
  19. subplot(211);
  20. plot(linear,nonlinear,'LineWidth',1.5,'DisplayName',"Elastomer");
  21. title('Problem 1: Question 1C');
  22. xlabel('Distance');
  23. ylabel('Elastomer Force');
  24.  
  25. subplot(212);
  26. plot(l,linear,'LineWidth',1.5,'DisplayName',"Linear");
  27. xlabel('Distance');
  28. ylabel('Linear Force');
  29.  
  30. %2b)
  31. l0=0.2;
  32. m=1;
  33. t0=0;
  34. tf=6;
  35.  
  36. lt0 = 0.1;
  37. v0=0;
  38.  
  39. tspan=[t0 tf];
  40. u0 = [lt0 v0];
  41. f1=@(t,u) [u(2), -1*((k0)*(1+(l0/u(1))+((l0^2)/(u(1)^2)))*(u(1)-l0))/(3*m)]';
  42.  
  43. [tarray,uarray]=ode45(f1,tspan,u0);
  44.  
  45. A=[0 -1;k0 0];
  46. [T,U]=ode45(@(t,u)-A*u,tspan,u0);
  47.  
  48. figure(2)
  49. plot(tarray,uarray(:,1),'LineWidth',1.2,'DisplayName',"x1 ODE45")
  50. hold on
  51. title("Graph for 2b)")
  52. xlabel('t')
  53. ylabel('l')
  54. grid on
  55.  
  56. plot(T,U(:,1),'LineWidth',1.2,'DisplayName',"x1 ODE45")
  57. hold on
  58. legend('l(t)','l(t) response');
  59.  
  60. %2c)
  61.  
  62. l0=[0.05,0.1,0.2,0.5];
  63. for ii=1:length(l0)
  64. f1=@(t,u) [u(2), -1*((k0)*(1+(l0(ii)/u(1))+((l0(ii)^2)/(u(1)^2)))*(u(1)-l0(ii)))/(3*m)]';
  65.  
  66. [tarray,uarray]=ode45(f1,tspan,u0);
  67.  
  68. A=[0 -1;k0 0];
  69. [T,U]=ode45(@(t,u)-A*u,tspan,u0);
  70.  
  71. figure(ii+2)
  72. plot(tarray,uarray(:,1),'LineWidth',1.2,'DisplayName',"x1 ODE45")
  73. hold on
  74. title("Graph for 2c)")
  75. xlabel('t')
  76. ylabel('l')
  77. grid on
  78.  
  79. plot(T,U(:,1),'LineWidth',1.2,'DisplayName',"x1 ODE45")
  80. hold on
  81. legend('l(t)','l(t) response');
  82.  
  83. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement