+ - 0:00:00
Notes for current slide
Notes for next slide

On Schemes for Exponential Decay

Hans Petter Langtangen at Center for Biomedical Computing, Simula Research Laboratory and Department of Informatics, University of Oslo

Sep 24, 2015

Copyright 2015, Hans Petter Langtangen. Released under CC Attribution 4.0 license

1 / 11

Goal

The primary goal of this demo talk is to demonstrate how to write talks with DocOnce and get them rendered in numerous HTML formats.

2 / 11

Problem setting and methods

3 / 11

We aim to solve the (almost) simplest possible differential equation problem

u(t)=au(t)

u(0)=I

Here,

  • t(0,T]
  • a, I, and T are prescribed parameters
  • u(t) is the unknown function
  • The ODE (1) has the initial condition (2)

4 / 11

The ODE problem is solved by a finite difference scheme

  • Mesh in time: 0=t0<t1<tN=T
    • Assume constant \( \Delta t = t{n}-t{n-1} \)
    • un: numerical approx to the exact solution at tn

The θ rule,

un+1=1(1θ)aΔt1+θaΔtun,n=0,1,,N1

contains the Forward Euler (θ=0), the Backward Euler (θ=1), and the Crank-Nicolson (θ=0.5) schemes.

5 / 11

The Forward Euler scheme explained

6 / 11

Implementation

Implementation in a Python function:

def solver(I, a, T, dt, theta):
"""Solve u'=-a*u, u(0)=I, for t in (0,T]; step: dt."""
dt = float(dt) # avoid integer division
N = int(round(T/dt)) # no of time intervals
T = N*dt # adjust T to fit time step dt
u = zeros(N+1) # array of u[n] values
t = linspace(0, T, N+1) # time mesh
u[0] = I # assign initial condition
for n in range(0, N): # n=0,1,...,N-1
u[n+1] = (1 - (1-theta)*a*dt)/(1 + theta*dt*a)*u[n]
return u, t
7 / 11

How to use the solver function

A complete main program.

# Set problem parameters
I = 1.2
a = 0.2
T = 8
dt = 0.25
theta = 0.5
from solver import solver, exact_solution
u, t = solver(I, a, T, dt, theta)
import matplotlib.pyplot as plt
plt.plot(t, u, t, exact_solution)
plt.legend(['numerical', 'exact'])
plt.show()
8 / 11

Results

9 / 11

The Crank-Nicolson method shows oscillatory behavior for not sufficiently small time steps, while the solution should be monotone

10 / 11

The artifacts can be explained by some theory

Exact solution of the scheme:

un=An,A=1(1θ)aΔt1+θaΔt.

Key results:

  • Stability: |A|<1
    • No oscillations: A>0
    • Δt<1/a for Forward Euler (θ=0)
    • Δt<2/a for Crank-Nicolson (θ=1/2)

Concluding remarks: Only the Backward Euler scheme is guaranteed to always give qualitatively correct results.

11 / 11

Goal

The primary goal of this demo talk is to demonstrate how to write talks with DocOnce and get them rendered in numerous HTML formats.

2 / 11
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow