# runge kutta 4 question

I have a quick question that I'm having a little trouble with, it seems simple enough but i just need a bit of clarification.

If I had a system of ode's and I was to choose the runge kutta 4 method to solve, then how would i go about obtaining the correct equation for $k_2$ if the original function $f(x_n, t_n) = \frac{dx}{dt}$ is a function of, say, $\theta$ (and not $x$ or $t$)?

E.g. if $\frac{dx}{dt} = \cosh(\theta) = f(x_n, t_n)$ then for $k_1$, Ii would use $k_1 = h f(x_n, t_n) = h(\cosh(\theta))$

but for $k_2$ the general equation is $k_2 = h f(x_n + \frac{k_1}{2}, t_n + \frac{h}{2})$ so would my desired equation for $k_2$ specific to my problem be:

$k_2 = h(\cosh(\theta)+\frac{k_1}{2})$

or

$k_2 = h(\cosh(\theta+\frac{k_1}{2}))$ ?

Thanks!

-
But what is $\theta$ then? The equation $dx/dt = \cosh \theta$ doesn't make sense unless you tell us what $\theta$ is, and if it's related to $x$ or $t$ somehow. (If $\theta$ is just a parameter, then the right-hand side of the ODE can be seen as a constant, and the solution is $x(t)=x(0)+t \cosh \theta$; no need to use Runge-Kutta for that.) :) – Hans Lundmark Apr 13 '11 at 14:58
hi, sorry for not being too clear, but i have a system of non-linear coupled ode's, so, say d(theta)/dt = dx/dt. Does that help? – user7907 Apr 13 '11 at 15:04
Erhm, not really... So $\theta=x$ then?!? – Hans Lundmark Apr 13 '11 at 15:06
lol, sorry, i'm just using a very, very bad example, i don't want a specific answer, i just wanted to know the procedure for calculating the rk4 algorithm when the function f(x,t) is a function of another parameter which in turn is a function of x and t. – user7907 Apr 13 '11 at 15:11
mathuser, people might be much more helpful with your situation if you just post the "nonlinear coupled ODEs" that you have to begin with. – J. M. Apr 14 '11 at 1:23

As Hans Lundmark says, you should use the same variable on both sides of the equation. If $\theta$ is a function of $x$ you should plug that in to get everything in terms of $x$. If $\theta =x$, you are just confusing yourself by using one on the left and one on the right. you are trying to integrate $\frac{dx}{dt}=\cosh(x)$, as you say $k_1=h\cosh(x)$ and $k_2=hf(x+\frac{k_1}{2})=h\cosh(x+\frac{k_1}{2})$
If you have $\frac{d\theta}{dt}=f(x,\frac{dx}{dt},t)$ and $\frac{dx}{dt}=(x,t)$ you have two integrations and need two sets of $k$'s, one for $x$ and one for $\theta$. Is that what you were asking? – Ross Millikan Apr 13 '11 at 17:45