Goal
I have been attempting to solve and plot the following coupled differential equation belonging to quadratic drag:
The variables from the equations are defined as:
c = 0.0004
m = 0.0027
starting position of projectile= (0,0.3)
velocity on horizontal component = 2.05
velocity on vertical component = 0.55
g = 9.81
The problem
I cannot seem to solve the equation correctly and have some errors in programming
What I have tried
I have tried using the code from online on MatLab and I have tried on Matematica but none of them is able to program this equation. I have also tried looking at SciPy on Python but it does not seem to work.
Could anybody please set me in the right direction on how to code this properly?
You can use a number of MATLAB built-in ODE solvers.
ode45
is usually a good place to start.You have two positions and two velocities (4 states total), so you need to pass 4 ODEs to the solver
ode45
(one derivative for each state). Ifx(1)
is the x-position,x(2)
is the y-position,x(3)
is the x-velocity, andx(4)
is the y-velocity, then the derivative ofx(1)
isx(3)
, the derivative ofx(2)
isx(4)
and the derivatives ofx(3)
andx(4)
are the ones given by your two drag equations.In the end, the MATLAB implementation might look like this:
And you can plot the results as follows: