Well as an example given the following to differential equations:

\(\displaystyle \frac{d^{2} x}{d{t}^{2}} = -\frac{C_{d} \cdot A \cdot \rho}{2 \cdot m} \cdot \left( \left( \frac{dx}{dt} \right)^{2}+\left( \frac{dy}{dt}^{2} \right) \right) ^{\frac{1}{2}} \cdot \frac{dx}{dt} \)

\(\displaystyle \frac{d^{2} y}{d{t}^{2}} = -\frac{g}{m}-\frac{C_{d} \cdot A \cdot \rho}{2 \cdot m} \cdot \left( \left( \frac{dx}{dt} \right)^{2}+\left( \frac{dy}{dt}^{2} \right) \right) ^{\frac{1}{2}} \cdot \frac{dy}{dt}\)

Can be rewritten where you introduce following:

\(\displaystyle z_{1} = x\)

\(\displaystyle z_{2} =y\)

\(\displaystyle z_{3} = \frac{dx}{dt}\)

\(\displaystyle z_{4} = \frac{dy}{dt}\)

Then the system of first order differential equation from the above will be:

\(\displaystyle \frac{dz_{1}}{dt} = z_{3} \)

\(\displaystyle \frac{dz_{1}}{dt} = z_{4} \)

\(\displaystyle \frac{dz_{1}}{dt} = -\frac{C_{d} \cdot A \cdot \rho}{2 \cdot m} \cdot \left( \left( x_{3} \right)^{2}+\left( z_{4}^{2} \right) \right) ^{\frac{1}{2}} \cdot z_{3} \)

\(\displaystyle \frac{dz_{1}}{dt} = -\frac{g}{m}-\frac{C_{d} \cdot A \cdot \rho}{2 \cdot m} \cdot \left( \left( z_{3} \right)^{2}+\left( z_{4}^{2} \right) \right) ^{\frac{1}{2}} \cdot z_{4} \)

Then the correspondent matlab code for the above will look like this:

function [dzdt] = odefunB(t, z,Cd,A,p,m,g)

dzdt = [

z(3);

z(4);

- (Cd*A*p/(2*m)) * sqrt((z(3)^2 + z(4)^2))*z(3);

-g/m - (Cd*A*p/(2*m)) * sqrt((z(3)^2 + z(4)^2))*z(4)];

end

Where each line is one of the right hand sides of the first order differential equations above, and then all the conditions comes like this:

fineness = 1000;

startangel = 30;

initialspeed = 500;

m = 0.55;

Cd = 0.5;

d = 0.07;

A = (pi*d^2)/4;

p = 1.2041;

g = 9.82;

tspan = linspace(0,30,fineness);

z0 = [0 2 cos(startangel/180 * pi)*initialspeed sin(startangel /180 * pi)*initialspeed];

[t,z] = ode45(@(t,z) odefunB(t,z,Cd,A,p,m,g),tspan,z0);

Hope the example can help you