The Student Room Group

Runge-Kutta 4th Order Integration help.

Hi,

I have been given two second order differential equations which I am to convert to a system of four first order differential equations:

2de.png
I then get the following from these:
Attachment not found


I now have to solve these using the runge-kutta first order method.
I am confused as to how to do this, because as far as I am aware, the format that this numerical method can be used on is the form of y'(t)=f(y,t).

my functions instead are such that for example equation 3 is s'(t)=f(z,t). (I have chosen my variable names poorly as that t is not time but just a letter.

my question is when solving the k values using this method, how can i calculate the f(y,t) values given that in my function i dont know how I can use the time value. are my initial system of first order equations wrong and i need to derive a different system or can it be solved ?

thanks
Original post by KloppOClock
Hi,

I have been given two second order differential equations which I am to convert to a system of four first order differential equations:

I then get the following from these:

I now have to solve these using the runge-kutta first order method.
I am confused as to how to do this, because as far as I am aware, the format that this numerical method can be used on is the form of y'(t)=f(y,t).

my functions instead are such that for example equation 3 is s'(t)=f(z,t). (I have chosen my variable names poorly as that t is not time but just a letter.

my question is when solving the k values using this method, how can i calculate the f(y,t) values given that in my function i dont know how I can use the time value. are my initial system of first order equations wrong and i need to derive a different system or can it be solved ?

thanks


What does z˙\dot{z} denote?? Is it differentiation with respect to tt ? If so, isn't it a bit confusing to then define ϕ˙=t\dot{\phi} = t ?
Original post by RDKGames
What does z˙\dot{z} denote?? Is it differentiation with respect to tt ? If so, isn't it a bit confusing to then define ϕ˙=t\dot{\phi} = t ?


yes thats what it means. i chose t as a variable by accident, should have called it something else. all the t's in the equations can be called something else but the differentials are differentiated with respect to time, not that t.
problemo.png

i got functions 3-6 from 1-2. i then have to solve using kutta but they are not of the form y'=f(y,t) as you can see at the end.

can i still solve them using runge - kutta or are my differential equations wrong.
Original post by KloppOClock
problemo.png

i got functions 3-6 from 1-2. i then have to solve using kutta but they are not of the form y'=f(y,t) as you can see at the end.

can i still solve them using runge - kutta or are my differential equations wrong.

Is your problem that "you don't know what t is", or that, for example, you have c' = f(c(t), b(t), z(t)) and you were expecting something more like c' = f(c(t))?
Original post by DFranklin
Is your problem that "you don't know what t is", or that, for example, you have c' = f(c(t), b(t), z(t)) and you were expecting something more like c' = f(c(t))?


i was expecting to get c' as a function of c(t).

my problem is that i dont know if i can use my equations with this method because im not sure if ive derived the correct ones to use.

also when i work out the k values using this method i need to be able to evaluate c(t+dt) which i dont know how to do if i dont have any time variables in the actual equation or maybe im misunderstanding it
Original post by KloppOClock
i was expecting to get c' as a function of c(t).

my problem is that i dont know if i can use my equations with this method because im not sure if ive derived the correct ones to use.

also when i work out the k values using this method i need to be able to evaluate c(t+dt) which i dont know how to do if i dont have any time variables in the actual equation or maybe im misunderstanding it


RK4 is an interative technique, so you iterate from one time to another to yield approximated z,z˙,ϕ,ϕ˙z, \dot{z}, \phi, \dot{\phi} values.

You don't 'solve' for f(y,t)f(y,t) or whatever it is.

The ODE's here are only dependent on tt through z,ϕz,\phi. It doesn't need to appear explicitly in the ODE's.
Original post by RDKGames
RK4 is an interative technique, so you iterate from one time to another to yield approximated z,z˙,ϕ,ϕ˙z, \dot{z}, \phi, \dot{\phi} values.

You don't 'solve' for f(y,t)f(y,t) or whatever it is.

The ODE's here are only dependent on tt through z,ϕz,\phi. It doesn't need to appear explicitly in the ODE's.


https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods

i dont think i understand how to work out the values of k2,k3,k4.

how can i evaluate that function ?
Original post by KloppOClock
i was expecting to get c' as a function of c(t).

my problem is that i dont know if i can use my equations with this method because im not sure if ive derived the correct ones to use.

also when i work out the k values using this method i need to be able to evaluate c(t+dt) which i dont know how to do if i dont have any time variables in the actual equation or maybe im misunderstanding it

if there's no t dependence, then f(c, t) = f(c). In other words, just pretend your function f takes a parameter t but doesn't do anything with it.
Original post by KloppOClock
https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods

i dont think i understand how to work out the values of k2,k3,k4.

how can i evaluate that function ?

Are you happy you know how to find k1?
Original post by DFranklin
Are you happy you know how to find k1?


what about my equations when its not c'(t) = c(t)

but like c'(t)= function of c(t),b(t),z(t)
Original post by KloppOClock
what about my equations when its not c'(t) = c(t)

but like c'(t)= function of c(t),b(t),z(t)

The simplest way of looking at this is to think of y in the wiki article as being a vector. So here you'd have a vector

y=(zϕbc)y = \begin{pmatrix} z \\ \phi \\ b \\ c \end{pmatrix}, and then y' = F(y), where the 4 components of F are basically the 4 equations (3)-(6) in your post #4. Then the equations in the wiki article still work and still apply (just ignoring t in F(y, t) etc. since our equations are time independent)

Or, on a stricly procedural basis:

if you have c' = f(c, b, z), and assuming you've already calculated cn,bn,znc_n, b_n, z_n and want to find cn+1c_{n+1} then to find k1 you'd
just calculate h f(c_n, b_n, z_n). (f doesn't depend directly on t, so we just ignore it).

Now, to find k2, you need to have done this for *all* the components you need to evaluate f. That is, you found "k1 for c", but you need to find "k1 for b" and "k1 for z" as well. For clarity, denote these as k1,c,k1,b,k1,zk_{1, c}, k_{1, b},k_{1, z}.

Then k2 (for c, so k2,ck_{2,c} if we wanted to be consistent about notation) is going to be

hf(cn+12k1,c,bn+12k1,b,zn+12k1,z)h f(c_n+\frac{1}{2} k_{1,c}, b_n+\frac{1}{2} k_{1,b}, z_n+\frac{1}{2} k_{1,z})

So you'd find all the k_2, then do something similar to find all the k_3, and then the k_4.

In terms of implementation, you *really* want to get comfortable with the idea of y being a vector, however.
Original post by DFranklin
The simplest way of looking at this is to think of y in the wiki article as being a vector. So here you'd have a vector

y=(zϕbc)y = \begin{pmatrix} z \\ \phi \\ b \\ c \end{pmatrix}, and then y' = F(y), where the 4 components of F are basically the 4 equations (3)-(6) in your post #4. Then the equations in the wiki article still work and still apply (just ignoring t in F(y, t) etc. since our equations are time independent)

Or, on a stricly procedural basis:

if you have c' = f(c, b, z), and assuming you've already calculated cn,bn,znc_n, b_n, z_n and want to find cn+1c_{n+1} then to find k1 you'd
just calculate h f(c_n, b_n, z_n). (f doesn't depend directly on t, so we just ignore it).

Now, to find k2, you need to have done this for *all* the components you need to evaluate f. That is, you found "k1 for c", but you need to find "k1 for b" and "k1 for z" as well. For clarity, denote these as k1,c,k1,b,k1,zk_{1, c}, k_{1, b},k_{1, z}.

Then k2 (for c, so k2,ck_{2,c} if we wanted to be consistent about notation) is going to be

hf(cn+12k1,c,bn+12k1,b,zn+12k1,z)h f(c_n+\frac{1}{2} k_{1,c}, b_n+\frac{1}{2} k_{1,b}, z_n+\frac{1}{2} k_{1,z})

So you'd find all the k_2, then do something similar to find all the k_3, and then the k_4.

In terms of implementation, you *really* want to get comfortable with the idea of y being a vector, however.


this has cleared it up for me so much, thank you xx

Quick Reply

Latest