Advertisement
llLazy

Untitled

Apr 13th, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. function hw2_246
  2. clc
  3. hw2_246_1
  4. hw2_246_2
  5.  
  6. function hw2_246_1
  7. %% Part a
  8. syms y(t)
  9. dsolve('D2y + y*2 = 0');
  10. Dy = diff(y);
  11. sols = sym(zeros(11,1));
  12. for x = 1:10
  13. sols(x) = dsolve('D2y + y*2 = 0', y(0) == 0, Dy(0) == x/10);
  14. end
  15. figure
  16. hold on
  17. for x = 1:11
  18. ezplot(sols(x), [0,10])
  19. end
  20. hold off
  21.  
  22.  
  23. %% Part b
  24. syms y(t)
  25. Dy = diff(y);
  26. figure
  27. hold on
  28. ezplot(dsolve('D2y + Dy + y*2 = 0', y(0)== 0, Dy(0) == 2), [0 40])
  29. %ezplot(dsolve('D2y + Dy*2*sqrt(2) + y*2 = 0', y(0) == 2, Dy(0) == 2), [0 40])
  30. %second case doesn't want to work for whatever reason
  31. ezplot(dsolve('D2y + Dy*4 + y*2 = 0', y(0)== 2, Dy(0) == 2), [0 40])
  32. hold off
  33.  
  34. %% Part c
  35. syms y(t)
  36. figure
  37. hold on
  38. ezplot('2*cos(sqrt(2)*t) + (sin(sqrt(2)*t)*sqrt(2))+(sin(7*t)-cos(sqrt(2)*t))/(-45)', [0, 40])
  39. ezplot('2*cos(sqrt(2)*t) + (sin(sqrt(2)*t)*sqrt(2))+t*sin(sqrt(2)*t)/(2*sqrt(2))', [0, 40])
  40. hold off
  41. %% Part d
  42. syms y(t)
  43.  
  44.  
  45. function hw2_246_2
  46. hold on
  47. for k = 1:5
  48. m(k) = -2+(k-1);
  49. n(k) = -1+.5*(k-1);
  50. [t,x] = ode45('F',[-3,3],[m(k),n(k)]);
  51. plot(t,x(:,1))
  52. end
  53. hold off
  54. function xp = F(t,x)
  55. xp = zeros(2,1);
  56. xp(1) = x(2);
  57. xp(2) = -t^3*x(2)-x(1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement