2
$\begingroup$

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.

  • 0
    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!2011-07-14

3 Answers 3

1

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.

0

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:

$y(t+h)=y(t)+hz\left(t+\frac{h}{2},y(t)+\frac{h}{2}z(t,y(t))\right)$

where

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

0

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

  • 0
    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.2011-07-15