problem3_2ndorderODE.m 668 B

12345678910111213141516171819202122232425
  1. clear all; close all; clc;
  2. % I'm using GNU Octave, so hopefully you don't mind that I constructed
  3. % the ode vector myself.
  4. % Really this is basically the same as writing the differential equation as
  5. % it was given, since the only transformative step I took was shifting
  6. % everything to the other side of the equation to solve for the
  7. % second derivative.
  8. ode_system = @(t, Y) [
  9. Y(2);
  10. -3 - (t^2 + Y(1))*Y(1) - (3*t+2*Y(1))*Y(2)
  11. ];
  12. t_span = [0, 10];
  13. initial_conditions = [1; 0];
  14. [t, Y] = ode45(ode_system, t_span, initial_conditions);
  15. figure;
  16. hold on;
  17. grid on;
  18. plot(t, Y(:, 1));
  19. plot(t, Y(:, 2));
  20. legend("y(t)", "y'(t)");
  21. xlabel("t");
  22. ylabel("y(t) & y'(t)");