You are on page 1of 4

Matlab Solution of PDE’s

pdepe

There is a build in function for solving pds’e in Matlab—pdepe

It solves the general transient equation

c
u
t
 xm
 m
x
 
x f s (1)

u
Where m is 0 or a positive integer and c, f , s are functions of x, t , u,
x

Equation (1) has an initial condition of the form

u( x,0)  g ( x) (2) Think of g as the initial condition function icfun

Equation (1) also has the Boundary Conditions

p  qf  0 (3)

Where IMPORTANT p is a function of x, t , u


And q is a a function of x, t
For our example problem

C   C 
 k , 0  x  1 (1)
t x  x 

C (t  0, x  0)  0
C(t  0, x  0)  1, C(t  0, x  1)  0

We have the following settings

c 1
m0
C
f k
x
s0

g 0

And distinguishing between the left and right boundaries

pleft  C (0)  1
qleft  0
pright  C (1)
qright  0
To solve this problem in Matlab using the pdepe function we need to use
the following steps—refer to Solving PDE Problems in Matlab help

1. Identify the forms of c,f,s,g,q,p see abobve

2. Make and save a function that defines our forms for c, f , s

function [c,f,s] = expde(x,t,C,dCdx)


c = 1;
f = 1*dCdx;
s = 0;

Assuming k =1 here

3. Make and save a function that defines our initial condition

function C0 = expdeic(x)
C0 =0*x;

(note C0 has to be a vector with one value for each node point
The node point locations are stored in x (see below)

4. Make and save a function that defines our boundary conditions

function [pl,ql,pr,qr] = expdebc(xl,Cl,xr,Cr,t)


pl = Cl - 1;
ql = 0;
pr = Cr;
qr = 0;

5. Select mode points and time steps

x = linspace(0,1,11);
t = linspace(0,2,5);

Note the first line will make 11 node points 0.1 apart at
x = 0, 0.1, 0.2,---0.9, 1

The second line will provide solutions for the pde at times
t= 0, 0.5,1,1.5 and 2
THIS DOES NOT MEAN TIME STEP IS 0.5

6. Apply the inbuild pde solver with appropriate function handles

m = 0;
sol = pdepe(m,@expde,@expdeic,@expdebc,x,t);

When you look at sol each row will represent the profile of C at the relevant
time step

Here is an m-file code that rund pdepe once all of the functions have been
defined

clear all
x = linspace(0,1,11);
t = linspace(0,.125,5);
m = 0;
sol = pdepe(m,@expde,@expdeic,@expdebc,x,t);
plot(x,sol(5,:,1))

Here our time range has been chosen so that we can compare with our
explicit code in previous hand out

You might also like