MATLAB: Plotting third order differential equation using ode45

third order ode

Hello
Could you please how to plot below third order differential equation using ODE45.
d3x/dt3 = +-1

Best Answer

You need to convert this 3-rd order ODE to 3 first order ODEs. Also due to +-1, you have two systems of ODEs. Try following code
odeFun = @(t,x,a) [x(2);
x(3);
a];
tspan = [0 10];
IC = [1; 0; 0];
ode45(@(t,x) odeFun(t,x,1), tspan, IC)
hold on
ode45(@(t,x) odeFun(t,x,-1), tspan, IC)
legend({'$x$', '$\dot{x}$', '$\ddot{x}$'}, 'Interpreter', 'latex', 'FontSize', 16, ...
'Location', 'best')