Euler-scheme discretization for 2 dimensional vector field ODE

numerical methodsordinary differential equationsVector Fields

Let $V: \mathbb{R}^m \rightarrow \mathbb{R}^m$ be a vector field on $\mathbb{R}^m$. An ODE is the equation:
$$X_t = X_0 + \int_0^t V(X_s)ds$$
where $X: \mathbb{R}_{+} \rightarrow \mathbb{R}^m, X_0\in \mathbb{R}^m$. Euler scheme to solve this ODE is as follows:

  1. Choose time points $0=t_0<t_1<\dots<t_n$
  2. $\tilde{X}_{t_0} :=X_0$
  3. $\tilde{X}_{t_{k+1}} := \tilde{X}_{t_k} + V(\tilde{X}_{t_k})(t_{k+1} – t_{k})$

Now to the exercise:

Consider a 2-dimensional vector field $V(x) = (-x_2,x_1)$ and implement Euler scheme with $X_0 = (1,0)$ on interval $[0,7]$. Use different $n$s.

The solution to this should be a circle for some reason, however my solution does definitely not remind a circle:

n <- 1000
tt <- seq(0,7,length.out = n)
xx <- matrix(0,n,2)
xx[1,] <- c(1,0)

vv <- function(x){
  return(c(-x[1],x[2]))
}

for(i in 1:(n-1)){
  xx[i+1,] <- xx[i,]+ vv(xx[i,])*(tt[i+1]-tt[i])
} 

What did I do wrong? This is quite important question, as there are more of such in the assignment.

Best Answer

For the specific given task, you can easily simulate the solution manually using complex numbers. If $z=x_1+ix_2$, then $v(z)=iz$. This gives the exact solution as $z(t)=e^{it}z(0)=\cos t+i\sin t$ which indeed traces a circle. The Euler method computes $$ z_{n}=(1+ih)z_{n-1}=(1+ih)^nz_0=(1+h^2)^{n/2}e^{i\phi n} $$ where $\phi=\arg(1+ih)=\arctan(h)$. Or in another way $$ z_n=e^{n(ih+\frac12h^2-\frac13ih^3-\frac14h^4+...)}=e^{\frac12ht_n(1-\frac12h^2+...)}e^{it_n(1-\frac13h^2+..)} $$ This gives an outwards spiral that gets tighter the smaller $h$ is. As a secondary effect one gets that the angular speed is slower than the exact solution, this error also reducing for falling $h$.

Related Question