Solve a system of two second-order differential equations using ode

Hello everyone!
I'm new to Matlab and I'm facing a problem to solve a system of two second-order differential equations.
My aim is to draw a graph of y-x.
The initial condition for x and y is 0, and for x' and y' is 9.
In this equation, m=0.175, p=1.29, g=-9.81, A=0.0568, CD=-14.1404, and CL=1.894604571
I cannot get how to use ode45 or ode15s to solve a system.
Thanks in advance!

 Accepted Answer

Start by using the Symbolic Math Toolbox to set the equations up, then use odeToVectorField and matlabFunction to create an anonymous function to use with ode45, ode15s, or other numerical solvers.
EDIT — (28 May 2021 at 3:18)
You will need to code your equations correctly, then do something like this. The documentation explains it in detaiil.
A prototype example —
syms x(t) T Y
ODE = diff(x,2) + 10*diff(x) - 1;
[VF,Subs] = odeToVectorField(ODE)
VF = 
Subs = 
odefcn = matlabFunction(VF, 'Vars',{T,Y})
odefcn = function_handle with value:
@(T,Y)[Y(2);Y(2).*-1.0e+1+1.0]
tspan = [0 1];
ics = [0 1];
[t,y] = ode45(odefcn, tspan, ics);
figure
plot(t,y)
grid
legend(string(Subs))
.

More Answers (0)

Asked:

on 28 May 2021

Edited:

on 28 May 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!