APPLIED NUMERICAL METHODS USING MATLAB phần 10 pot

52 444 0
APPLIED NUMERICAL METHODS USING MATLAB phần 10 pot

Đ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

456 PARTIAL DIFFERENTIAL EQUATIONS 9.8 PDEtool: GUI (Graphical User Interface) of MATLAB for Solving PDEs (a) Consider the PDE 4 ∂ 2 u(x, y) ∂x 2 − 4 ∂ 2 u(x,y) ∂x∂y + ∂ 2 u(x,y) ∂y 2 = 0for0≤ x ≤ 1, 0 ≤ y ≤ 1 (P9.8.1) with the boundary conditions u(0,y)= ye 2y ,u(1,y) = (1 + y)e 1+2y , u(x, 0) = xe x ,u(x,1) = (x + 1)e x+2 (P9.8.2) Noting that the field of coefficient c should be filled in as  Elliptic       c 4-2-21 4-21 in the PDE specification dialog box and the true analytical solution is u(x, y) = (x + y)e x+2y (P9.8.3) use the PDEtool to solve this PDE and fill in Table P9.8.1 with the maximum absolute error and the number of nodes together with those of Problem 9.2(d) for comparison. You can refer to Example 9.8 f or the procedure to get the numerical value of the maximum absolute error. Notice that the number of nodes is the number of columns of p, which is obtained by clicking ‘Export Mesh’ in the Mesh pull-down menu and then, clicking the OK button in the Export dialog box. You can also refer to Example 9.10 for the usage of ‘Adaptive Mesh’, but in this case you only have to check the box on the left of ‘Adaptive Mode’ and click the OK button in the ‘Solve Parameters’ dialog box opened by clicking ‘Parameters’ in the Solve pull-down menu, and then the mesh is adaptively refined every time you click the = button in the tool-bar to get the solution. With the box on the left of ‘Adaptive Mode’ unchecked in the ‘Solve Parameters’ dialog box, Table P9.8.1 The Maximum Absolute Error and the Number of Nodes The Maximum Absolute Error The Number of Nodes poisson() 1.9256 41 ×41 PDEtool with Initialize Mesh 0.1914 177 PDEtool with Refine Mesh PDEtool with second Refine Mesh PDEtool with Adaptive Mesh PDEtool with second Adaptive Mesh PROBLEMS 457 the mesh is nonadaptively refined every time you click ‘Refine Mesh’ in the Mesh pull-down menu. You can restore the previous mesh by clicking ‘Undo Mesh Change’ in the Mesh pull-down menu. (b) Consider the PDE ∂ 2 u(x, y) ∂x 2 + ∂ 2 u(x, y) ∂y 2 = 0for0≤ x ≤ 4, 0 ≤ y ≤ 4 (P9.8.4) with the Dirichlet/Neumann boundary conditions u(0,y)= e y − cos y, ∂u(x, y)/∂x| x=4 =−e y sin 4 − e 4 cos y (P9.8.5) ∂u(x, y)/∂y| y=0 =cos x, ∂u(x, y)/∂y| y=4 =e 4 cos x + e x sin 4 (P9.8.6) Noting that the true analytical solution is u(x,y) = e y cos x − e x cos y(P9.8.7) use the PDEtool to solve this PDE and fill in Table P9.8.2 with the maximum absolute error and the number of nodes together with those of Problem 9.3(g) for comparison. (c) Consider the PDE 2 ∂ 2 u(x, t) ∂x 2 = ∂u(x,t) ∂t for 0 ≤ x ≤ π, 0 ≤ t ≤ 0.2 (P9.8.8) with the initial/boundary conditions u(x, 0) = sin(2x), u(0,t)= 0,u(π,t)= 0 (P9.8.9) Noting that the true analytical solution is u(x, t) = sin(2x)e −8t (P9.8.10) Table P9.8.2 The Maximum Absolute Error and the Number of Nodes The Maximum Absolute Error The Number of Nodes poisson() 0.2005 21 ×21 PDEtool with Initialize Mesh 0.5702 177 PDEtool with Refine Mesh PDEtool with second Refine Mesh PDEtool with Adaptive Mesh PDEtool with second Adaptive Mesh 458 PARTIAL DIFFERENTIAL EQUATIONS Table P9.8.3 The Maximum Absolute Error and the Number of Nodes The Maximum Absolute Error The Number of Nodes poisson() 7.5462 × 10 −4 41 ×101 PDEtool with Initialize Mesh PDEtool with Refine Mesh PDEtool with second Refine Mesh use the PDEtool to solve this PDE and fill in Table P9.8.3 with the maximum absolute error and the number of nodes together with those obtained with the MATLAB routine ‘ heat_CN()’ in Problem 9.4(c) for comparison. In order to do this job, take the following steps. (1) Click the button in the tool-bar and click-and-drag on the graphic region to create a rectangular domain. Then, double- click the rectangle to open the Object dialog box and set the Left/Bottom/Width/Height to 0/0/pi/0.01 to make a long rectangular domain. (cf) Even if the PDEtool is originally designed to deal with only 2-D PDEs, we can use it to solve 1-D PDEs like (P9.8.8) by proceeding in this way. (2) Click the ∂ button in the tool-bar, double-click the upper/lower boundary segments to set the homogeneous Neumann boundary con- dition (g = 0, q = 0) and double-click the left/right boundary seg- ments to set the Dirichlet boundary condition (h = 1, r = 0) as given by Eq. (P9.8.9). (3) Open the PDE specification dialog box by clicking the PDE button, check the box on the left of ‘Parabolic’ as the type of PDE, and set its parameters in Eq. (9.5.5) as c = 2, a = 0, f = 0andd= 1, which corresponds to Eq. (P9.8.8). (4) Click ‘Parameters’ in the Solve pull-down menu to set the time range, say, as 0:0.002:0.2 and to set the initial conditions as Eq. ( P9.8.9). (5) In the Plot selection dialog box opened by clicking the but- ton, check the box before Height and click the Plot button. If you want to plot the solution graph at a time other than the final time, select the time for plot from {0, 0.002, 0.004, ,0.2} in the far- right field of the Plot selection dialog box and click the Plot but- ton again. (6) If you want to see a movie-like dynamic picture of the solution graph, check the box before Animation and then click the Plot button in the Plot selection dialog box. (7) Click ‘Export Mesh’ in the Mesh pull-down menu, and then click the OK button in the Export dialog box to extract the mesh data { p,e,t }. PROBLEMS 459 Also click ‘Export Solution’ in the Solve pull-down menu, and then click the OK button in the Export dialog box to extract the solution u. Now, you can estimate how far the graphical/numerical solution deviates from the true solution (P9.8.10) by typing the following statements into the MATLAB command window: >>x = p(1,:)’; y = p(2,: )’; %x,y coordinates of nodes in columns >>tt = 0:0.01:0.2; %time vector in row >>err = sin(2*x)*exp(-8*tt)-u; %deviation from true sol.(P9.8-10) >>err_max = max(abs(err)) %maximum absolute error (d) Consider the PDE ∂ 2 u(x, t) ∂x 2 = ∂ 2 u(x, t) ∂t 2 for 0 ≤ x ≤ 10, 0 ≤ t ≤ 10 (P9.8.11) with the initial/boundary conditions u(x, 0) =  (x − 2)(3 − x) for 2 ≤ x ≤ 3 0elsewhere , ∂u ∂t | t=0 = 0 (P9.8.12) u(0,t)= 0,u(10,t)= 0 (P9.8.13) Use the PDEtool to make a dynamic picture out of the solution for this PDE and see if the result is about the same as that obtained in Problem 9.6(c) in terms of the time when one of the two separated pulses propagating leftward is reflected and reversed and the time when the two separated pulses are reunited. (cf) Even if the PDEtool is originally designed to solve only 2-D PDEs, we can solve 1-D PDE like (P9.8.11) by proceeding as follows: (0) In the PDE toolbox window, adjust the ranges of the x axis and the y axis to [−0.5 10.5] and [−0.01 +0.01], respectively, in the box opened by clicking ‘Axes Limits’ in the Options pull-down menu. (1) Click the button in the tool-bar and click-and-drag on the graphic region to create a long rectangle of domain ranging from x 0 = 0to x f = 10. Then, double-click the rectangle to open the Object dialog box and set the Left/Bottom/Width/Height to 0/−0.01/10/0.02. (2) Click the ∂ button in the tool-bar, double-click the upper/lower boundary segments to set the homogeneous Neumann boundary con- dition (g = 0, q = 0) and double-click the left/right boundary seg- ments to set the Dirichlet boundary condition (h = 1, r = 0) as given by Eq. (P9.8.13). (3) Open the PDE specification dialog box by clicking the PDE button, check the box on the left of ‘Hyperbolic’ a s the type of PDE, and set its parameters in Eq. (P9.8.11) as c = 1, a = 0, f = 0andd= 1. (See Fig. 9.15a.) 460 PARTIAL DIFFERENTIAL EQUATIONS (4) Click ‘Parameters’ in the Solve pull-down menu to set the time range to, say, as 0:0.2:10, the boundary condition as (P9.8.13) and the ini- tial conditions as (P9.8.12). (See Fig. 9.15b and Problem 9.6(c)(ii).) (5) In the Plot selection dialog box opened by clicking the button, check the box before ‘Height’ and the box before ‘Animation’ and then click the Plot button in the Plot selection dialog box to see a movie-like dynamic picture of the solution graph. (6) If you want to have better resolution in the solution graph, click Mesh in the top menu bar and click ‘Refine Mesh’ in the Mesh pull-down menu. Then, select Plot in the top menu bar or type CTRL + P( ∧ P) on the keyboard and c lick ‘Plot Solution’ in the Plot pull-down menu to see a smoother animation graph. (7) In order to estimate the time when one of the two separated pulses propagating leftward is reflected and reversed and the time when the two separated pulses are reunited, count the fl ickering frame numbers, noting that one flickering corresponds to 0.2 s according to the time range set in step (4). (8) If you want to save the PDEtool program, click File in the top menu bar, click ‘Save As’ in the File pull-down menu, and input the file name of your choice. APPENDIX A MEAN VALUE THEOREM Theorem A.1. Mean Value Theorem 1 . Let a function f(x) be continuous on the interval [a, b] and differentiable over (a, b). Then, there exists at least one point ξ between a and b at which f  (ξ ) = f(b)− f(a) b − a ,f(b)= f(a)+ f  (ξ )(b −a) (A.1) In other words, the curve of a continuous function f(x) has the same slope as the straight line connecting the two end points (a,f (a))and(b, f (b))ofthe curve at some point ξ ∈ [a, b], as in Fig. A.1. f ( a ) f' (x) = f' (x) f ( b ) f ( b ) − f ( a ) b − a ab x Figure A.1 Mean value theorem. 1 See the website @http://www.maths.abdn.ac.uk/∼igc/testing/tch/ma2001/notes/notes.html Applied Numerical Methods Using MATLAB  , by Yang, Cao, Chung, and Morris Copyr ight  2005 John Wiley & Sons, I nc., ISBN 0-471-69833-4 461 462 MEAN VALUE THEOREM Theorem A.2. Taylor Series Theorem 1 . If a function f(x) is continuous and its derivatives up to order (K + 1) are also continuous on an open interval D containing some point a, then the value of the function f(x) at any point x ∈ D can be represented by f(x)= K  k=0 f k (a) k! (x − a) k + R K+1 (x) (A.2) where the first term of the right-hand side is called the Kth-degree Taylor poly- nomial, and the second term called the remainder (error) term is R K+1 (x) = f (K+1) (ξ ) (K +1)! (x − a) K+1 for some ξ between a and x(A.3) Moreover, if the f unction f(x) has continuous derivatives of all orders on D, then the above representation becomes f(x)= ∞  k=0 f k (a) k! (x − a) k (A.4) which is called the (infinite) Taylor series expansion of f(x) about a. APPENDIX B MATRIX OPERATIONS/PROPERTIES B.1 ADDITION AND SUBTRACTION A + B =     a 11 a 12 · a 1N a 21 a 22 · a 2N ···· a M1 a M2 · a MN     +     b 11 b 12 · b 1N b 21 b 22 · b 2N ···· b M1 b M2 · b MN     =     c 11 c 12 · c 1N c 21 c 22 · c 2N ···· c M1 c M2 · c MN     = C (B.1.1) with a mn + b mn = c mn (B.1.2) B.2 MULTIPLICATION AB =     a 11 a 12 · a 1K a 21 a 22 · a 2K ···· a M1 a M2 · a MK         b 11 b 12 · b 1N b 21 b 22 · b 2N ···· b K1 b K2 · b KN     =     c 11 c 12 · c 1N c 21 c 22 · c 2N ···· c M1 c M2 · c MN     = C (B.2.1) Applied Numerical Methods Using MATLAB  , by Yang, Cao, Chung, and Morris Copyr ight  2005 John Wiley & Sons, I nc., ISBN 0-471-69833-4 463 464 MATRIX OPERATIONS/PROPERTIES with c mn = K  k=1 a mk b kn (B.2.2) (cf) For this multiplication to be done, the number of columns of A must equal the number of rows of B. (cf) Note that the commutative law does not hold for the matrix multiplication, that is, AB = BA. B.3 DETERMINANT The determinant of a K × K (square) matrix A = [a mn ]isdefinedby det(A) =|A|= K  k=0 a kn (−1) k+n M kn or K  k=0 a mk (−1) m+k M mk (B.3.1) for any fixed 1 ≤ n ≤ K or 1 ≤ m ≤ K where the minor M kn is the determinant of the (K − 1) × (K − 1) (minor) matrix formed by removing the kth row and the nth column from A and A kn = (−1) k+n M kn is called the cofactor of a kn . In particular, the determinants of a 2 × 2matrixA 2×2 and a 3 × 3matrix A 3×3 are det(A 2×2 ) =     a 11 a 12 a 21 a 22     = 2  k=1 a kn (−1) k+n M kn = a 11 a 22 − a 12 a 21 (B.3.2) det(A 3×3 ) =       a 11 a 12 a 13 a 21 a 22 a 23 a 31 a 32 a 33       = a 11     a 22 a 23 a 32 a 33     − a 12     a 21 a 23 a 31 a 33     + a 13     a 21 a 22 a 31 a 32     = a 11 (a 22 a 33 − a 23 a 32 ) − a 12 (a 21 a 33 − a 23 a 31 ) + a 13 (a 21 a 32 − a 22 a 31 ) (B.3.3) Note the following properties. ž If the determinant of a matrix is zero, the matrix is singular. ž The determinant of a matrix equals the product of the eigenvalues of a matrix. ž If A is upper/lower triangular having only zeros below/above the diag- onal in each column, its determinant is the product of the diagonal ele- ments. ž det(A T ) = det(A);det(AB) = det(A)det(B);det(A −1 ) = 1/det(A) INVERSE MATRIX 465 B.4 EIGENVALUES AND EIGENVECTORS OF A MATRIX 2 The eigenvalue or characteristic value and its corresponding eigenvector or char- acteristic vector of an N × N matrix A aredefinedtobeascalarλ and a nonzero vector v satisfying Av = λv ⇔ (A − λI )v = 0 (v = 0)(B.4.1) where (λ, v) is called a n eigenpair and there are N eigenpairs for an N ×N matrix A. The eigenvalues of a matrix can be computed as the roots of the characteristic equation |A − λI |=0 (B.4.2) and the eigenvector corresponding to an eigenvalue λ i can be obtained by sub- stituting λ i into Eq. (B.4.1) and solve it for v. Note the following properties. ž If A is symmetric, all the eigenvalues are real-valued. ž If A is symmetric and positive definite, all the e igenvalues are real and positive. ž If v is an eigenvector of A,soiscv for any nonzero scalar c. B.5 INVERSE MATRIX The inverse matrix of a K ×K (square) matrix A = [a mn ] is denoted by A −1 and defined to be a matrix which is premultiplied/postmultiplied by A to form an identity matrix—that is, satisfies A × A −1 = A −1 × A = I(B.5.1) An element of the inverse matrix A −1 = [α mn ] can be computed as α mn = 1 det(A) A mn = 1 |A| (−1) m+n M mn (B.5.2) where M kn is the minor of a kn and A kn = (−1) k+n M kn is the cofactor of a kn . 2 See the website @http://www.sosmath.com/index.html or http://www.psc.edu/∼burkardt/papers/ linear glossary.html.) [...]... Af = 1 2 0 0 0 3 0 0 0 0 4 0 0 0 0 5 We can use the MATLAB routine sprandn(m,n,nzd) to generate an m × n sparse matrix having the given non-zero density nzd Let us see how efficient the operations can be on the matrices in sparse forms >>As = sprandn (10, 10,0.2); %a sparse matrix and >>Af = full(As); its full version Applied Numerical Methods Using MATLAB , by Yang, Cao, Chung, and Morris Copyright ... bar\continuous stem(x,y),loglog(x,y) \stairs\discrete\xy-log\x-log\y-log graph semilogx(x,y),semilogy(x,y) Applied Numerical Methods Using MATLAB , by Yang, Cao, Chung, and Morris Copyright  2005 John Wiley & Sons, Inc., ISBN 0-471-69833-4 491 492 Table I.1 MATLAB Commonly Used Commands and Functions in MATLAB plot(y) (y: read-valued) plot the values of vector\array over the index plot(y) (y: complex-valued)... |x| < 1 (F.7) ∞ nk x n = lim (−1)k n=0 ∞ n=0 a→0 nx n = n=0 ∂k ∂a k x x − e−a , x , (1 − x)2 |x| < 1 |x| < 1 (F.8) (F.9) 1 1 1 1 (−1)n = 1 − + − + ··· = π 2n + 1 3 5 7 4 (F .10) (continued overleaf ) Applied Numerical Methods Using MATLAB , by Yang, Cao, Chung, and Morris Copyright  2005 John Wiley & Sons, Inc., ISBN 0-471-69833-4 477 478 ∞ n=0 USEFUL FORMULAS 1 1 1 1 1 = 1 + 2 + 2 + 2 + · · · = π2 n2... x(t) (5) e−at us (t) (6) t m e−at us (t) (7) sin ωt us (t) (8) cos ωt us (t) X(s) 1 s +a m! (s + a)m+1 x(t) X(s) (9) e−at sin ωt us (t) ω (s + a)2 + ω2 (10) e−at cos ωt us (t) s+a (s + a)2 + ω2 ω s 2 + ω2 s s 2 + ω2 Applied Numerical Methods Using MATLAB , by Yang, Cao, Chung, and Morris Copyright  2005 John Wiley & Sons, Inc., ISBN 0-471-69833-4 473 474 LAPLACE TRANSFORM Table D.2 Properties of Laplace... −∞ (9) Complex convolution (10) Scaling (11) Duality (12) Parseval’s relation −∞ g(τ )x(t − τ ) dτ → G(ω)X(ω) x (t) → j ωX(ω) (7) Time integral (8) Complex derivative ∞ x(τ ) dτ → 1 X(ω) + π X(0)δ(ω) jω d X(ω) dω 1 X(ω) ∗ Y (ω) x(t)y(t) → 2π 1 X(ω/a) x(at) → |a| g(t) → f (ω) ⇔ f (t) → 2πg(ω) ∞ ∞ 1 |x(t)|2 dt → |x(ω)|2 dω 2π −∞ −∞ t x(t) → j Applied Numerical Methods Using MATLAB , by Yang, Cao, Chung,... ∂x =y = 2x (C.2) (C.3) Also with an M × N matrix A, we have ∂ T x Ay = ∂x ∂ T y Ax = ∂x where ∂ T T y A x = Ay ∂x ∂ T T x A y = AT y ∂x M (C.4a) (C.4b) N xT Ay = amn xm yn (C.5) m=1 n=1 Applied Numerical Methods Using MATLAB , by Yang, Cao, Chung, and Morris Copyright  2005 John Wiley & Sons, Inc., ISBN 0-471-69833-4 471 472 DIFFERENTIATION WITH RESPECT TO A VECTOR Especially for a square, symmetric... x^3 + 3*x^2*y + 3*x*y^2 + y^3 - x^2 - 2*x*y - y^2 >>collect(eq1,y) %collect similar terms in descending order with respect to y ans = y^3 + (3*x - 1)*y^2 + (3*x^2 - 2*x)*y + x^3 - x^2 Applied Numerical Methods Using MATLAB , by Yang, Cao, Chung, and Morris Copyright  2005 John Wiley & Sons, Inc., ISBN 0-471-69833-4 481 482 SYMBOLIC COMPUTATION >>factor(eq1) %factorize ans = (x + y - 1)*(x + y)^2 >>horner(eq1)... the number of floating-point operations APPENDIX I MATLAB First of all, the following should be noted: 1 The index of an array in MATLAB starts from 1, not 0 2 A dot(.) must be put before an operator to make a termwise (element-byelement) operation Some of useful MATLAB commands are listed in Table I.1 Table I.1 Commonly Used Commands and Functions in MATLAB break fprintf keyboard return load *** x y... at points specified by (i, j) Once you installed MATLAB, you can click the icon like the one in the left side to run MATLAB Then you will see the MATLAB command window on your monitor as depicted in Fig I.1, where a cursor appears (most likely blinking) to the right of the prompt like ‘>>’ or ‘?’ waiting for you to type in a command If you are running MATLAB of version 6.x, the main window has not only... full(regular) forms ans = 2000 >>b = ones (10, 1); flops(0), x = As\b; flops ans = 160 >>flops(0), x = Af\b; flops ans = 592 >>flops(0), inv(As); flops ans = 207 >>flops(0), inv(Af); flops ans = 592 >>flops(0), [L,U,P] = lu(As); flops ans = 53 >>flops(0), [L,U,P] = lu(Af); flops ans = 92 Additionally, the MATLAB routine speye(n) is used to generate an n × n identity matrix and the MATLAB routine spy(n) is used to . a) m+1 (10) e −at cos ωt u s (t) s + a (s + a) 2 + ω 2 (3) u s (t) 1 s (7) sin ωt u s (t) ω s 2 + ω 2 (4) t m u s (t) m! s m+1 (8) cos ωt u s (t) s s 2 + ω 2 Applied Numerical Methods Using MATLAB  ,. → 1 2π X(ω) ∗Y(ω) (10) Scaling x(at) → 1 |a| X(ω/a) (11) Duality g(t) → f(ω) ⇔ f(t)→ 2πg(ω) (12) Parseval’s relation  ∞ −∞ |x(t)| 2 dt → 1 2π  ∞ −∞ |x(ω)| 2 dω Applied Numerical Methods Using MATLAB  ,. = ∂ ∂x x T A T y = A T y (C.4b) where x T Ay = M  m=1 N  n=1 a mn x m y n (C.5) Applied Numerical Methods Using MATLAB  , by Yang, Cao, Chung, and Morris Copyr ight  2005 John Wiley & Sons,

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

Từ khóa liên quan

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

  • Đang cập nhật ...

Tài liệu liên quan