TITLE: Experiments with Schemes for Exponential Decay
AUTHOR: Hans Petter Langtangen Email:hpl@simula.no at Center for Biomedical Computing, Simula Research Laboratory and Department of Informatics, University of Oslo.
DATE: August 20, 2012

__Summary.__
This report investigates the accuracy of three finite difference
schemes for the ordinary differential equation $u'=-au$ with the
aid of numerical experiments. Numerical artifacts are in particular
demonstrated.

TOC: on

# Section with multi-line equation.

======= Mathematical problem =======
label{math:problem}

idx{model problem} idx{exponential decay}

We address the initial-value problem

!bt
\begin{align}
u'(t) &= -au(t), \quad t \in (0,T], label{ode}\\
u(0)  &= I,                         label{initial:value}
\end{align}
!et
where $a$, $I$, and $T$ are prescribed parameters, and $u(t)$ is
the unknown function to be estimated. This mathematical model
is relevant for physical phenomena featuring exponential decay
in time.

# Section with single-line equation and a bullet list.

======= Numerical solution method =======
label{numerical:problem}

idx{mesh in time} idx{$\theta$-rule} idx{numerical scheme}
idx{finite difference scheme}

We introduce a mesh in time with points $0= t_0< t_1 \cdots < t_N=T$.
For simplicity, we assume constant spacing $\Delta t$ between the
mesh points: $\Delta t = t_{n}-t_{n-1}$, $n=1,\ldots,N$. Let
$u^n$ be the numerical approximation to the exact solution at $t_n$.

The $\theta$-rule is used to solve (ref{ode}) numerically:

!bt
\[
u^{n+1} = \frac{1 - (1-\theta) a\Delta t}{1 + \theta a\Delta t}u^n,
\]
!et
for $n=0,1,\ldots,N-1$. This scheme corresponds to

  * The Forward Euler scheme when $\theta=0$
  * The Backward Euler scheme when $\theta=1$
  * The Crank-Nicolson scheme when $\theta=1/2$

# Section with computer code taken from a part of
# a file. The fromto: f@t syntax copies from the
# regular expression f up to the line, but not
# including, the regular expression t.

======= Implementation =======

The numerical method is implemented in a Python function:

@@@CODE ../decay_theta.py  fromto: def theta_rule@def verify_three

# Section with figures.

======= Numerical experiments =======

idx{numerical experiments}

We define a set of numerical experiments where $I$, $a$, and $T$ are
fixed, while $\Delta t$ and $\theta$ are varied.
In particular, $I=1$, $a=2$, $\Delta t = 1.25, 0.75, 0.5, 0.1$.



# Subsection with inline figure (figure without caption).

===== The Backward Euler method =====

idx{BE}

FIGURE: [BE.png, width=800]



# Subsection with inline figure (figure without caption).

===== The Crank-Nicolson method =====

idx{CN}

FIGURE: [CN.png, width=800]



# Subsection with inline figure (figure without caption).

===== The Forward Euler method =====

idx{FE}

FIGURE: [FE.png, width=800]



===== Error vs $\Delta t$ =====

# Exemplify referring to a figure with label and caption.

idx{error vs time step}

How $E$ varies with $\Delta t$ for $\theta=0,0.5,1$
is shown in Figure ref{fig:E}.

FIGURE: [error.png, width=400] Error versus time step. label{fig:E}