Professional Documents
Culture Documents
TUTORIAL9:SOLVINGPDES2SOLUTIONS
3. UsingpdepetosolveaparticularPDE
Asafirststep,comparethePDEequations(4)(7)withMatlabsrequiredequationformsforpdepe,
equations(1)(3).Whatareappropriatevaluesorequationsthefollowingpdepeinputs?
m=0
c=1
f=dy/dx
s=0
u0=0
LefthandBC:
RighthandBC:
[note:whenm=0,bothxmandxm=1]
pl=0
ql=1
pr=A*(1yr) [note:yrmeansthevalueofyontherighthandboundary]
qr=1
Thescriptfilepdesim.mshouldlooklikethis:
% PDESIM: Solve a PDE using Matlab's PDE solver, pdepe
% Set simulation parameters
t = 0:0.2:5;
x = 0:0.2:1;
A = 2;
tol = 1e-3;
Page1
ThefunctionfilesolvePDE.mshouldlooklikethis:
function sol = solvePDE(xmesh,tspan,A,tol)
% SOLVEPDE: Solve for y(x,t) given by the PDE
%
%
dy/dt = d2y/dx2
%
%
BC1: dy/dx = 0
at x=0
%
BC2: dy/dx = A(1-y) at x=1
%
IC:
y = 0 at t=0
%
% for spatial points xmesh, at time points tspan, for parameter A and
% relative solution tolerance tol.
m = 0;
opts = odeset('Reltol',tol);
% Solve the PDE using pdepe
sol = pdepe(m,@pdefun,@icfun,@bcfun,xmesh,tspan,opts);
%
%
%
%
% Nested functions that embody the PDE equation(s), initial and boundary
% conditions
% (Note that parameter values passed through as arguments in the main
% function solvePDE are automatically available in the nested functions
% below.)
%-------------------------------------------------------------------------% PDE function
function [cfun,ffun,sfun] = pdefun(x,t,y,dydx)
cfun = 1;
ffun = dydx;
sfun = 0;
end
%-------------------------------------------------------------------------% Initial condition function
function y0 = icfun(x)
y0 = 0;
end
%-------------------------------------------------------------------------% Boundary condition function
function [pl,ql,pr,qr] = bcfun(xl,yl,xr,yr,t)
pl = 0;
ql = 1;
pr = -A*(1-yr);
qr = 1;
end
%-------------------------------------------------------------------------end
Page2
Theplotsshouldlooklikethis:
0.9
0.9
0.8
0.8
0.7
0.7
0.6
0.6
0.5
0.5
0.4
0.4
0.3
0.3
0.2
0.2
0.1
0.1
0.5
x
Fig 2
1
0.8
0.6
0.4
0.2
0
6
1
0.8
0.6
2
t
0.4
0
0.2
0
Page3
Doesthenumericalsolutionappeartosatisfytheinitialconditions,thetwoboundaryconditions,and
thesteadystatesolution?Explainbrieflyhowyouverifiedthisfromaninspectionofthegraphs.
IC:Fig1(a)andFig2clearlyshowthaty=0att=0forallx,sotheinitialconditionisok.
BC1:ThelefthandBCsaysthegradientdy/dxshouldbezeroatx=0.FromFig1(b),thegradient
seemstobenonzeroatthestart,butgetsclosertozeroasthesolutionprogresses,butthisis
difficulttojudgebecauseoftherelativelycoarsenodespacing(x=0.2).
BC2:TherighthandBCsaysthegradientshouldrangefromdy/dx=Awheny(1,t)=0downto
dy/dx=0wheny(1,t)=1.ThisishardtojudgefromquantitativelyfromFig1(b)withoutactually
calculatingthegradient,butitdoesappeartobeconsistentOntherighthandboundary,the
slopeislowwhenyisnearone,andtheslopeincreaseswhenyisclosertozero.
SS:Fig1(a)andFig(2)bothshowthaty1forallxastincreases,soitseemstogetthesteady
statesolutionright.
Reducethespatialnode(x)spacingfrom0.2to0.05.Rerunthesimulation andcommentagainon
theboundaryconditionatx=0:
Witharoundfourtimesasmanynodesasbefore,thegradientdy/dxatx=0seemstobecloserto
zeroasrequiredbyeqn(5),evenatshorttimes.WithmorenodesIthinkitwouldgetcloserstill.
Thesolutionwiththenodalspacingreducedtox=0.05
canbeseenopposite:
0.6
0.5
0.4
0.3
0.2
0.1
0
Page4
0.5
x
4. Usingpdepetosolvethecatalystpelletmodel
Thescriptfilepdesimcat.mshouldlooklikethis:
Page5
ThefunctionfilesolvePDEcat.mshouldlooklikethis:
% Nested functions that embody the PDE equation(s), initial and boundary
% conditions
% (Note that parameter values passed through as arguments in the main
% function solvePDE are automatically available in the nested functions
% below.)
%-------------------------------------------------------------------------% PDE function
function [cfun,ffun,sfun] = pdefun(r,t,c,dcdr)
cfun = 1;
ffun = alpha*dcdr;
sfun = -beta*c;
end
%-------------------------------------------------------------------------% Initial condition function
function c0 = icfun(r)
c0 = 0;
end
%-------------------------------------------------------------------------% Boundary condition function
function [pl,ql,pr,qr] = bcfun(rl,cl,rr,cr,t)
pl = 0;
ql = 1/alpha;
pr = cr-1;
qr = 0;
end
%-------------------------------------------------------------------------end
Page6
Theplotsshouldlooklikethis:
0.9
0.9
0.8
0.8
0.7
0.7
0.6
0.6
0.5
0.5
0.4
0.4
0.3
0.3
0.2
0.2
0.1
0.1
0.5
t
0.5
r
Fig 2
1
0.8
0.6
0.4
0.2
0
1
1
0.8
0.5
0.6
0.4
t
0.2
0
Page7
5. Checkingthesolutionatsteadystate
After the extra statements that calculate the steady state errors and draw the graph have been
addedtopdesimcat.m,thefollowinggraphshouldbeproduced:
-3
x 10
0.9
0.8
0.7
c err
0.6
0.5
0.4
0.3
0.2
0.1
0
0.1
0.2
0.3
0.4
0.5
r
0.6
0.7
0.8
0.9
Alongwiththeoutput:
Page8
Briefsensitivitystudy
Performseveralsensitivityrunsassetoutinthetablebelow,recordtheresultsandaddacomment:
Relative
Number cerrmax
cerravg
Comment
tf
tolerance ofnodes
1
1e3
11
8.72e004 2.96e004 Base case. The errors are already very
small. But, this really doesnt check
anythingaboutthetransientsolution.
2
1e3
11
1e3
11
1e6
11
1e6
21
1e6
41
6. Challengeproblem(optional)
Ver1.0(26/4/2012)
Page9