0
$\begingroup$

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!

  • 0
    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.) :)2011-04-13
  • 0
    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?2011-04-13
  • 0
    Erhm, not really... So $\theta=x$ then?!?2011-04-13
  • 0
    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.2011-04-13
  • 0
    mathuser, people might be much more helpful with your situation if you just post the "nonlinear coupled ODEs" that you have to begin with.2011-04-14

1 Answers 1

1

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})$

  • 0
    so what if I have an equation for d(theta)/dt which is a function of dx/dt and a function of theta? I thought that when using the RK4 method, it is not necessary to integrate? (so in the equation for k1, k2 I do not have to express theta in terms of x and t) Do I not just plug in predetermined values of theta(0), step size, x(0) and t(0) to start the algorithm??2011-04-13
  • 0
    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?2011-04-13