matlab pde
TRANSCRIPT
![Page 1: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/1.jpg)
CHEE 412Partial Differential Equations in
MATLABHadis Karimi
Queen’s UniversityMarch 2011
1
![Page 2: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/2.jpg)
Introduction
• Parabolic partial differential equations are encountered in many chemical engineering applications
• MATLAB’s pdepe command can solve these• For partial dierential equations in two space
dimensions PDE Toolbox can solve four types of equations: Elliptic, Parabolic, Hyperbolic and Eigenvalue
2
![Page 3: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/3.jpg)
Agenda• Solving a parabolic PDE in MATLAB using “pdepe” function• A mass transfer example• A heat transfer example• Solving a system of parabolic PDE’s in MATLAB using “pdepe”
function• A mass transfer example• Solving other types of PDE’s using PDE toolbox• A heat transfer example using PDE toolbox
3
![Page 4: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/4.jpg)
PDE in One Space Dimension
• The form of Parabolic PDE’s in MATLAB
• Boundary conditions
• Initial conditions
)xu
,u,t,x(s))xu
,u,t,x(bx(x
xtu
)xu
,u,t,x(c mm
0)u,u,t,xl(b).t,xl(q)u,t,xl(p x 0)u,u,t,xr(b).t,xr(q)u,t,xr(p x
)x(f)x,0(u 4
m=0 for Cartesian, for cylindrical, 1 and for spherical 2
![Page 5: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/5.jpg)
Example 1: A Mass Transfer System
X=
L 2
2
2
xC
DtC
5
![Page 6: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/6.jpg)
Initial Conditions
X=
L 2
6
0
1
CC
Lx0
0C
LxL 21
0C
LxL 32
@ t=0
![Page 7: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/7.jpg)
Boundary Conditions
X=
L 3
7
0xC
0x
0xC
Lx 3
xC
DxC
D
Lx
32
2
xC
DxC
D
Lx
21
1
![Page 8: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/8.jpg)
Steps to Solve PDE’s in MATLAB
1- Define the system 2- Specify boundary conditions3- Specify initial conditions4- Write System m-file 5-Write Boundary Conditions m-file6- Write Initial condition m-file7-Write MATLAB script M-file that solves and
plots
8
![Page 9: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/9.jpg)
1- Define the System
0m
9
2
2
xC
DtC
1)u,u,t,x(c x
x11x u.DxC
.D)u,u,t,x(b
0)u,u,t,x(s x
)xu
,u,t,x(s))xu
,u,t,x(bx(x
xtu
)xu
,u,t,x(c mm
![Page 10: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/10.jpg)
2-Specify Boundary Conditions0
xC
,0x
10
0)u,t,0(p
1
121 D
DD)t,L(q
0)u,t,L(p 1
0)u,u,t,xl(b).t,xl(q)u,t,xl(p x
0)u,u,t,xr(b).t,xr(q)u,t,xr(p x
1D1
)t,0(q
0xC
DD
)DD(,Lx
orxC
DxC
D,Lx
11
121
211
xC
.D1
xC
.Db 1
![Page 11: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/11.jpg)
3- Specify Initial Conditions
0
0
C)x,0(u
C)x,0(C
11
)x(f)x,0(u
![Page 12: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/12.jpg)
4- Write System m-file
function [c,b,s] = system(x,t,u,DuDx)
c = 1;
b =D1*DuDx;
s = 0;
end
12
![Page 13: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/13.jpg)
5-Write Boundary Conditions m-file
function [pl,ql,pr,qr] = bc1(xl,ul,xr,ur,t)
pl = 0;ql = 1/D1;pr = 0;qr = (D2-D1)/D1;end
13
![Page 14: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/14.jpg)
6- Write Initial Conditions m-file
function value = initial1(x)
value = C0;
end
14
![Page 15: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/15.jpg)
7-Write MATLAB script M-file that solves and plots
m = 0;%Define the solution meshx = linspace(0,1,20);t = linspace(0,2,10);%Solve the PDEu = pdepe(m,@system,@initial1,@bc1,x,t);%Plot solutionsurf(x,t,u);title('Surface plot of solution.');xlabel('Distance x');ylabel('Time t');
15
![Page 16: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/16.jpg)
Results
16
![Page 17: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/17.jpg)
Example 2: A Heat Transfer System
17
L
x
T=0 2
2
p xT
ktT
c
''qxT
k
0)0,L(T
0)0,x(T
q”
![Page 18: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/18.jpg)
Defining System
18
0sxT
kb
1c
)xu
,u,t,x(s))xu
,u,t,x(bx(x
xtu
)xu
,u,t,x(c mm
2
2
p xT
ktT
c
![Page 19: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/19.jpg)
Defining System
function [c,b,s]=pdecoef(x,t,u,DuDx)
global rho cp k
c=rho*cp;
b=k*DuDx;
s=0;
end
19
![Page 20: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/20.jpg)
Initial Conditions
function u0=pdeic(x)
u0=0;
end
20
![Page 21: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/21.jpg)
Boundary Conditions
21
''qxT
k
0)u,u,t,xl(b).t,xl(q)u,t,xl(p x 0)u,u,t,xr(b).t,xr(q)u,t,xr(p x
0)0,L(T xT
kb
Remember
x=Lp=T=urq=0
x=0p=q”q=10q
xT
k ''
or
![Page 22: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/22.jpg)
Writing Boundary Condition m-file
function[pl,ql,pr,qr]=pdebc(xl, ul,xr,ur,t)
global q
pl=q;
ql=1;
pr=ur;
qr=0;
end22
![Page 23: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/23.jpg)
Calling the Solver
tend=10;
m=0;
x=linspace(0,L,200);
t=linspace(0,tend,50);
sol=pdepe(m,@pdecoef,@pdeic,@pdebc,x,t);
23
![Page 24: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/24.jpg)
Plotting
Temperature=sol(:,:,1);
figure
plot(t,Temperature(:,1))
24
![Page 25: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/25.jpg)
System of PDE’s in MATLAB
)u,u,t,x(s))u,u,t,x(bx(x
xu)u,u,t,x(c
.
.
.
)u,u,t,x(s))u,u,t,x(bx(x
xu)u,u,t,x(c
)u,u,t,x(s))u,u,t,x(bx(x
xu)u,u,t,x(c
xnxnmm
ntxn
x2x2mm
t2x2
x1x1mm
t1x1
25
![Page 26: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/26.jpg)
Boundary Conditions
26
0)u,u,t,xr(b).t,xr(q)u,t,xr(p
0)u,u,t,xl(b).t,xl(q)u,t,xl(p
.
.
.
0)u,u,t,xr(b).t,xr(q)u,t,xr(p
0)u,u,t,xl(b).t,xl(q)u,t,xl(p
xnnn
xnnn
x111
x111
![Page 27: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/27.jpg)
Initial Conditions
27
)x(f)x,0(u
.
.
.
)x(f)x,0(u
)x(f)x,0(u
nn
22
11
![Page 28: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/28.jpg)
MucosaMucosa
SalivaSaliva
RL RS
Example 3: Mass Transport in the Saliva Layer
28
Drug Transport Direction
Lozenge
Blood Stream
RM
gvg
2g
2
gg
1v1
21
2
11
ck)r
c
r2
r
c(D
t
c
ck)rc
r2
rc
(Dtc
![Page 29: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/29.jpg)
MucosaMucosa
SalivaSaliva
RL
Boundary Conditions
29
Drug Transport Direction
Lozenge
Blood Stream
)c)(cc(Dk
r
C
)c)(cc(Dk
rC
LLL
LLL
RrggRrgg,solgg
dRr
g
Rr11Rrgg,solg1
dRr
1
![Page 30: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/30.jpg)
MucosaMucosa
SalivaSaliva
Boundary Conditions
30
Drug Transport Direction
Lozenge
Blood Stream
SS
SS
RrGRrgg
Rr2Rr11
ccK
ccK
RS
![Page 31: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/31.jpg)
MucosaMucosa
SalivaSaliva
Initial Conditions
31
Drug Transport Direction
Lozenge
Blood Stream
Before any drug is released (at time = 0), the drug and glucose concentrations in the saliva are equal to zero: C1 =Cg =0
0
0)x,0(u
![Page 32: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/32.jpg)
System
r2g
r11
gg
11
uD
uD
r
cD
rc
Db
2m
1
1c
2v
1v
gv
1v
uk
uk
ck
cks
32
gvg
2g
2
gg
1v1
122
1v1
21
2
11
ck)r
c
r2
r
c(D
t
c
ck)rc
Dr(r
rck)rc
r2
rc
(Dtc
![Page 33: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/33.jpg)
Boundary Conditions at RL
33
)cc)(cc(Dk
DrC
DLLL Rr11Rrgg,sol
g1
d1Rr
11
)u)(uc(Dk
D
)u)(uc(Dk
D
)u,t,R(p
LL
LL
Rrg1Rr2g,solgg
dg
Rr11Rr2g,solg1
d1
L
)cc)(cc(Dk
Dr
CD
LLL RrggRrgg,solgg
dgRr
gg
1
1)u,t,R(q L
![Page 34: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/34.jpg)
Boundary Conditions at Rs
0
0)u,t,R(q s
34
SS
SS
RrGRrgg
Rr2Rr11
ccK
ccK
SS
SS
SS
SS
RrGRr2g
Rr2Rr11
RrGRrgg
Rr2Rr11
scuK
cuK
ccK
ccK)u,t,R(p
![Page 35: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/35.jpg)
System
function [c,b,s] = eqn (x,t,u,DuDx)
c = [1; 1];b = [D1; Dg] .* DuDx;s = [-kv*u(1); -kv*u(2)]; end
35
![Page 36: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/36.jpg)
Boundary Conditions
function [pl,ql,pr,qr] = bc2(xl,ul,xr,ur,t)
pl = [D1*kd/D1g*(csolg-ul(2))*(rou1 -ul(1))); Dg*kd/Dgg*(csolg-ul(2))*(roug-ul(2)))];
ql = [-1; -1];
pr = [K1*ur(1)-c2Rs; Kg*ur(2)-cGRs];
qr = [0; 0];
end
36
![Page 37: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/37.jpg)
Initial Conditions
function value = initial2(x);
value = [0;0];
end
37
![Page 38: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/38.jpg)
Solving and Plottingm = 2;x = linspace(0,1,10);t = linspace(0,1,10);sol = pdepe(m,@eqn,@initial2,@bc2,x,t);u1 = sol(:,:,1);u2 = sol(:,:,2);subplot(2,1,1)surf(x,t,u1);title('u1(x,t)');xlabel('Distance x');ylabel('Time t');subplot(2,1,2)surf(x,t,u2);title('u2(x,t)');xlabel('Distance x');ylabel('Time t');
38
![Page 39: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/39.jpg)
Plotting
39
![Page 40: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/40.jpg)
Single PDE in Two Space Dimensions
1. Elliptic
2. Parabolic
3. Hyperbolic
4. Eigenvalue
40
fau)uc.(
fau)uc.(du t
fau)uc.(du tt
duau)uc.(
![Page 41: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/41.jpg)
Example 4
0T2
T=10 T=0Laplace’s Equation
No Heat
No Heat
41
0yT
xT
2
2
2
2
![Page 42: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/42.jpg)
Step 1• Start the toolbox by typing in
>> pdetool at the Matlab prompt
42
![Page 43: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/43.jpg)
Step 2Select Heat Transfer Application
43
![Page 44: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/44.jpg)
Step 3The Draw Menu
44
![Page 45: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/45.jpg)
Step 4Create Rectangle
45
![Page 46: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/46.jpg)
Step 5The Boundary Menu
46
![Page 47: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/47.jpg)
Step 6Display Options
47
![Page 48: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/48.jpg)
Step 7Select Boundary 4
48
![Page 49: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/49.jpg)
Step 8 Specify Boundary Condition
Steps 9 - 10 Select Boundary 1 and specify Steps 9 - 10 Select Boundary 1 and specify conditioncondition
49
![Page 50: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/50.jpg)
Steps 11 - 14 Specify remaining boundary conditions
50
![Page 51: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/51.jpg)
Step 15 The PDE Mode
51
![Page 52: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/52.jpg)
Step 16 PDE Menu
52
![Page 53: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/53.jpg)
Step 17 Specify PDE parameters
53
)v.(0T2
![Page 54: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/54.jpg)
PDE Solution: T Calculated
54
![Page 55: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/55.jpg)
Step 18 The Plot Menu
55
![Page 56: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/56.jpg)
Step 19 Specify plotting parameters
56
![Page 57: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/57.jpg)
Finally the Solution: Temperature Contours
57
![Page 58: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/58.jpg)
Thank You!
Any questions?
58
![Page 59: Matlab Pde](https://reader033.vdocuments.mx/reader033/viewer/2022061406/55cf9d39550346d033acbf70/html5/thumbnails/59.jpg)
References
• P. Howard, Partial Differential Equations in MATLAB 7.0, Spring 2005.
• Kim, K. S., & Simon, L. ,Transport Mechanisms in oral transmucosal drug delivery: Implications for pain management. Mathematical Biosciences , 93-100, 2011.
59