Replacing the first derivative on the left-side boundary x = x0 by its three-pointcentral difference approximation 5.1.8 If the boundary condition on the lower side boundary y = y0 is al
Trang 1x y
Figure 9.2 Temperature distribution over a plate— Example 9.1.
Replacing the first derivative on the left-side boundary (x = x0) by its three-pointcentral difference approximation (5.1.8)
If the boundary condition on the lower side boundary (y = y0) is also of
Neumann type, then we need to write similar equations for j = 1, 2, , M x− 1
u 0,j = r y (u 0,j+1 + u0,j−1 ) + 2r x u 1,j + r xy (g 0,j u 0,j − f0,j − 2b
y0(x j )/y) ( 9.1.10) and additionally for the left-lower corner point (x0, y0),
u 0,0 = 2(r y u 0,1 + r x u 1,0 ) + r xy (g 0,0 u 0,0 − f0,0 − 2(b
x0(y0)/x + 2b
y0(x0)/y))
(9.1.11)
Trang 2406 PARTIAL DIFFERENTIAL EQUATIONS
An example of a parabolic PDE is a one-dimensional heat equation describing
the temperature distribution u(x, t) (x is position, t is time) as
A ∂
2u(x, t)
∂x2 = ∂u(x, t)
∂t for 0≤ x ≤ x f , 0≤ t ≤ T ( 9.2.1)
In order for this equation to be solvable, the boundary conditions u(0, t)=
b0(t) & u(x f , t) = b xf (t) as well as the initial condition u(x, 0) = i0 (x) should
be provided
To apply the finite difference method, we divide the spatial domain [0, x f] into
M sections, each of length x = x f /M , and divide the time domain [0, T ] into
N segments, each of duration t = T /N, and then replace the second partial
derivative on the left-hand side and the first partial derivative on the right-handside of the above equation (9.2.1) by the central difference approximation (5.3.1)and the forward difference approximation (5.1.4), respectively, so that we have
e j iπ/P (P is any nonzero integer) ( 9.2.4)
into Eq (9.2.3) to get
Trang 3PARABOLIC PDE 407
function [u,x,t] = heat_exp(a,xf,T,it0,bx0,bxf,M,N)
%solve a u_xx = u_t for 0 <= x <= xf, 0 <= t <= T
% Initial Condition: u(x,0) = it0(x)
% Boundary Condition: u(0,t) = bx0(t), u(xf,t) = bxf(t)
% M = # of subintervals along x axis
% N = # of subintervals along t axis
dx = xf/M; x = [0:M]’*dx;
dt = T/N; t = [0:N]*dt;
for i = 1:M + 1, u(i,1) = it0(x(i)); end
for n = 1:N + 1, u([1 M + 1],n) = [bx0(t(n)); bxf(t(n))]; end
not to lose the stability
The MATLAB routine “heat_exp()” has been composed to implement thisalgorithm
In this section, we consider another algorithm called the implicit backward Eulermethod, which comes out from substituting the backward difference approxima-tion (5.1.6) for the first partial derivative on the right-hand side of Eq (9.2.1) as
Trang 4408 PARTIAL DIFFERENTIAL EQUATIONS
How about the case where the values of ∂u/∂x|x=0= b
0(t) at one end aregiven? In that case, we approximate this Neumann type of boundary condition by
function [u,x,t] = heat_imp(a,xf,T,it0,bx0,bxf,M,N)
%solve a u_xx = u_t for 0 <= x <= xf, 0 <= t <= T
% Initial Condition: u(x,0) = it0(x)
% Boundary Condition: u(0,t) = bx0(t), u(xf,t) = bxf(t)
% M = # of subintervals along x axis
% N = # of subintervals along t axis
dx = xf/M; x = [0:M]’*dx;
dt = T/N; t = [0:N]*dt;
for i = 1:M + 1, u(i,1) = it0(x(i)); end
for n = 1:N + 1, u([1 M + 1],n) = [bx0(t(n)); bxf(t(n))]; end
Trang 5PARABOLIC PDE 409
Here, let us go back to see Eq (9.2.7) and try to improve the implicit backwardEuler method The difference approximation on the left-hand side is taken at
time point k, while the difference approximation on the right-hand side is taken
at the midpoint between time k and k− 1, if we regard it as the central
differ-ence approximation with time step t/2 Doesn’t this seem to be inconsistent?
How about taking the difference approximation of both sides at the same time
point—say, the midpoint between k + 1 and k—for balance? In order to do so,
we take the average of the central difference approximations of the left-hand side
at the two points k + 1 and k, yielding
u k2+1
u k+1 3
· 0
Trang 6410 PARTIAL DIFFERENTIAL EQUATIONS
function [u,x,t] = heat_CN(a,xf,T,it0,bx0,bxf,M,N)
%solve a u_xx = u_t for 0 <= x <= xf, 0 <= t <= T
% Initial Condition: u(x,0) = it0(x)
% Boundary Condition: u(0,t) = bx0(t), u(xf,t) = bxf(t)
% M = # of subintervals along x axis
% N = # of subintervals along t axis
dx = xf/M; x = [0:M]’*dx;
dt = T/N; t = [0:N]*dt;
for i = 1:M + 1, u(i,1) = it0(x(i)); end
for n = 1:N + 1, u([1 M + 1],n) = [bx0(t(n)); bxf(t(n))]; end
b = [r*u(1,k); zeros(M - 3,1); r*u(M + 1,k)]
+ r*(u(1:M - 1,k - 1) + u(3:M + 1,k - 1)) + r2*u(2:M,k - 1); u(2:M,k) = trid(A,b); %Eq.(9.2.17)
end
Example 9.2 One-Dimensional Parabolic PDE: Heat Flow Equation.
Consider the parabolic PDE
∂2u(x, t)
∂x2 = ∂u(x, t)
∂t for 0≤ x ≤ 1, 0 ≤ t ≤ 0.1 ( E9.2.1)
with the initial condition and the boundary conditions
u(x, 0) = sin πx, u( 0, t) = 0, u( 1, t)= 0 ( E9.2.2)
We made the MATLAB program “solve_heat.m” in order to use the routines
“heat_exp()”, “heat_imp()”, and “heat_CN()” in solving this equation and ranthis program to obtain the results shown in Fig 9.3 Note that with the spatial
interval x = x f /M = 1/20 and the time step t = T /N = 0.1/100 = 0.001,
we have
r = A t
x2 = 1 0.001
( 1/20)2 = 0.4 ( E9.2.3) which satisfies the stability condition (r ≤ 1/2) (9.2.6) and all of the three meth-
ods lead to reasonably fair results with a relative error of about 0.013 But,
if we decrease the spatial interval to x = 1/25 for better resolution, we have
r = 0.625, violating the stability condition and the explicit forward Euler method
(“heat_exp()”) blows up because of instability as shown in Fig 9.3a, whilethe implicit backward Euler method (“heat_imp()”) and the Crank–Nicholsonmethod (“heat_CN()”) work quite well as shown in Figs 9.3b,c Now, with the
spatial interval x = 1/25 and the time step t = 0.1/120, the explicit method
as well as the other ones works well with a relative error less than 0.001 in return
Trang 7PARABOLIC PDE 411
1 0.5
0.5 x
0 0
0.05t0.1 1
(c) The Crank-Nicholson method
5
0
x
0.05t0.1 1
1 0.5
0.5 x
0 0
0.05t0.1 1
(a) The explicit method (b) The implicit method
0 0
Figure 9.3 Results of various algorithms for a one-dimensional parabolic PDE: heat equation.
for somewhat (30%) more computations, despite that r = 0.5208 doesn’t strictly
satisfy the stability condition
This implies that the condition (r ≤ 1/2) for stability of the explicit forward
Euler method is not a necessary one, but only a sufficient one Besides, if itconverges, its accuracy may be better than that of the implicit backward Eulermethod, but generally no better than that of the Crank–Nicholson method
%solve_heat
a = 1; %the parameter of (E9.2.1)
it0 = inline(’sin(pi*x)’,’x’); %initial condition
bx0 = inline(’0’); bxf = inline(’0’); %boundary condition
Uo = uo(x,t); aUo = abs(Uo)+eps; %values of true analytical solution
%How far from the analytical solution?
err1 = norm((u1-Uo)./aUo)/MN
err2 = norm((u2-Uo)./aUo)/MN
err3 = norm((u3-Uo)./aUo)/MN
Trang 8412 PARTIAL DIFFERENTIAL EQUATIONS
Another example of a parabolic PDE is a two-dimensional heat equation
describ-ing the temperature distribution u(x, y, t)((x, y) is position, t is time) as
u(x0, y, t) = b x (y, t), u(x f , y, t) = b xf (y, t),
u(x, y0, t) = b y (x, t), and u(x, y f , t) = b yf (x, t)
as well as the initial condition u(x, y, 0) = i0 (x, y)
We replace the first-order time derivative on the right-hand side by the
three-point central difference at the midthree-point (t k+1+ t k )/2 just as with the Crank–
Nicholson method We also replace one of the second-order derivatives, u xx and
u yy , by the three-point central difference approximation (5.3.1) at time t kand the
other at time t k+1, yielding
k
i,j+1− 2u k
i,j + u k i,j−1
t ( 9.2.20)
which seems to be attractive, since it can be formulated into a tridiagonal system
of equations with respect to u k i +1,j+1 , u k i,j+1, and u k i −1,j+1 But, why do we treat u xx and u yy with discrimination—that is, evaluate one at time t kand the other at time
t k+1in a fixed manner? In an alternate manner, we write the difference equation
for the next time point t k+1 as
This formulation, proposed by Peaceman and Rachford [P-1], is referred to as thealternating direction implicit (ADI) method and can be cast into the followingalgorithm:
Trang 9imple-function [u,x,y,t] = heat2_ADI(a,D,T,ixy0,bxyt,Mx,My,N)
%solve u_t = c(u_xx + u_yy) for D(1) <= x <= D(2), D(3) <= y <= D(4), 0 <= t <= T
% Initial Condition: u(x,y,0) = ixy0(x,y)
% Boundary Condition: u(x,y,t) = bxyt(x,y,t) for (x,y)cB
% Mx/My = # of subintervals along x/y axis
% N = # of subintervals along t axis
bx = [ry*u(i,1) zeros(1,Mx - 3) ry*u(i,My + 1)]
+rx*(u_1(i-1,jj)+ u_1(i + 1,jj)) + rx2*u_1(i,jj);
u(i,jj) = trid(Ay,bx’)’; %Eq.(9.2.22a)
end
else
for j = 2:Mx
ii = 2:My;
by = [rx*u(1,j); zeros(My-3,1); rx*u(Mx + 1,j)]
+ ry*(u_1(ii,j-1) + u_1(ii,j + 1)) + ry2*u_1(ii,j);
u(ii,j) = trid(Ax,by); %Eq.(9.2.22b)
end
end
end
Trang 10414 PARTIAL DIFFERENTIAL EQUATIONS
2 0
0 2
y 4
Example 9.3 A Parabolic PDE: Two-Dimensional Temperature Diffusion.
Consider a two-dimensional parabolic PDE
with the initial conditions and boundary conditions
u(x, y, t) = e y cos x − e x cos y for x = 0, x = 4, y = 0, y = 4 ( E9.3.2b)
We made the following MATLAB program “solve_heat2.m” in order to usethe routine “heat2_ADI()” to solve this equation and ran this program to get theresult shown in Fig 9.4 at the final time
%solve_heat2
clear, clf
a = 1e-4;
it0 = inline(’0’,’x’,’y’); %(E9.3.2a)
bxyt = inline(’exp(y)*cos(x)-exp(x)*cos(y)’,’x’,’y’,’t’); %(E9.3.2b)
D = [0 4 0 4]; T = 5000; Mx = 40; My = 40; N = 50;
[u,x,y,t] = heat2_ADI(a,D,T,it0,bxyt,Mx,My,N);
mesh(x,y,u)
An example of a hyperbolic PDE is a one-dimensional wave equation for the
amplitude function u(x, t)(x is position, t is time) as
A ∂
2u(x, t)
∂x2 = ∂2u(x, t)
∂t2 for 0≤ x ≤ x f , 0≤ t ≤ T ( 9.3.1)
Trang 11HYPERBOLIC PDE 415
In order for this equation to be solvable, the boundary conditions u(0, t)=
b0(t) and u(x f , t) = b xf (t) as well as the initial conditions u(x, 0) = i0 (x)and
∂u/∂t|t=0(x, 0) = i
0(x)should be provided
In the same way as with the parabolic PDEs, we replace the second derivatives
on both sides of Eq (9.3.1) by their three-point central difference approximation(5.3.1) as
i directly from this
We use Eq (9.3.6) together with the initial conditions to get u1i and then go
on with Eq (9.3.3) for k = 1, 2, Note the following facts:
ž We must have r≤ 1 to guarantee the stability
ž The accuracy of the solution gets better as r becomes larger so that x
decreases
It is therefore reasonable to select r= 1
The stability condition can be obtained by substituting Eq (9.2.4) into
Eq (9.3.3) and applying the Jury test [P-3]:
λ = 2r cos(π/P ) + 2(1 − r) − λ−1, λ2+ 2(r(1 − cos(π/P )) − 1)λ + 1 = 0
Trang 12416 PARTIAL DIFFERENTIAL EQUATIONS
We need the solution of this equation to be inside the unit circle for stability,which requires
Example 9.4 A Hyperbolic PDE: One-Dimensional Wave (Vibration) Consider
a one-dimensional hyperbolic PDE
∂2u(x, t)
∂x2 = ∂u2(x, t)
∂t2 for 0≤ x ≤ 2, 0 ≤ y ≤ 2, and 0 ≤ t ≤ 2 (E9.4.1)
with the initial conditions and boundary conditions
u(x, 0) = x(1 − x), ∂u/∂t(x, 0) = 0 for t = 0 (E9.4.2a)
u( 0, t) = 0 for x = 0, u(1, t) = 0 for x = 1 (E9.4.2b)
We made the following MATLAB program “solve_wave.m” in order to usethe routine “wave()” to solve this equation and ran this program to get the resultshown in Fig 9.5 and see a dynamic picture
function [u,x,t] = wave(a,xf,T,it0,i1t0,bx0,bxf,M,N)
%solve a u_xx = u_tt for 0<=x<=xf, 0<=t<=T
% Initial Condition: u(x,0) = it0(x), u_t(x,0) = i1t0(x)
% Boundary Condition: u(0,t)= bx0(t), u(xf,t) = bxf(t)
% M = # of subintervals along x axis
% N = # of subintervals along t axis
u(2:M,k) = r*u(1:M - 1,k - 1) + r2*u(2:M,k-1) + r*u(3:M + 1,k - 1)
- u(2:M,k - 2); %Eq.(9.3.3) end
%solve_wave
a = 1;
it0 = inline(’x.*(1-x)’,’x’); i1t0 = inline(’0’); %(E9.4.2a)
bx0t = inline(’0’); bxft = inline(’0’); %(E9.4.2b)
for n = 1:N %dynamic picture
plot(x,u(:,n)), axis([0 xf -0.3 0.3]), pause(0.2)
Trang 13Figure 9.5 A solution for a 1-D hyperbolic PDE obtained by using ‘‘wave()’’ (Example 9.4).
In this section, we consider a two-dimensional wave equation for the amplitude
function u(x, y, t) ((x, y) is position, t is time) as
u( 0, y, t) = b x (y, t), u(x f , y, t) = b xf (y, t),
u(x, 0, t) = b y (x, t), and u(x, y f , t) = b yf (x, t)
as well as the initial condition u(x, y, 0) = i0 (x, y) and ∂u/∂t|t=0(x, y, 0)=
i0(x, y)
In the same way as with the one-dimensional case, we replace the ond derivatives on both sides by their three-point central difference approxi-mation (5.3.1) as
k
i,j+1− 2u k
i,j + u k i,j−1
Trang 14418 PARTIAL DIFFERENTIAL EQUATIONS
Since u−1i,j = u(x j , y i , −t) is not given, we cannot get u1
i,j directly from this
0(x j , y i ) ( 9.3.12) and make use of this to remove u−1i,j from Eq (9.3.11) to have
We use this Eq (9.3.13) together with the initial conditions to get u1
i,j and then
go on using Eq (9.3.10) for k = 1, 2, A sufficient condition for stability [S-1,
algo-Example 9.5 A Hyperbolic PDE: Two-Dimensional Wave (Vibration) Over a
Square Membrane Consider a two-dimensional hyperbolic PDE
u( 0, y, t) = 0, u(2, y, t) = 0, u(x, 0, t) = 0, u(x, 2, t) = 0 (E9.5.2)
u(x, y, 0) = 0.1 sin(πx) sin(πy/2), ∂u/∂t(x, y, 0) = 0 for t = 0 (E9.5.3)
We made the following MATLAB program “solve_wave2.m” in order to usethe routine “wave2()” for solving this equation and ran this program to get theresult shown in Fig 9.6 and see a dynamic picture Note that we can be sure ofstability, since we have
x2+ y2 = 4(1/4)(2/20)2
( 2/20)2+ (2/20)2 = 1
Trang 15HYPERBOLIC PDE 419
function [u,x,y,t] = wave2(a,D,T,it0,i1t0,bxyt,Mx,My,N)
%solve a(u_xx + u_yy) = u_tt for D(1) <= x <= D(2), D(3) <= y <= D(4), 0 <= t <= T
% Initial Condition: u(x,y,0) = it0(x,y), u_t(x,y,0) = i1t0(x,y)
% Boundary Condition: u(x,y,t) = bxyt(x,y,t) for (x,y) on Boundary
% Mx/My = # of subintervals along x/y axis
% N = # of subintervals along t axis
adt2 = a*dt*dt; rx = adt2/(dx*dx); ry = adt2/(dy*dy);
rxy1 = 1- rx - ry; rxy2 = rxy1*2;
u_1 = u;
for k = 0:N
t = k*dt;
for i = 1:My + 1 %Boundary condition
u(i,[1 Mx + 1]) = [bxyt(x(1),y(i),t) bxyt(x(Mx + 1),y(i),t)];
u(i,j) = 0.5*(rx*(u_1(i,j - 1) + u_1(i,j + 1))
+ ry*(u_1(i - 1,j)+u_1(i + 1,j))) + rxy1*u(i,j) + dt*ut(i,j);
u(i,j) = rx*(u_1(i,j - 1)+ u_1(i,j + 1))
+ ry*(u_1(i - 1,j) + u_1(i + 1,j)) + rxy2*u(i,j) -u_2(i,j);
end
end
end
u_2 = u_1; u_1 = u; %update the buffer memory
mesh(x,y,u), axis([0 2 0 2 -.1 1]), pause
end
%solve_wave2
it0 = inline(’0.1*sin(pi*x)*sin(pi*y/2)’,’x’,’y’); %(E9.5.3)
i1t0 = inline(’0’,’x’,’y’); bxyt = inline(’0’,’x’,’y’,’t’); %(E9.5.2)
(a) At t = 0.1
−0.1 0.1
0 0
0
2 2
(b) At t = 1.8
Figure 9.6 The solution of a two-dimensional hyperbolic PDE: vibration of a square membrane (Example 9.5).
Trang 16420 PARTIAL DIFFERENTIAL EQUATIONS
The FEM method is another procedure used in finding approximate numericalsolutions to BVPs/PDEs It can handle irregular boundaries in the same way asregular boundaries [R-1, S-2, Z-1] It consists of the following steps to solve theelliptic PDE:
∂2u(x, y)
∂x2 +∂2u(x, y)
∂y2 + g(x, y)u(x, y) = f (x, y) ( 9.4.1) for the domain D enclosed by the boundary B on which the boundary condition
is given as
1 Discretize the (two-dimensional) domain D into, say, N s subregions
{S1 , S2, , S N s} such as triangular elements, neither necessarily of thesame size nor necessarily covering the entire domain completely andexactly
2 Specify the positions of N n nodes and number them starting from the
boundary nodes, say, n = 1, , N b , and then the interior nodes, say, n=
N b + 1, , N n
3 Define the basis/shape/interpolation functions
φ n (x, y) = {φ n,s , for s = 1, , N s } ∀ (x, y) ∈ D (9.4.3a)
φ n,s (x, y) = p n,s ( 1) + p n,s ( 2)x + p n,s ( 3)y
for each subregion S s (9.4.3b)
collectively for all subregions s = 1 : N s and for each node n = 1 : N n, so
that φ n is 1 only at node n, and 0 at all other nodes Then, the
approxi-mate solution of the PDE is a linear combination of basis functions
ϕ1= [ φ1 φ2 · φ N b]T , c1= [ c1 c2 · c N b]T (9.4.5a)
ϕ2= [ φ N b+1 φ N b+2 · φ N n]T , c2= [ c N b+1 c N b+2 · c N n]T
(9.4.5b)
Trang 17FINITE ELEMENT METHOD (FEM) FOR SOLVING PDE 421
For each subregion s = 1, , N s, this solution can be written as
(x s , y s ): the centroid (gravity center) of the sth subregion S s
The FEM is based on the variational principle that a solution to Eq (9.4.1)can be obtained by minimizing the functional
Trang 18422 PARTIAL DIFFERENTIAL EQUATIONS
which, with u(x, y)= cT ϕ(x, y), can be written as
See [R-1] for details
The objectives of the MATLAB routines “fem_basis_ftn()” and
“fem_coef()” are to construct the basis function φ n,s (x, y)’s for each node
n = 1, , N n and each subregion s = 1, , N s and to get the coefficient vector
c of the solution (9.4.4) via Eq (9.4.7) and the solution polynomial φ s (x, y)’s
via Eq (9.4.6) for each subregion s = 1, , N s, respectively
Before going into a specific example of applying the FEM method to solve
a PDE, let us take a look at the basis (shape) function φ n (x, y) for each node
n = 1, , N n, which is defined collectively for all of the (triangular) subregions
so that φ n is 1 only at node n, and 0 at all other nodes and can be generated by
the routine “fem_basis_ftn()”
function p = fem_basis_ftn(N,S)
%p(i,s,1:3): coefficients of each basis ftn phi_i
%N(n,1:2) : x & y coordinates of the n-th node
%S(s,1:3) : the node #s of the s-th subregion(triangle)
N_n = size(N,1); % the total number of nodes
N_s = size(S,1); % the total number of subregions(triangles)
Trang 19FINITE ELEMENT METHOD (FEM) FOR SOLVING PDE 423
function [U,c] = fem_coef(f,g,p,c,N,S,N_i)
%p(i,s,1:3): coefficients of basis ftn phi_i for the s-th subregion
%c = [ 1 1 0 0 ] with value for boundary and 0 for interior nodes
%N(n,1:2) : x & y coordinates of the n-th node
%S(s,1:3) : the node #s of the s-th subregion(triangle)
%N_i : the number of the interior nodes
%U(s,1:3) : the coefficients of p1 + p2(s)x + p3(s)y for each subregion N_n = size(N,1); % the total number of nodes = N_b + N_i
N_s = size(S,1); % the total number of subregions(triangles)
%phi_i,x*phi_n,x + phi_i,y*phi_n,y - g(x,y)*phi_i*phi_n
p_vctr = [p([i n],s,1) p([i n],s,2) p([i n],s,3)];
tmpg(s) = sum(p(i,s,2:3).*p(n,s,2:3))
-g(xy(1),xy(2))*p_vctr(1,:)*[1 xy]’*p_vctr(2,:)*[1 xy]’;
dS(s) = det([N(S(s,1),:) 1; N(S(s,2),:) 1;N(S(s,3),:) 1])/2;
%area of triangular subregion
if n == 1, tmpf(s) = -f(xy(1),xy(2))*p_vctr(1,:)*[1 xy]’; end
“trimesh()” to plot the shape functions for nodes n= 2, 3, 4, and 5 as depicted
in Figs 9.8b–e, each of which is 1 only at the corresponding node n and is
0 at all other nodes Figure 9.8f is the graph of a linear combination of basisfunctions
having the given value c n at each node n This can obtained by using the
MAT-LAB command “trimesh()” as
>>trimesh(S,N(:,1),N(:,2),c)
where the first input argument Shas the node numbers for each subregion, thesecond/third input argument N has the x/y coordinates for each node, and the
Trang 20424 PARTIAL DIFFERENTIAL EQUATIONS
1
0.2 0.5]
S = [1 2
2 3
3 4
4 5] 5; 5; 5;
Figure 9.7 A region (domain) divided into four triangular subregions.
fourth input argumentchas the function values at each node as follows:
The meaning of this N n ( the number of nodes:5) × N s (the number of
subre-gions:4) × 3 array p is that, say, the second rows of the three sub-arrays constitute
Trang 21FINITE ELEMENT METHOD (FEM) FOR SOLVING PDE 425
Figure 9.8 The basis (shape) functions for nodes in Fig 9.7 and a composite function.
the coefficient vectors of the basis function for node 2 as
−7/10 + (1/2)x + (6/5)y for subregion S1
−7/16 + (15/16)x + (1/2)y for subregion S2
Trang 22426 PARTIAL DIFFERENTIAL EQUATIONS
With the program “show_basis.m” in your computer, type the following mands into the MATLAB command window and see the graphical/textual output
N = [-1 1;1 1;1 -1;-1 -1;0.2 0.5]; %the list of nodes in Fig.9.7
N_n = size(N,1); % the number of nodes
S = [1 2 5;2 3 5;3 4 5;1 4 5]; %the list of subregions in Fig.9.7
N_s = size(S,1); % the number of subregions
Trang 23FINITE ELEMENT METHOD (FEM) FOR SOLVING PDE 427
Example 9.6 Laplace’s Equation: Electric Potential Over a Plate with Point
Charge Consider the following Laplace’s equation:
∇2u(x, y)= ∂2u(x, y)
∂x2 +∂2u(x, y)
∂y2 = f (x, y) (E9.6.1)for − 1 ≤ x ≤ +1, −1 ≤ y ≤ +1
23
8 9
1
28
26 16 27
Trang 24428 PARTIAL DIFFERENTIAL EQUATIONS
(−0.5, −0.5), since they are only two points at which the value of the right-hand side of Eq (9.6.1) is not zero, and consequently the value of the solution u(x, y)
is expected to change sensitively around them
We made the following MATLAB program “do_fem.m” in order to use theroutines “fem_basis_ftn()” and “fem_coef()” for solving this equation Forcomparison, we have added the statements to solve the same equation by using theroutine “poisson()” (Section 9.1) The results obtained by running this programare depicted in Fig 9.10a–c
−1 −1
x
(c) 16 ×15-point FDM (Finite Difference Method) solution
Figure 9.10 Results of Example 9.6.
Trang 25GUI OF MATLAB FOR SOLVING PDES: PDETOOL 429
N_n = size(N,1); %the total number of nodes
N_i = N_n - N_b; %the number of interior nodes
c = zeros(1,N_n); %boundary value or 0 for boundary/interior nodes
p = fem_basis_ftn(N,S);
[U,c] = fem_coef(f,g,p,c,N,S,N_i);
%Output through the triangular mesh-type graph
figure(1), clf, trimesh(S,N(:,1),N(:,2),c)
%Output through the rectangular mesh-type graph
N_s = size(S,1); %the total number of subregions(triangles)
by0 = inline(’0’); byf = inline(’0’);
[U,x,y] = poisson(f,g,bx0,bxf,by0,byf,[x0 xf y0 yf],Mx,My);
figure(3), clf, mesh(x,y,U)
In this section, we will see what problems can be solved by using the GUI (graphicuser interface) tool of MATLAB for PDEs and then apply the tool to solve theelliptic/parabolic/hyperbolic equations dealt with in Examples 9.1/9.3/9.5 and 9.6