Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two functions, $f(t,x)$ and $g(t,u)$, where $\frac{d}{dt}u=f(t,x)$ and $\frac{d}{dt}x=g(t,u)$.

I am trying to discretize the integral of this system in order to track $x$ and $u$. I have succeeded using Euler integration, which is quite simple, since $x(t)$ and $u(t)$ are both known at $t$:

$u(t+h) = u(t) + h f(t,x(t))$

$x(t+h) = x(t) + h g(t,u(t))$

However, I am now trying to implement mid-point integration to get more accurate results. (Eventually Runge-Kutta but I am stuck here for now.)

EDIT: nevermind, if I'd written out the mid-point rule properly in the original question this wouldn't have been a problem. Edited to remove misleading math from the web.

share|cite|improve this question
This is an ODE for a vector-valued function $t\mapsto(u(t),x(t))$. Don't be misled by the fact that $f$ does not depend on $u$ nor $g$ on $x$. Runge-Kutta apllies to such ODE's as well; see here: – Christian Blatter Jul 13 '11 at 16:06
Of course, I'm so used to thinking one-dimensionally that it didn't even occur to me. Expressing it as a single function on a 2-vector made the whole thing work out, thank you! – Steve Jul 14 '11 at 1:55
@Christian, yours makes an answer to this question that Steve can accept. – J. M. Jul 14 '11 at 10:41
up vote 1 down vote accepted

I'm expanding my comment.

The fact that $f$ does not depend on $u$ and $g$ does not depend on $x$ could be of significance if one tried to solve the two differential equations explicitly. But otherwise we just have a differential equation for a vector-valued function $y(t):=\bigl(u(t),x(t)\bigr)$, namely $$\dot y(t)\ =\ \bigl(f(t, u(t)),g(t,x(t))\bigr)\ .$$ The general existence and uniqueness theorem as well as the usual numerical methods (e.g. Runge-Kutta) are applicable to this setup.

It could be that the functions $t\mapsto u(t)$ and $t\mapsto x(t)$ have "different time scales"; e.g., $u(\cdot)$ could be a "slow" function and $x(\cdot)$ could be a rapidly oscillating function. This is the phenomenon of "stiffness" which requires special measures in numerical work.

share|cite|improve this answer

Per Christian's suggestion I re-thought the question in terms of a state vector $y=[u, x]$, with a single derivative function $[\dot{u},\dot{x}]=\dot{y}=z(t,x,u)$.

This allows to express the mid-point method as usual:



$z(t,x,u) = [f(t,x), g(t,x)]$

share|cite|improve this answer

You can write the mid-point rule even with both equations separated as was your original post as $$u(t+h)=u(t)+hf\Bigl(t+\frac{h}{2},\underbrace{x(t)+\frac{h}{2}g(t,u(t))}_{\approx x(t+h/2)}\Bigr)$$

and mutatis mutatndis for $x(t+h)$.

P.S. I find your notation a bit verbose; personally I got used to using indices $-$, $\ominus$, $\circ$, $\oplus$, $+$ for values at $t-h$, $t-\frac{h}{2}$, $t$, $t+\frac{h}{2}$, $t+h$; then the equation would read

$$\dot u^+=u^\circ+h\dot u^\oplus\left(x^\circ+\frac{h}{2}\dot x^\circ(u^\circ)\right)$$

share|cite|improve this answer
You're absolutely right. My mistake was actually writing the mid-point method equations wrongly. If I'd written them correctly there would have been no interdependency. Sorry for the noise. I've never seen your notation before, however. – Steve Jul 15 '11 at 4:45
I invented it for my thesis :-) there was a chapter on leapfrog integration and writing $t+\frac{\Delta t}{2}$ all the time drove me nuts. It is in no way standard. – eudoxos Jul 15 '11 at 9:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.