MATLAB: Using differential equations of acceleration how would I plot a trajectory

differential equationsMATLABrunge kutta

Hi!
I have an assignment in my course where I need to plot the trajectory of an object where the only input of the function is the initial angle of the throw. I have two differential equations that each give me the acceleration in horizontal (x) and vertical (y) of the object. In these formulas I also have an air friction constant to keep in mind of.
The initial values that are given is the initial speed of the object and the initial position of the object.
I am not to sure as what kind of algorithms I would need to use in order to plot the trajectory.
Here's what I think I should do:
Solve the DE:s given the initial values using runge-kutta formula. Then upon getting the acceleration in both x and y I would then integrate this over the time passed and once again in order to get the change in position, this could perhaps be done using the trapezoidal method. For example with a step size of 0.1 I would then integrate the acceleration between time 0 and 0.1 and then once again in order to find the displacement of the object. Does this sound like a reasonable solution?
I hope the question does not seem unfitting given no code, but I would like to know simply if my heading is correct or not, given my limited knowledge and not haven done any multivariable calculus or advanced DE:s before!

Best Answer

Hi Alexander,
What you've depicted is all appropriate. Just a brief recap what you have stated and how to implement in MATLAB environment.
  1. Define: initial conditions: [x0, dx0]
  2. Define: time space to simulate your system; [0, tend]
  3. Define: your system equation has to be re-write as two first order ODEs, e.g.: dxdt = [x(2), g-a*x(2)] ; % I am making up as an example. Where x(2) represents dx, g is gravitational acc., a is air drag coeff... In this case, you can employ, anonymous function (@), function file, or express directly or use inline function or use symbolic MATH matlabFunction().
  4. You can write your own script based on 4/5 RK or use ode45 or ode23 or ode113, .. etc.. w.r.t your problem's nature - how stiff it is.
  5. PLOT: your computed numerical results which will contain displacement and velocity.
  6. End
Good luck.