Solve two second order differential equations where initial values are known in a vector!

조회 수: 3 (최근 30일)
Hi,
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:
x''(t)=-k*x'(t)*sqrt((x''(t))^2+(y''(t)^2) y''(t)=-g-k*abs(y'(t))*sqrt((x''(t))^2+(y''(t)^2)
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
Matt Tearle 2014년 10월 20일
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... :)
  댓글 수: 3
Matt Tearle
Matt Tearle 2014년 10월 20일
편집: Matt Tearle 2014년 10월 20일
Oh, right -- in my mind RK4 = ode45 :)
If you've coded up an RK4 solver by hand, the use should be the same for this new, 4-D system of equations as before with your 2-D system. In either case, you have a system of ODEs z' = f(t,z). RK4 says, starting with z0,
k1 = f(t0,z0);
k2 = f(t0+h/2, z0+(h/2)*k1);
k3 = f(t0+h/2, z0+(h/2)*k2);
k4 = f(t0+h, z0+h*k3);
k = (k1 + 2*(k2+k3) + k4)/6;
z1 = z0 + h*k;
t1 = t0 + h;
Rinse and repeat. (Check my math -- that was from memory!) For a simple ode, each of those terms is a scalar. For a system, each is a vector (except t, of course). For this system of 2 2nd-order odes, once converted to a 4-D 1st-order system, each is a four element vector.
So if you had it working for the first part of your project, you should just be able to replace the function that calculates f(t,z) with one that calculates the four derivatives I gave above.
BTW, you might find this tutorial helpful -- it has a section on solving ODEs. Mostly the focus is on using things like ode45 but the general principles should help. (In fact, IIRC, we use an example that's very similar to the one you're doing!)
Michael B
Michael B 2014년 10월 21일
Alright, now I understand what to do and thank you for the tutorial,
best regards!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by