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