Partial Differential Equations

We implemented a computer code to solve the partial differential equation

∂y/∂t = v(t,x) y'' + p(t,x) y' + q(t,x) y + f(t,x)

with initial and boundary conditions given by

y(0,x) = y0(x),   y(t,a) = A(t),   y(t,b) = B(t).

To do this we used a finite difference approximation of the spatial derivatives on the right hand side of the equation to obtain a system of ordinary differential equations

dY/dt = L(t) Y(t) + F(t)

where L(t) is a tridiagonal matrix and Y(t) and F(t) are vectors.

The Numeric Code

The code pdeuler.c solves this system using Euler's method

Yn+1 = Yn + k (L(tn) Yn + F(tn))

and the code pdetrap.c solves this system using the trapezoid method

(I - (k/2) L(tn+1)) Yn+1 = Yn + (k/2) (L(tn) Yn + F(tn) + F(tn+1)).

Note that these numeric schemes do not yield convergent approximations for all possible choices of v(t,x), p(t,x), q(t,x) and f(t,x). In particular, not all partial differential equations of this form even have unique differentiable solutions. Moreover, for numerical stability the ratio r=k/h2 must also be small.

To test our programs we choose

v(t,x)=0.01,   p(t,x)=0,   q(t,x)=0,   f(t,x)=0

to obtain the heat equation.

Plotting the Output

We used a Makefile to compile the programs and create the output files pdeuler.out and pdetrap.out. The gnuplot commands

display the initial condition

The gnuplot commands

create a plot of y(T,x) versus x which compares the approximation obtained by Euler's method to the approximation obtained by the trapezoid method.

The graphs of the two approximations overlay each other and represent a smoothed version of the initial condition. Since it is known that diffusion of heat physically smoothes the temperature distribution, this is a partial check of the two methods.


Last Updated: Sun Dec 7 20:25:02 PST 2014