Solve two second order differential equations where initial values are known in a vector!
5 views (last 30 days)
Show older comments
Michael B on 20 Oct 2014
Commented: Michael B on 21 Oct 2014
me and my classmate are writing a program for a school project.
It's supposed to simulate a girl on a swing where she will jump until she reaches maximum jump length.
It consists of two parts, one to simulate the swings movements where she increases her speed at the turning points until she reaches 90 degrees where she stops. we have finished this part. The different angle and angular speed has been saved as vectors for part 2.
In part 2 we have two second order differential equations, on for the movement in the x-axis and one for the movement in the y-axis. The equations look like this:
k and g are constants we already have. we also have the x'(t) and y'(t) from the previous part, which is the velocity of the swing in x-axis and y-axis, which are the initial values.
Our question is, how do we solve these equations? Using RK4? In that case the RK4 is supposed to solve the equations using the first values in our vector, then stop and re run the RK4 again using next elements in the vector.
This is what we did for part 1 but then it was only one differential equation, now it is two!
Thank you for your help!
Matt Tearle on 20 Oct 2014
Are your equations correct there? It seems like the RHS should involve sqrt(x'^2 + y'^2) not x''^2 and y''^2. I'm going to assume first derivatives; if not, first you need to solve to get the equations in the form x'' = f(t,x,y,x',y') (and similarly for y'').
Anyway, 2 ODEs are no different to 1 -- convert the system of 2 2nd-order equations to a system of 4 1st-order equations:
z1' = z2
z2' = -k*z2*sqrt(z2^2 + z4^2)
z3' = z4
z4' = -g-k*|z4|*sqrt(z2^2 + z4^2)
ie z = [x x' y y']
Code that up and hand it to ode45... :)
More Answers (0)
Find more on Symbolic Computations in MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!