Professional Documents
Culture Documents
1D Pde
1D Pde
1D Pde
:'(
402 PARTIAL DIFFERENTIAL EQUATIONS
9.1 ELLIPTIC PDE ?s an e@ample, e ill deal ith a special t)pe of elliptic equation called -elmholtA/s equation, hich is ritten as )2u(x, y) # &(x, y)u(x, y) * d2u(x, y) d2u(x, y) !!!!!!!B!!!!!!(!!!!!!!!!B!!!!!!h &(x, y)u(x, y) * fix, y) (&.(.() over a domain + = ,(x, y)\xo C x < Xf, yo < y < yf- ith some boundar) conditions of U(XQ, y) = bxo(y), u(xf, y) = bxf(y), (&.(.*) u(x, yo) = byo(x), and u(x, yf) = byf(x)
(cf) Equation (&.(.() is called Poisson/s equation if &(x, y) = ' and it is called Daplace/s equation if &(x, y) $ ' and f(x, y) $ '.
+o appl) the difference method, e divide the domain into !x sections, each of length ?@ $ (xf - xQ).!x along the @!a@is and into !y sections, each of length ?) $ (yf - y/).!y along the )!a@is, respectivel), and then replace the second derivatives b) the three!point central difference appro@imation (4.>.() = "E!!!!!!!!!!!E!!!!!!!!" ith X0 = xQ # 0 Ax, y" = yQ1iAy (&.(.>a)
2 ui1i0 - 2ii00 # ,!FiG $!!!!!!!!!!!!!!!!!E!!!!!!!!!!!!! ith U00 = u(X0, y")
Ay
(&.(.>b)
ww.,
so that, for ever) interior point (x0, y") ith ( C i < !y - ( and ( C 0 C !x - (, e obtain the finite difference equation u i,0 1 l 2 2U,0 # W%5!l Hi#l,G " * ,!G # W,!l,G !!!!!!!!!!!!2322!!!!!!!!!!!!!!/!!!!!!!!!!!!!!2\24!!!!!!!!!!!!!!(H 5i6ui,0 2 6i6 (&!(.:) here ,!G $ U(X6, yi), fi0 $ f(x0, yi), and g,G $ &(x0, yi)
+hese equations can someho be arranged into a s)stem of simultaneous equations ith respect to the (!y - \),!X - () variables ,uu,uU2, 777, WI.2.!I, u82,i, 7 7 7 ,u82,!x-i, 7 7 7 ,U!,-9,9,U!,-9,2, 7 7 7 ,U!,-9,!X-9-, but it seems to be mess) to orI ith and e ma) be reall) inJ trouble as !x and !y become large. ? simpler a) is to use the iterative methods introduced in 7ection *.4. +o do so, e first need to shape the equations and the boundar) conditions into the follo ing form,
u
(&.(.4a)
ELLIPTIC PDE
uQ6 = by/(x0),
*(?@* # ?)*) rx , *(?@* # ?)*) r:, (&.(.<) -o do e initialiAe this algorithm? If e have no priori Ino ledge about the solution, it is reasonable to taIe the average value of the boundar) values as the initial values of ,!,K. +he obGective of the 2?+D?8 routine Hpoisson.mH is to solve the above equation.
function [u,x,y] = poisson(f,g,bx0,bxf,by0,byf,D,Mx,My,tol,MaxIter-) %solve u xx ! u yy ! g(x,y)u = f(x,y) % over- t"e region D = [x#$xf,y0,yf] = %(x,y) &x0 '= x '= xf, y# '= y '= yf( % )it" t"e boun*ary +on*itions, % u(x0,y) = bx#(y), u(xf,y) = bxf(y) % u(x,y0) = by#(x), u(x,yf) = byf(x) % Mx = - of subintervals along x axis % My = - of subintervals along y axis % tol , error tolerance % Maxlter, t"e .axi.u. - of iterations x# = D(/)0 xf = D(1)0 y# = D(2)0 yf = D(3)0 *x = (xf - x#)4Mx0 x = x# ! [0,Mx]5*x0 *y = (yf - y#)4My0 y = y# ! [0,My]65*y0 Mx/ = Mx ! /0 My/ = My ! /0 %7oun*ary con*itions for . = /,My/, u(.,[/ Mx/])=[bx#(y(.)) bxf(y(.))]0 en* %left4rig"t si*e for n = /,Mx/, u([/ My/],n) = [by#(x(n))0 byf(x(n))]0 en* %botto.4top %initiali8e as t"e average of boun*ary values su. of bv = su.(su.([u(1,My,[/ Mx/]) u([/ My/],1,Mx)6]))0 u(1,My,1,Mx) = su. of bv4(15(Mx ! My for i = /,My for 9 = /,Mx :(i,9) = f(x(]),y(i))0 ;(i,9) = en* en* *x1 = *x5*x0 *y1 = *y5*y0 *xy1 = 15(*x1 ! *y1)0 rx = *x14*xy10 ry = *y14*xy10 rxy = rx5*y10 for itr = /,MaxIter for 9 = 1,Mx for i = 1,My u(i,9) = ry5(u(i,9 ! l)!u(i,9 - /)) ! rx5(u(i ! l,9)!u(i - /,9))$$$ ! rxy5(;(i,])5u(i,])- :(i,9))0 %<=$(>$/$?a) en* en* if itr @ / A .ax(.ax(abs(u u# = u0 en* 1))0 >(x(]),y(i))0 u#))) ' tol, breaB0 en* %solve poisson in <xa.ple >$/ f = inline(6#6$6x6$6y6)0 g = inline(606,6x6,6y6)0 x# = 00 xf = 30 Mx = 100 y# = 00 yf = 30 My = 100 bx# = inline(6exp(y) - cos(y)6,6y6)0 %(<>$/$1a) bxf = inline(6exp(y)5cos(3) - exp(3)5cos(y)6,6y6)0 %(<>$/$1b) by# = inline(6cos(x) - exp(x)6,6x6)0 %(<>$/$2a) byf = inline(6exp(3)5cos(x) - exp(x)5cos(3)6,6x6)0 %(<>$/$2b) D = [x# xf y# yf]0 Maxlter = ?000 tol = /e-30 [C,x,y] = poisson(f,g,bx#,bxf,by#,byf,D,Mx,My,tol,Maxlter)0 elf, .es"(x,y,C), axis([0 3 0 3 -/00 /00])
404
PARTIAL DIFFERENTIAL EQUATIONS
E@ample &.(. Daplace/s Equation"7tead)!7tate +emperature Distribution. 1onsider Daplace/s equation d2u(x,y) d2u(x,y) L u(x, y) * "<*<!!!!!!h ; ' for ' C @ C :, /<y <4 (E&.(.() dx2 dy2 ith the boundar) conditions u(/, y) = ey * cos y, u(4, y) = ey cos : " e4 cos y (E&.(.*) x u(x,/) = co$x * e , u(x,4) = e4co$x * ex co$4 (E&.(.>) What e ill get from solving this equation is u(x, y), hich supposedl) describes the temperature distribution over a square plate having each side : units long (Mig. &.(). We made the 2?+D?8 program HsolveFpoisson.mH in order to use the routine Hpoisson()H to solve Daplace/s equation given above and run this program to obtain the result sho n in Mig. &.*. 9o , let us consider the so!called 9eumann boundar) conditions described as du(x,y) br ()) for x = xQ (the left!side boundar)) (&.(.;)
=uy Dirichlet-type b !"#$ry c "#iti " %&!"cti " '$l!e &i(e#)
?)
A
*I Yo
!;E r7 HH;E M+H >?r\ HH;E rx2 2><r@2 >?r< H;E rL >Ar
-*~ +
**A
T~~T
!2N
J
;,y-1
i+1, j i - 1,i
EFFF0BCDFFFFEFFFFEFFFFEFFFFEFFFFEEFFFFE.
>iHHH4
5
%,)#i
fO!?@!frP
4 -*-4 !
Ne!+$""-type b !"#$ry c "#iti " %#eri'$ti'e &i(e#) "i#$%& 9.1 type b !"#$ry c "#iti "1
?$?f)
ELLIPTIC PDE
40'
Qeplacing the first derivative on the left!side boundar) (x = x/) b) its three!point central difference appro@imation (4.(.=) *?@ bCx ,y"), Ui,-i B %,( " 2bCx (yi)Ax for i = (, *,..., !y
(
(&.(.=)
and then substituting this constraint into Eq. (&.(.4a) at the boundar) points, e have Uifi = r>(uiA # , ) # rx(ui1UQ # ,!Fi,o) # rxy,&ifiuifi - fifi)
= ry(Ui,l # 2%,l " *E (yi)Ax) # E( E # Eo # W%!l,o) # rxy(&i,Qui,Q * fifi)
= 2ryuiA # rx(ui1,fi # ,Fi,o) # rxy(&ifiuifi - fifi - 2bCX (yi) . Ax) foii = l,2,888,!y-l (&.(.&) If the boundar) condition on the lo er side boundar) (y = y/) is also of 9eumann t)pe, then e need to rite similar equations for 0 = (, *,..., !x - ( UQ6 = r=(uQ61i # '5!i) # *r@ u # rxy(&/6u/0 - f/6 - 2b.yo(x0).Ay) (&.(.(') and additionall) for the left!lo er corner point (xQ, y/), uQQ = *(r) ',i # r@2i,o) # r@)feo,o2o,o " %o,o " *(E'()/o)%?@ # *EE,o(@')%?))) (&.(.(() )
3 4 3 2 2
405 PARTIAL DIFFERENTIAL EQUATIONS
9.2 P*+*,-LIC PDE ?n e@ample of a parabolic PDE is a one!dimensional heat equation describing the temperature distribution u(x,") (x is position, f is time) as d2u(x,") du(x,") A!!!!!!!!" $!!!!!!!!!! for ' C x < Xf, ' C " < ' (&.*.() In order for this equation to be solvable, the boundar) conditions (', f) $ bo(") 6 u(xf, ") = bxf(") as ell as the initial condition u(x, ') $ io(x) should be providedE 9.2.1 T.& Ex/0i1i2 ")%w3%4 E$0&% 5&2.)4 +o appl) the finite difference method, e divide the spatial domain R', xf- into ! sections, each of length ?@ $ xf.!, and divide the time domain R', +S into N segments, each of duration A" = '.N, and then replace the second partial
6&
! sections, each of length ?@ $ xf.!, and divide the time domain R', '- into A" derivative on the left!hand side and the first partial derivative on the right!hand side of the above equation (&.*.() b) the central difference appro@imation (4.>.() and the for ard difference appro@imation (4.(.:), respectivel), so that e have uE,, - 2uE # uE , uE1l - uE A_Li---------,------i-i = _,----------,_ (9 2 2) 2 Ax A" +his can be cast into the follo ing algorithm, called the e@plicit for ard Euler method, hich is to be solved iterativel), uE1l = r(uE1l # f!i) # (( ! *r) f ith r $ A!!!!!! (&.*.>) for i = (, *,..., ! * ( +o find the stabilit) condition of this algorithm, e substitute a trial solution uE = XEe6ll'< (F is an) nonAero integer) (&.*.:) into Eq. (&.*.>) to get E = r(e0,r.p 1 e-6?.p) 1 (( ! *r) $ ( ! *r(l ! 1T7(++%P)) (&.*.4) 7ince e must have P?.P C ( for nondivergence, the stabilit) condition turns out to be A" ( r $ A"! C ! (&.*.<) ?@* ! *
DEFE7#GI+ DD< 30H "eat exp(a,xf,I,it#,bx#,bxf,M,J)
0 78 t 78 T &!"cti " 9!:(:t; <. l'e $ !=(( 8 !=t & r 0 78 ( 78 (&: < I"iti$l C "#iti "> !%(:0) 8 itO%() < ? !"#$ry C "#iti "> !%0:t) 8 b(O%t): !%(&:t) .!bi"ter'$l. $l ", ( $(i. .!bi"ter'$l. $l ", t $(i. ( 8 90>@;AB#(C t 8 90>N;B#tC !%i:2) !%92 @ D 2;:") r2 8 2 - 2BrC b(&%t) < @ 8 E & < N 8 E & #( 8 (&0@C #t 8 T0NC & r i 8 2>@ D 2:
& r " 8 2>N D 2: r 8 $B#t0#(0#(: & r F 8 2>N & r i 8 2>@ !%i:FD2) 8 e"# e"# itO%(%i))C e"# 9b(O%t%"))C b(&%t%"));C e"# rB%!%i D 2:F) D !%i-2:F)) D r2B!%i:F)C <E-1%41213)
+his implies that as e decrease the spatial interval ?@ for better accurac), e must also decrease the time step A" at the cost of more computations in order not to lose the stabilit). +he 2?+D?8 routine HheatFe@p()H has been composed to implement this algorithm. 41212 The I+plicit ?$cF/$r# E!ler @eth # In this section, e consider another algorithm called the implicit bacI ard Euler method, hich comes out from substituting the bacI ard difference appro@imation (4.(.<) for the first partial derivative on the right! hand side of Eq. (&.*.() as ?! uE ! 2uE # uE
B:G D H
-1
Ax2
U- U
k-l
A" ru"G, # (( # 2r)u, * rui1l = u" ith r AA" ACx4 (&.*.;) (&.*.=) for i * (, *,..., ! * ( If the values of uEQ and uE! at both end points are given from the Dirichlet t)pe of boundar) condition, then the above equation ill be cast into a s)stem of simultaneous equations, ( # *r !r ' "r ( # *r "r ' !r ( # *r
00 0 0 0 0 0 0
( # *r !r !r ( # *r . u\ u\ u\ E
U
M2
- M-\ k-l
uH fc!(
l
M-\
FFry
# ru
M.
(&.*.&)
40I PARTIAL DIFFERENTIAL EQUATIONS
-o about the case here the values of du.dx\x=Q = bCQ(") at one end are given? In that case, e appro@imate this 9eumann t)pe of boundar) condition b)
*?@ bUE) (&.*.(') and mi@ it up ith one more equation associated ith the unIno n variable uEQ to get *ru # (( # 2r)iC * ru = n (( # *r) ' " *r G $ ' * 2rbCQ(E)Ax We augment Eq. (&.*.&) ith this to rite
l# *r "r ' ' ' '
*r
(&.*.(() (&.*.(*)
2rbC(E)Ax
U
!-\ # r22
(&.*.(>) Equations such as Eq. (&.*.&) or (&.*.(>) are reall) nice in the sense that the) can be solved ver) efficientl) b) e@ploiting their tridiagonal structures and are guaranteed to be stable o ing to their diagonal dominanc). +he unconditional stabilit) of Eq. (&.*.&) can be sho n b) substituting Eq. (&.*.:) into Eq. (&.*.=), -re-!F # (( # *r) ! re0>r.p = l.E, E = ( \! < ( l#*r(l !1T7(++%P)) (&.*.(:) +he follo ing routine HheatFimp()H implements this algorithm to solve the PDE (&.*.() ith the ordinar) (Dirichlet t)pe of) boundar) condition via Eq. (&.*.&).
function [u,x,t] = "eat i.p(a,xf,I,it#,bx#,bxf,M,J) %solve a u xx = u t for 0 '= x '= xf, 0 '= t '= I % Initial +on*ition, u(x,0) = it0(x)
< ? !"#$ry C "#iti "> !%0:t) 8 b(0%t): !%(&:t) 8 b(&%t)
% M = - of subintervals along x axis % J = - of subintervals along t axis *x = xf4M0 x = [0,M]65*x0 *t = I4J0 t = [0,J]5*t0 for i = /,M ! /, u(i,/) = it0(x(i))0 en* for n = /,J ! /, u([/ M ! /],n) = [bx0(t(n))0 bxf(t(n))]0 en* r = a5*t4*x4*x0 r1 = / ! 2*r; & r i 8 2>@ - 2
?(i,i) $ I2\ UEq.(&.*.&) i& i J 2: A%i - 2:i) 8 -rC A%i:i - 2) 8 -rC e"# e"# & r F 8 2>N D 2 b 8 9rB!%2:F)C Ker .%@ - 3:2)C rB!%@ D 2:F); D !%2>@:F - 2)C <E-1%41214) !%2>@:F) 8 tri#%A:b)C e"# u u u u PARA?OLIC PDE
404
41213 The Cr$"F-Nich l. " @eth # -ere, let us go bacI to see Eq. (&.*.;) and tr) to improve the implicit bacI ard Euler method. +he difference appro@imation on the left!hand side is taIen at time point E, hile the difference appro@imation on the right!hand side is taIen at the midpoint bet een time E and E - (, if e regard it as the central
difference appro@imation ith time step A".28 Doesn/t this seem to be inconsistent? -o about taIing the difference appro@imation of both sides at the same time point"sa), the midpoint bet een E # ( and E* for balance? In order to do so, e taIe the average of the central difference appro@imations of the left!hand side at the t o points E # ( and E, )ielding A
*B
..fc#i l i1l
+
J%#i
! 2uE 1 u
!l fc#i
Ax2 A" (&.*.(4) hich leads to the so!called 1ranI!9icholson method, "ruE1\ # *(( # r)uE1l * ruE1, * ruE1l # *(( " r)uE # ruEGl (&.*.(<) ith r * AA" Ale2 With the Dirichlet%9eumann t)pe of boundar) condition on x/.x!, respectivel), this can be cast into the follo ing tridiagonal s)stem of equations.
/*(( #(V)!(V -r *(( 1r) ' -r 00 /*(( -r) 00 r *(( -r) ' ' ( ' -r *(( 1r)
r <+ 'i
WJ#/ WJ#/
U
' '
(#c )
!*r 00
!-\
!
*(l#c) 5
)
' '
) 7i % 86
' ' O/
r 7 *(( ! r) 7
(&.*.(;) +his s)stem of equations can also be solved ver) efficientl), and its unconditional stabilit) can be sho n b) substituting Eq. (&.*.:) into Eq. (&.*.(<), *?.(( # r(l ! 1T7(++%P))) $ *(( ! r(l ! 1T7(++%P))), ( r(l ! cos
(%.F))
l#r(l !1T7(++%P)) WC( (&.*.(=)
+his algorithm is cast into the follo ing 2?+D?8 routine HheatF19()H.
420 PARTIAL DIFFERENTIAL EQUATIONS &!"cti " 9!:(:t; 8 he$t=CN%$:(&:T:itO:b(O:b(&:@:N) <. l'e $ !=(( 8 !=t & r 0 78 ( 78 (&: 0 78 t 78 T < I"iti$l C "#iti "> !%(:0) 8 itO%() < ? !"#$ry C "#iti "> !%0:t) 8 b(O%t): !%(&:t) 8 b(&%t) < @ 8 E & .!bi"ter'$l. $l ", ( $(i. < N 8 E & .!bi"ter'$l. $l ", t $(i. #( 8 (&0@C ( 8 90>@;AB#(C #t 8 T0NC t 8 90>N;B#tC & r i 8 2>@ D 2: !%i:2) 8 itO%(%i))C e"# & r " 8 2>N D 2: !%92 @ D 2;:") 8 9b(O%t%"))C b(&%t%"));C e"# r 8 $B#t0#(0#(C r2 8 2B%2 - r)C r2 8 2B%2 D r)C & r i 8 2>22 L 2 A%i:i) 8 r2C <E-1%41212M) i& i J 2: A%i - 2:i) 8 -rC A%i:i - 2) 8 -rC e"# e"# & r F 8 2>N D 2 b 8 9rB!%2:F)C Ker .%@ - 3:2)C rB!%@ D 2:F); 111 D rB%!%2>@ - 2:F - 2) D !%3>@ D 2:F - 2)) D r2B!%2>@:F - 2)C !%2>@:F) 8tri#%A:b)C <E-1%41212M) e"#
Example 9.2. Tne!Dimensional Parabolic PDE, -eat Mlo Equation. 1onsider the parabolic PDE
d2u(x,") du(x,")
forTC@ C (,' <" C'.( (E&.*.() dx2 d" ith the initial condition and the boundar) conditions u(x,/) = $i%i"x, u(/, ") = ', u(l,")= ' (E&.*.*) We made the 2?+D?8 program HsolveFheat. mH in order to use the routines HheatFe@p()H, HheatFimp()H, and HheatF19()H in solving this equation and ran this program to obtain the results sho n in Mig. &.>. 9ote that ith the spatial interval ?@ $ xf.! = (%*' and the time step A" = '.N = '.(%('' $ '.''(, e have A" '.''( r = A!!!!- = \!!!!!!!!G$'.: (E&.*.>) hich satisfies the stabilit) condition (r C (%*) (&.*.<) and all of the three methods lead to reasonabl) fair results ith a relative error of about '.'(>. 8ut, if e decrease the spatial interval to ?@ $ (%*4 for better resolution, e have r $ '.<*4, violating the stabilit) condition and the e@plicit for ard Euler method (HheatFe@p()H) blo s up because of instabilit) as sho n in Mig. &.>a, hile the implicit bacI ard Euler method (HheatFimp()H) and the 1ranI!9icholson method (HheatF19()H) orI quite ell as sho n in Migs. &.>b,c. 9o , ith the spatial interval ?@ $ (%*4 and the time step A" $ '.(%(*', the e@plicit method as ell as the other ones orIs ell ith a relative error less than '.''( in return
PARA?OLIC PDE
5 -,-""""
422
""-... 1 -r-""""
Re.!lt. & '$ri !. $l, rith+. & r $ "e-#i+e".i "$l p$r$b lic PDE> he$t e-!$ti "1
for some hat (>'U) more computations, despite that r $ '.4*'= doesn/t strictl) satisf) the stabilit)
condition. +his implies that the condition (r C (%*) for stabilit) of the e@plicit for ard Euler method is not a necessar) one, but onl) a sufficient one. 8esides, if it converges, its accurac) ma) be better than that of the implicit bacI ard Euler method, but generall) no better than that of the 1ranI!9icholson method.
<. l'e=he$t
a = /0 %t"e para.eter of (<>$1$/) itO 8 i"li"e%A.i"%piB()A:A(A)C <i"iti$l c "#iti " bx# = inline(6#6)0 bxf = inline(6#6)0 %boun*ary con*ition xf = /0 M = 1?0 I = 0$/0 J = /000 %r = 0$K1? %analytical solution uo = inline(6sin(pi5x)5exp(-pi5pi5t)6,6x6,6t6)0 [u/,x,t] = "eat exp(a,xf,I,it#,bx#,bxf,M,J)0 figure(l), elf, .es"(t,x,u/) [u1,x,t] = "eat i.p(a,xf,I,it#,bx#,bxf,M,J)0 %converge uncon*itionally figure(1), elf, .es"(t,x,u1) [u2,x,t] = "eat +J(a,xf,I,it0,bx0,bxf,M,J)0 %converge uncon*itionally figure(2), elf, .es"(t,x,u2) MJ = M5J0 Co = uo(x,t)0 aCo = abs(Co)!eps0 %values of true analytical solution %Lo) far fro. t"e analytical solutionM errl = nor.((u/-uo) $4aCo)4MJ err2 = nor.((u1-Co)$4aCo)4MJ err2 = nor.((u2-uo)$4aCo)4MJ