APPLIED NUMERICAL METHODS USING MATLAB phần 9 docx

51 527 0
APPLIED NUMERICAL METHODS USING MATLAB phần 9 docx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

ELLIPTIC PDE 405 100 50 0 −50 −100 4 3 2 1 0 0 1 2 3 4 u(x, y) x y Figure 9.2 Temperature distribution over a plate—Example 9.1. Replacing the first derivative on the left-side boundary (x = x 0 ) by its three-point central difference approximation (5.1.8) u i,1 − u i,−1 2x ≈ b  x 0 (y i ), u i,−1 ≈ u i,1 − 2b  x 0 (y i )x for i = 1, 2, ,M y − 1 (9.1.8) and then substituting this c onstraint into Eq. (9.1.5a) at the boundary points, we have u i,0 = r y (u i,1 + u i,−1 ) + r x (u i+1,0 + u i−1,0 ) + r xy (g i,0 u i,0 − f i,0 ) = r y (u i,1 + u i,1 − 2b  x 0 (y i )x) + r x (u i+1,0 + u i−1,0 ) + r xy (g i,0 u i,0 − f i,0 ) = 2r y u i,1 + r x (u i+1,0 + u i−1,0 ) + r xy (g i,0 u i,0 − f i,0 − 2b  x 0 (y i )/x) for i = 1, 2, ,M y − 1 (9.1.9) If the boundary condition on the lower side boundary (y = y 0 )isalsoof 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 + u 0,j −1 ) + 2r x u 1,j + r xy (g 0,j u 0,j − f 0,j − 2b  y 0 (x j )/y) (9.1.10) and additionally for the left-lower corner point (x 0 ,y 0 ), u 0,0 = 2(r y u 0,1 + r x u 1,0 ) + r xy (g 0,0 u 0,0 − f 0,0 − 2(b  x 0 (y 0 )/x + 2b  y 0 (x 0 )/y)) (9.1.11) 406 PARTIAL DIFFERENTIAL EQUATIONS 9.2 PARABOLIC PDE 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 ∂ 2 u(x, t) ∂x 2 = ∂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)= b 0 (t) & u(x f ,t)= b xf (t) as well as the initial condition u(x, 0) = i 0 (x) should be provided. 9.2.1 The Explicit Forward Euler Method 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-hand side 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 A u k i+1 − 2u k i + u k i−1 x 2 = u k+1 i − u k i t (9.2.2) This can be cast into the following algorithm, called the explicit forward Euler method, which is to be solved iteratively: u k+1 i = r(u k i+1 + u k i−1 ) + (1 − 2r)u k i with r = A t x 2 (9.2.3) for i = 1, 2, ,M− 1 To find the stability condition of this algorithm, we substitute a trial solution u k i = λ k e jiπ/P (P is any nonzero integer)(9.2.4) into Eq. (9.2.3) to get λ = r(e jπ/P + e −jπ/P ) + (1 − 2r) = 1 − 2r(1 − cos(π/P )) (9.2.5) Sincewemusthave|λ|≤1 for nondivergence, the stability condition turns out to be r = A t x 2 ≤ 1 2 (9.2.6) PARABOLIC 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=#ofsubintervals along x axis %N=#ofsubintervals 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 r = a*dt/dx/dx, r1 = 1 - 2*r; for k = 1:N for i = 2:M u(i,k+1) = r*(u(i + 1,k) + u(i-1,k)) + r1*u(i,k); %Eq.(9.2.3) end end This implies that as we decrease the spatial interval x for better accuracy, we must also decrease the time step t at the c ost of more computations in order not to lose the stability. The MATLAB routine “ heat_exp()” has been composed to implement this algorithm. 9.2.2 The Implicit Backward Euler Method In this section, we consider another algorithm called the implicit backward Euler method, 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 A u k i+1 − 2u k i + u k i−1 x 2 = u k i − u k−1 i t (9.2.7) −ru k i−1 + (1 + 2r)u k i − ru k i+1 = u k−1 i with r = A t x 2 (9.2.8) for i = 1, 2, ,M −1 If the values of u k 0 and u k M at both end points are given from the Dirichlet type of boundary condition, then the above equation will be cast into a system of simultaneous equations:        1 + 2r −r 0 · 00 −r 1 + 2r −r · 00 0 −r 1 + 2r · 00 · · ··· · 000· 1 + 2r −r 000·−r 1 + 2r                u k 1 u k 2 u k 3 · u k M−2 u k M−1         =          u k−1 1 + ru k 0 u k−1 2 u k−1 3 · u k−1 M−2 u k−1 M−1 + ru k M          (9.2.9) 408 PARTIAL DIFFERENTIAL EQUATIONS How about the case where the values of ∂u/∂x| x=0 = b  0 (t) at one end are given? In that case, we approximate this Neumann type of boundary condition by u k 1 − u k −1 2x = b  0 (k) (9.2.10) and mix it up with one more equation associated with the unknown variable u k 0 −ru k −1 + (1 + 2r)u k 0 − ru k 1 = u k−1 0 (9.2.11) to get (1 + 2r)u k 0 − 2ru k 1 = u k−1 0 − 2rb  0 (k)x (9.2.12) We augment Eq. (9.2.9) with this to write             1 +2r −2r 00· 00 −r 1 +2r −r 0 · 00 0 −r 1 +2r −r · 00 00−r 1 + 2r · 00 ······· 000 ··1 +2r −r 000 ··−r 1 +2r                         u k 0 u k 1 u k 2 u k 3 · u k M−2 u k M−1             =              u k−1 0 − 2rb  0 (k)x u k−1 1 u k−1 2 u k−1 3 · u k−1 M−2 u k−1 M−1 + ru k M              ( 9.2.13) Equations such as Eq. (9.2.9) or (9.2.13) are really nice in the sense that they can be solved very efficiently by exploiting their tridiagonal structures and are guaranteed to be stable owing to their diagonal dominancy. The unconditional stability of Eq. (9.2.9) can be shown by substituting Eq. (9.2.4) into Eq. (9.2.8): −re −jπ/P + (1 + 2r) − re jπ/P = 1/λ, λ = 1 1 + 2r(1 − cos(π/P )) , |λ|≤1 (9.2.14) The f ollowing routine “ heat_imp()” implements this algorithm to solve the PDE (9.2.1) with the ordinary (Dirichlet type of) boundary condition via Eq. (9.2.9). 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=#ofsubintervals along x axis %N=#ofsubintervals 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 r = a*dt/dx/dx; r2 = 1 + 2*r; fori=1:M-1 A(i,i) = r2; %Eq.(9.2.9) ifi>1,A(i-1,i) = -r; A(i,i - 1) = -r; end end fork=2:N+1 b = [r*u(1,k); zeros(M - 3,1); r*u(M + 1,k)] + u(2:M,k - 1); %Eq.(9.2.9) u(2:M,k) = trid(A,b); end PARABOLIC PDE 409 9.2.3 The Crank–Nicholson Method Here, let us go back to see Eq. (9.2.7) and try to improve the implicit backward Euler 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 + 1andk —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 + 1andk, yielding A 2  u k+1 i+1 − 2u k+1 i + u k+1 i−1 x 2 + u k i+1 − 2u k i + u k i−1 x 2  = u k+1 i − u k i t (9.2.15) which leads to the so-called C rank–Nicholson method: −ru k+1 i+1 + 2(1 + r)u k+1 i − ru k+1 i−1 = ru k i+1 + 2(1 − r)u k i + ru k i−1 (9.2.16) with r = A t x 2 With the Dirichlet/Neumann type of boundary condition on x 0 /x M , respec- tively, this can be cast into the following tridiagonal system of equations.            2(1 + r) −r 0 · 00 −r 2(1 + r) −r · 00 0 −r 2(1 + r) · 00 · · ··· · 000· 2(1 + r) −r 000·−2r 2(1 + r)                        u k+1 1 u k+1 2 u k+1 3 · u k+1 M−1 u k+1 M             =            2(1 − r) r 0 · 00 r 2(1 − r) r · 00 0 r 2(1 − r) · 00 · · ··· · 000· 2(1 −r) r 000· 2r 2(1 − r)                       u k 1 u k 2 u k 3 · u k M−1 u k M            +            r(u k+1 0 + u k 0 ) 0 0 · 0 2r(b  M (k +1) +b  M (k))            ( 9.2.17) This system of equations can also be solved very efficiently, and its uncondi- tional stability can be shown by substituting Eq. (9.2.4) into Eq. (9.2.16): 2λ(1 + r(1 − cos(π/P ))) = 2(1 − r(1 − cos(π/P ))), λ = 1 − r(1 − cos(π/P )) 1 + r(1 − cos(π/P )) , |λ|≤1 (9.2.18) This algorithm is cast into the following MATLAB routine “ heat_CN()”. 410 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=#ofsubintervals along x axis %N=#ofsubintervals 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 r = a*dt/dx/dx; r1 = 2*(1 - r); r2 = 2*(1 + r); fori=1:M-1 A(i,i) = r1; %Eq.(9.2.17) ifi>1,A(i-1,i) = -r; A(i,i - 1) = -r; end end fork=2:N+1 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 ∂ 2 u(x, t) ∂x 2 = ∂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 ran this 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 x 2 = 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, while the implicit backward Euler method (“ heat_imp()”) and the Crank–Nicholson method (“ 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 PARABOLIC PDE 411 1 0.5 0.5 x 0 0 0.05 t 0.1 1 0 (c) The Crank-Nicholson method 5 0 x 0.05 t 0.1 1 −5 0 1 0.5 0.5 x 0 0 0.05 t 0.1 1 (a) The explicit method (b) The implicit method 00 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. B esides, if it converges, its accuracy may be better than that of the implicit backward Euler method, 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 xf = 1; M = 25; T = 0.1; N = 100; %r = 0.625 %analytical solution uo = inline(’sin(pi*x)*exp(-pi*pi*t)’,’x’,’t’); [u1,x,t] = heat_exp(a,xf,T,it0,bx0,bxf,M,N); figure(1), clf, mesh(t,x,u1) [u2,x,t] = heat_imp(a,xf,T,it0,bx0,bxf,M,N); %converge unconditionally figure(2), clf, mesh(t,x,u2) [u3,x,t] = heat_CN(a,xf,T,it0,bx0,bxf,M,N); %converge unconditionally figure(3), clf, mesh(t,x,u3) MN = M*N; 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 412 PARTIAL DIFFERENTIAL EQUATIONS 9.2.4 Two-Dimensional Parabolic PDE 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 A  ∂ 2 u(x, y, t) ∂x 2 + ∂ 2 u(x, y, t) ∂y 2  = ∂u(x,y,t) ∂t (9.2.19) for x 0 ≤ x ≤ x f ,y 0 ≤ y ≤ y f , 0 ≤ t ≤ T In order for this equation to be solvable, we should be provided w ith the boundary conditions u(x 0 ,y,t)= b x0 (y, t), u(x f ,y,t) = b xf (y, t), u(x, y 0 ,t) = b y0 (x, t), and u(x, y f ,t) = b yf (x, t) as well as the initial condition u(x,y, 0) = i 0 (x, y). We replace the first-order time derivative on the right-hand side by the three- point central difference at the midpoint (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 k and the other at time t k+1 , yielding A  u k i,j+1 − 2u k i,j + u k i,j−1 x 2 + u k+1 i+1,j − 2u k+1 i,j + u k+1 i−1,j y 2  = u k+1 i,j − u k i,j 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+1 i+1,j , u k+1 i,j ,andu k+1 i−1,j . But, why do we treat u xx and u yy with discrimination—that is, evaluate one at time t k and the other at time t k+1 in a fixed manner? In an alternate manner, we write the difference equation for the next time point t k+1 as A  u k+1 i,j+1 − 2u k+1 i,j + u k+1 i,j−1 x 2 + u k i+1,j − 2u k i,j + u k i−1,j y 2  = u k+2 i,j − u k+1 i,j t (9.2.21) This formulation, proposed by Peaceman and Rachford [P-1], is referred to as the alternating direction implicit (ADI) method and can be cast into the following algorithm: −r y (u k+1 i−1,j + u k+1 i+1,j ) + (1 + 2r y )u k+1 i,j = r x (u k i,j−1 + u k i,j+1 ) + (1 −2r x )u k i,j for 1 ≤ j ≤ M x − 1 (9.2.22a) −r x (u k+2 i,j−1 + u k+2 i,j+1 ) + (1 + 2r x )u k+2 i,j = r y (u k+1 i−1,j + u k+1 i+1,j ) + (1 − 2r y )u k+1 i,j for 1 ≤ i ≤ M y − 1 (9.2.22b) PARABOLIC PDE 413 with r x = At/x 2 ,r y = At/y 2 , x = (x f − x 0 )/M x ,y= (y f − y 0 )/M y ,t= T/N The objective of the following MATLAB routine “ heat2_ADI()”istoimple- ment this algorithm for solving a two-dimensional heat equation (9.2.19). 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=#ofsubintervals along x/y axis %N=#ofsubintervals along t axis dx = (D(2) - D(1))/Mx; x = D(1)+[0:Mx]*dx; dy = (D(4) - D(3))/My; y = D(3)+[0:My]’*dy; dt = T/N; t = [0:N]*dt; %Initialization forj=1:Mx+1 fori=1:My+1 u(i,j) = ixy0(x(j),y(i)); end end rx = a*dt/(dx*dx); rx1 = 1 + 2*rx; rx2=1-2*rx; ry = a*dt/(dy*dy); ry1 = 1 + 2*ry; ry2=1-2*ry; for j = 1:Mx - 1 %Eq.(9.2.22a) Ay(j,j) = ry1; ifj>1,Ay(j - 1,j) = -ry; Ay(j,j-1) = -ry; end end for i = 1:My - 1 %Eq.(9.2.22b) Ax(i,i) = rx1; ifi>1,Ax(i - 1,i) = -rx; Ax(i,i - 1) = -rx; end end for k = 1:N u_1 = u; t = k*dt; for i = 1:My + 1 %Boundary condition u(i,1) = feval(bxyt,x(1),y(i),t); u(i,Mx+1) = feval(bxyt,x(Mx+1),y(i),t); end forj=1:Mx+1 u(1,j) = feval(bxyt,x(j),y(1),t); u(My+1,j) = feval(bxyt,x(j),y(My + 1),t); end if mod(k,2) == 0 for i = 2:My jj = 2:Mx; 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 414 PARTIAL DIFFERENTIAL EQUATIONS 2 0 0 2 y 4 1 3 4 x 100 0 −100 Figure 9.4 A solution for a two dimensional parabolic PDE obtained using ‘‘heat2 ADI()’’ (Example 9.3). Example 9.3. A Parabolic PDE: Two-Dimensional Temperature Diffusion. Consider a two-dimensional parabolic PDE 10 −4  ∂ 2 u(x, y, t) ∂x 2 + ∂ 2 u(x, y, t) ∂y 2  = ∂u(x,y,t) ∂t (E9.3.1) for 0 ≤ x ≤ 4, 0 ≤ y ≤ 4, 0 ≤ t ≤ 5000 with the initial conditions and boundary conditions u(x, y, 0) = 0fort = 0 (E9.3.2a) 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”inordertouse the routine “ heat2_ADI()” to solve this equation and ran this program to get the result 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) 9.3 HYPERBOLIC PDE 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 ∂ 2 u(x, t) ∂x 2 = ∂ 2 u(x, t) ∂t 2 for 0 ≤ x ≤ x f , 0 ≤ t ≤ T(9.3.1) [...]... 7/16; -9/ 16 -17/32;-7/16 -17/32; -1/2 -7/16 ;9/ 16 17/32;7/16 17/32;1/2 7/16]; %nodes N_b = 12; %the number of boundary nodes S = [1 11 12;1 11 19; 10 11 19; 4 5 19; 5 7 19; 5 6 7;1 2 15; 2 3 15; 3 15 17;3 4 17;4 17 19; 13 17 19; 1 13 19; 1 13 15;7 8 22;8 9 22; 9 22 24 ;9 10 24; 10 19 24; 19 20 24;7 19 20; 7 20 22;13 14 18; 14 15 16;16 17 18;20 21 25;21 22 23;23 24 25;14 26 28; 16 26 27;18 27 28; 21 29 31;23 29. .. equation by using the FEM, we locate 12 boundary points and 19 interior points, number them, and divide the domain into 36 triangular subregions as depicted in Fig 9. 9 Note that we have made the size of the subregions small and their density high around the points (+0.5, +0.5) and 1 y 12 10 11 8 9 S16 S18 0.8 S17 23 S3 S1 24 0.6 30 33 29 36 34 32 25 21 31 S 19 S2 0.4 S15 S22 S20 0.2 22 20 S21 0 1 19 S13 13... = tmpg*abs(dS)’; %Eqs (9. 4.8), (9. 4 .9) end d(i-N_b) = tmpf*abs(dS)’; %Eq. (9. 4.10) end d = d - A12(1:N_i,1:N_b)*c(1:N_b)’; %Eq. (9. 4.10) c(N_b + 1:N_n) = A12(1:N_i,N_b+1:N_n)\d; %Eq. (9. 4.7) for s = 1:N_s for j = 1:3, U(s,j) = c*p(:,s,j); end %Eq. (9. 4.6) end Actually, we will plot the basis (shape) functions for the region divided into four triangular subregions as depicted in Fig 9. 7 in two ways First,... (a) 31-point FEM solution drawn by using trimesh () x10−3 5 u (x, y ) 0 −5 1 y 0.5 0 −0.5 −1 −1 −0.5 0 x 1 0.5 x 1 0.5 (b) 31-point FEM solution by using mesh () x10−3 5 u (x, y ) 0 −5 1 y 0.5 0 −0.5 −1 −1 −0.5 0 (c) 16 ×15-point FDM (Finite Difference Method) solution Figure 9. 10 Results of Example 9. 6 GUI OF MATLAB FOR SOLVING PDES: PDETOOL 4 29 %do_fem % for Example 9. 6 clear N = [-1 0;-1 -1;-1/2 -1;0... functions by using the routine “fem_basis_ftn()” and plot one of them for node 1 by using the MATLAB command mesh(), as depicted in Fig 9. 8a Second, without generating the basis functions, we use the MATLAB command “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... elliptic/parabolic/hyperbolic equations dealt with in Examples 9. 1 /9. 3 /9. 5 and 9. 6 430 PARTIAL DIFFERENTIAL EQUATIONS 9. 5.1 Basic PDEs Solvable by PDETOOL Basically, the PDE toolbox can be used for the following kinds of PDE 1 Elliptic PDE −∇ · (c∇u) + au = f over a domain (9. 5.1) with some boundary conditions like hu = r (Dirichlet condition) (9. 5.2) or n · c∇u + qu = g (generalized Neumann condition)... (9. 3.13) together with the initial conditions to get u1 and then i,j go on using Eq (9. 3.10) for k = 1, 2, A sufficient condition for stability [S-1, Section 9. 6] is 4A t 2 ≤1 (9. 3.14) r= x2 + y2 The objective of the MATLAB routine “wave2()” is to implement this algorithm for solving a two-dimensional wave equation Example 9. 5 A Hyperbolic PDE: Two-Dimensional Wave (Vibration) Over a Square Membrane... function on a rectangular domain as depicted in Fig 9. 1, Eq (9. 5.1) becomes −c ∂ 2 u(x, y) ∂ 2 u(x, y) + ∂x 2 ∂y 2 + au(x, y) = f (x, y) (9. 5.3) and if the boundary condition for the left-side boundary segment is of Neumann type like Eq (9. 1.7), Eq (9. 5.2) can be written as −i·c = −c ∂u(x, y) ∂u(x, y) i+ j + qu(x, y) ∂x ∂y ∂u(x, y) + qu(x, y) = g(x, y) ∂x (9. 5.4) since the outward unit normal vector to... domain (9. 5.5) with boundary conditions like Eq (9. 5.2) and, additionally, the initial condition u(t0 ) 3 Hyperbolic PDE ∂ 2u =f ∂t 2 and for a time range 0 ≤ t ≤ T −∇ · (c∇u) + au + d over a domain (9. 5.6) 431 GUI OF MATLAB FOR SOLVING PDES: PDETOOL with boundary conditions like Eq (9. 5.2) and, additionally, the initial conditions u(t0 )/u (t0 ) 4 Eigenmode PDE −∇ · (c∇u) + au = λdu over a domain (9. 5.7)... tool-bar or ‘PDE Specification’ in the PDE pull-down menu (Fig 9. 12d), check the type of PDE, and set its parameters in Eq (9. 5.1)/ (9. 5.5)/ (9. 5.6)/ (9. 5.7) 4 In Mesh mode, you can create the triangular mesh for the domain drawn in Draw mode by just clicking the button in the tool-bar or ‘Initialize Mesh(∧ I)’ in the Mesh pull-down menu (Fig 9. 12e) To improve the accuracy of the solution, you can refine . %Eq. (9. 2 .9) ifi>1,A(i-1,i) = -r; A(i,i - 1) = -r; end end fork=2:N+1 b = [r*u(1,k); zeros(M - 3,1); r*u(M + 1,k)] + u(2:M,k - 1); %Eq. (9. 2 .9) u(2:M,k) = trid(A,b); end PARABOLIC PDE 4 09 9.2.3. tmpg*abs(dS)’; %Eqs. (9. 4.8), (9. 4 .9) end d(i-N_b) = tmpf*abs(dS)’; %Eq. (9. 4.10) end d=d-A12(1:N_i,1:N_b)*c(1:N_b)’; %Eq. (9. 4.10) c(N_b + 1:N_n) = A12(1:N_i,N_b+1:N_n)d; %Eq. (9. 4.7) for s = 1:N_s for. u 1 i,j and then go on using Eq. (9. 3.10) for k = 1, 2, A sufficient condition for stability [S-1, Section 9. 6] is r = 4At 2 x 2 + y 2 ≤ 1 (9. 3.14) The objective of the MATLAB routine “wave2()”

Ngày đăng: 09/08/2014, 12:22

Tài liệu cùng người dùng

Tài liệu liên quan