1. Trang chủ
  2. » Công Nghệ Thông Tin

APPLIED NUMERICAL METHODS USING MATLAB phần 10 pot

52 445 0

Đ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

Thông tin cơ bản

Định dạng
Số trang 52
Dung lượng 477,42 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

456 PARTIAL DIFFERENTIAL EQUATIONS9.8 PDEtool: GUI Graphical User Interface of MATLAB for Solving PDEs a Consider the PDE ux, 0 = xex, ux, 1 = x + 1ex+2 P9.8.2 Noting that the field of

Trang 1

456 PARTIAL DIFFERENTIAL EQUATIONS

9.8 PDEtool: GUI (Graphical User Interface) of MATLAB for Solving PDEs (a) Consider the PDE

u(x, 0) = xex, u(x, 1) = (x + 1)ex+2 ( P9.8.2)

Noting that the field of coefficient c should be filled in as

Elliptic  c 4 -2 -2 1 4 -2 1

in the PDE specification dialog box and the true analytical solution is

u(x, y) = (x + y)ex +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 for 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 MaximumAbsolute Error

The Number

of Nodes

PDEtool with Refine Mesh

PDEtool with second Refine Mesh

PDEtool with Adaptive Mesh

PDEtool with second Adaptive Mesh

Trang 2

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

2u(x, y)

∂x2 + 2u(x, y)

∂y2 = 0 for 0 ≤ x ≤ 4, 0 ≤ y ≤ 4 (P9.8.4)

with the Dirichlet/Neumann boundary conditions

u( 0, y) = ey− cos y, ∂u(x, y)/∂x|x=4= −eysin 4 − e4cos y (P9.8.5)

∂u(x, y)/∂y |y=0=cos x, ∂u(x, y)/∂y|y=4=e4cos x + exsin 4 (P9.8.6) Noting that the true analytical solution is

u(x, y) = eycos x − excos 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

2u(x, t)

∂x2 = ∂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 MaximumAbsolute Error

The Number

of Nodes

PDEtool with Refine Mesh

PDEtool with second Refine Mesh

PDEtool with Adaptive Mesh

PDEtool with second Adaptive Mesh

Trang 3

458 PARTIAL DIFFERENTIAL EQUATIONS

Table P9.8.3 The Maximum Absolute Error and the Number of Nodes

The MaximumAbsolute Error

The Number

of Nodes

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 dition (g = 0, q = 0) and double-click the left/right boundary seg-

con-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 = 0 and d = 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 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 ton again.

but-(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}.

Trang 4

>>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

(cf) Even if the PDEtool is originally designed to solve only 2-D PDEs, we cansolve 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 x0= 0 to

xf = 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 dition (g = 0, q = 0) and double-click the left/right boundary seg-

con-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’ as the type of PDE, and set its parameters in Eq (P9.8.11) as c = 1, a = 0, f = 0 and d = 1.

(See Fig 9.15a.)

Trang 5

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 tial conditions as (P9.8.12) (See Fig 9.15b and Problem 9.6(c)(ii).)

ini-(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 click ‘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 flickering 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.

Trang 6

APPENDIX A

MEAN VALUE THEOREM

Theorem A.1 Mean Value Theorem1 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)) of the curve at some point ξ ∈ [a, b], as in Fig A.1.

Figure A.1 Mean value theorem

1See 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

Trang 7

462 MEAN VALUE THEOREM

Theorem A.2 Taylor Series Theorem1 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

nomial, and the second term called the remainder (error) term is

Trang 8

APPENDIX B

MATRIX OPERATIONS/PROPERTIES

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

Trang 9

where the minor Mkn is the determinant of the (K − 1) × (K − 1) (minor) matrix formed by removing the kth row and the nth column from A and Akn =

( −1)k +nM

kn is called the cofactor of akn.

In particular, the determinants of a 2 × 2 matrix A2×2 and a 3 × 3 matrix

ž 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 diagdiag-onal ments.

ele-ž det(AT) = det(A); det(AB) = det(A)det(B); det(A−1) = 1/det(A)

Trang 10

INVERSE MATRIX 465

The eigenvalue or characteristic value and its corresponding eigenvector or acteristic vector of an N × N matrix A are defined to be a scalar λ and a nonzero

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 eigenvalues are real and

kn is the cofactor

of akn.

2See the website @http://www.sosmath.com/index.html or http://www.psc.edu/∼burkardt/papers/linear glossary.html.)

Trang 11

466 MATRIX OPERATIONS/PROPERTIES

Note that a square matrix A is invertible/nonsingular if and only if

ž No eigenvalue of A is zero, or equivalently,

ž The rows (and the columns) of A are linearly independent, or equivalently,

ž The determinant of A is nonzero.

A square matrix A is said to be symmetric if it is equal to its transpose, that is,

A complex-valued matrix is said to be Hermitian if it is equal to its complex

conjugate transpose, that is,

Note the following properties of a symmetric/Hermitian matrix.

ž All the eigenvalues are real.

ž If all the eigenvalues are distinct, the eigenvectors can form an

orthogo-nal/unitary matrix U

A nonsingular (square) matrix A is said to be orthogonal if its transpose is equal

to its inverse, that is,

A complex-valued (square) matrix is said to be unitary if its conjugate transpose

is equal to its inverse, that is,

Note the following properties of an orthogonal/unitary matrix.

ž The magnitude (absolute value) of every eigenvalue is one.

ž The product of two orthogonal matrices is also orthogonal; (AB)∗T(AB) =

B∗T(A∗TA)B ≡ I.

Trang 12

ROW ECHELON FORM 467

A matrix P having only one nonzero element of value 1 in each row and column

is called a permutation matrix and has the following properties.

ž Premultiplication/postmultiplication of a matrix A by a permutation matrix

P (i.e., P A or AP ) yields the row/column change of the matrix A,

The row space of an M × N matrix A, denoted by R ( A ) , is the space spanned

by the row vectors—that is, the set of all possible linear combinations of row

vectors of A that can be expressed by ATα with an M-dimensional column vector

α On the other hand, the null space of the matrix A, denoted by N(A) , is the space orthogonal (perpendicular) to the row space—that is, the set of all possible

linear combinations of the N -dimensional vectors satisfying Ax = 0.

A matrix is said to be of row echelon form if

ž Each nonzero row having at least one nonzero element has a 1 as its first nonzero element.

ž The leading 1 in a row is in a column to the right of the leading 1 in the upper row.

ž All-zero rows are below the rows that have at least one nonzero element.

A matrix is said to be of reduced row echelon form if it satisfies the above

conditions and, additionally, each column containing a leading 1 has no other nonzero elements.

Trang 13

A square matrix A is said to be positive definite if

x∗TAx > 0 for any nonzero vector x ( B.12.1)

A square matrix A is said to be positive semidefinite if

x∗TAx ≥ 0 for any nonzero vector x ( B.12.2) Note the following properties of a positive definite matrix A.

ž A is nonsingular and all of its eigenvalues are positive.

ž The inverse of A is also positive definite.

There are similar definitions for negative definiteness and negative ness.

semidefinite-Note the following property, which can be used to determine if a matrix

is positive (semi-) definite or not A square matrix is positive definite if and only if:

(i) Every diagonal element is positive.

(ii) Every leading principal minor matrix has positive determinant.

On the other hand, a square matrix is positive semidefinite if and only if: (i) Every diagonal element is nonnegative.

(ii) Every principal minor matrix has nonnegative determinant.

Trang 14

MATRIX INVERSION LEMMA 469

Note also that the principal minor matrices are the submatrices taking the diagonal

elements from the diagonal of the matrix A and, say for a 3 × 3 matrix, the principal minor matrices are

A scalar product of two N -dimensional vectors x and y is denoted by x · y and

An outer product of two three-dimensional column vectors x = [x1 x2 x3]T and

y = [y1 y2 y3]T is denoted by x × y and is defined by

Matrix Inversion Lemma Let A, C, and [C−1+ DA−1B ] be well-defined with

nonsingularity as well as compatible dimensions Then we have

Trang 16

APPENDIX C

DIFFERENTIATION WITH RESPECT TO A VECTOR

The first derivative of a scalar-valued function f (x) with respect to a vector

x = [x1 x2]T is called the gradient of f (x) and defined as

Applied Numerical Methods Using MATLAB, by Yang, Cao, Chung, and Morris

Copyr ight  2005 John Wiley & Sons, I nc., ISBN 0-471-69833-4

471

Trang 17

472 DIFFERENTIATION WITH RESPECT TO A VECTOR

Especially for a square, symmetric matrix A with M = N, we have

∂x x

TAx = (A + AT)x −−−−−−−−−→ 2Axif A is symmetric ( C.6)

The second derivative of a scalar function f (x) with respect to a vector x =

[x1 x2]T is called the Hessian of f (x) and is defined as

On the other hand, the first derivative of a vector-valued function f(x) with

respect to a vector x = [x1 x2]T is called the Jacobian of f (x) and is defined as

Trang 18

(2) δ(t − t1) e −t1s (6) t m e −at u s (t) m!

(s + a) m+1 (10) e −at cos ωt us (t)

s + a (s + a)2+ ω2

Applied Numerical Methods Using MATLAB, by Yang, Cao, Chung, and Morris

Copyr ight  2005 John Wiley & Sons, I nc., ISBN 0-471-69833-4

473

Trang 19

474 LAPLACE TRANSFORM

Table D.2 Properties of Laplace Transform

(0) Definition X(s) = L{x(t)} =

 ∞0

ds X(s) (8) Complex convolution x(t )y(t )→ 1

2πj

 σ0 +∞

σ0 −∞ X(v)Y (s − v) dv (9) Initial value theorem x(0)→ lim

s→∞sX(s)

(10) Final value theorem x( ∞) → lim

s→0sX(s)

Trang 20

x e (t): real and even→ Xe (ω) = Re{X(ω)}

x o (t): real and odd→ Xo (ω) = jIm{X(ω)} x( −t) → X(−ω)

Applied Numerical Methods Using MATLAB, by Yang, Cao, Chung, and Morris

Copyr ight  2005 John Wiley & Sons, I nc., ISBN 0-471-69833-4

475

Trang 21

(2) Symmetry x [n] = xe[n] + xo[n]: real → X() ≡ X( −)

x e[n]: real and even → Xe () = Re{X()}

x o[n]: real and odd → Xo () = jIm{X()}

Trang 22

Applied Numerical Methods Using MATLAB, by Yang, Cao, Chung, and Morris

Copyr ight  2005 John Wiley & Sons, I nc., ISBN 0-471-69833-4

477

Trang 23

2+ 13!x

3+ 15!x

5− 17!x

2+ 14!x

4− 16!x

tan x = x +13 3+152x5+ · · · , |x| < π2 (F.17)tan−1x=

3+15

5−17

Trigonometric Formulas

sin(A ± B) = sin A cos B ± cos A sin B ( F.19) tan(A ± B) = tan A ± tan B

1∓ tan A tan B (F.21)cos(A ± B) = cos A cos B ∓ sin A sin B (F.20)

Trang 24

USEFUL FORMULAS 479

sin3A=1

4( 3 sin A − sin 3A) (F.32) cos3A=1

4( 3 cos A + cos 3A) (F.33)

sin 2A = 2 sin A cos A ( F.34) sin 3A = 3 sin A − 4 sin3A (F.35)

cos 2A= cos2A− sin2A= 1 − 2 sin2A= 2 cos2A− 1 (F.36)

Trang 25

APPENDIX G

SYMBOLIC COMPUTATION

SYMBOLIC EXPRESSIONS

To declare any variable(s) as a symbolic variable, you should use the sym or

symscommand as below.

>>a = sym(’a’); t = sym(’t’); x = sym(’x’);

>>syms a x y t %or, equivalently and more efficiently

Once the variables have been declared as symbolic, they can be used in sions and as arguments to many functions without being evaluated as numeric.

>>eq1 = expand((x + y)^3 - (x + y)^2) %expand

eq1 = 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

Trang 26

482 SYMBOLIC COMPUTATION

>>factor(eq1) %factorize

ans = (x + y - 1)*(x + y)^2

>>horner(eq1) %nested multiplication form

ans = (-1 + y)*y^2 + ((- 2 + 3*y)*y + (-1 + 3*y + x)*x)*x

>>pretty(ans) %pretty form

2

(-1 + y) y + ((-2 + 3 y) y + (-1 + 3 y + x) x) x

If you need to substitute numeric values or other expressions for some bolic variables in an expression, you can use thesubsfunction as below.

sym->>subs(eq1,x,0) %substitute numeric value

ans = -y^2 + y^3

>>subs(eq1,{x,y},{0,x - 1}) %substitute numeric values

ans = (x - 1)^3 - (x - 1)^2

Thesymcommand allows you to declare symbolic real variables by using the

‘real’ option as illustrated below.

>>x = sym(’x’,’real’); y = sym(’y’,’real’);

>>syms x y real %or, equivalently

>>z = x + i*y; %declare z as a symbolic complex variable

>>conj(z) %complex conjugate

ans = x - i*y

>>abs(z)

ans = (x^2 + y^2)^(1/2) %equivalently

The sym function can be used to convert numeric values into their symbolic expressions.

>>sym(1/2) + 0.2

ans = 7/10 %symbolic expression

On the other hand, thedoublecommand converts symbolic expressions into their numeric (double-precision floating-point) values and thevpacommand finds the variable-precision arithmetic (VPA) expression (as a symbolic representation)

of a numeric or symbolic expression with d significant decimal digits, whered

is the current setting of DIGITS that can be set by thedigits command Note that the output of thevpacommand is a symbolic expression even if it may look like a numeric value Let us see some examples.

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

TỪ KHÓA LIÊN QUAN