[100] 008 [100] 008 Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com revised on 2012.10.30 cemmath The Simple is the Best Chapter 8 Partial Differential Equations 8-1 8-2 8-3 8-4 8-5 8-6 8-7 Initial-Boundary Value Problems (Initial BVPs) Steady Elliptic PDEs System of Steady Elliptic PDEs Data Extraction Transient Elliptic PDEs Summary of Syntax References In this chapter, we treat the partial differential equations (PDEs) in two different ways. One is using the Umbrella ‘bvp’ for parabolic-elliptic partial differential equations (i.e., initial-boundary value problems). The other is using the Umbrella ‘pde’ for steady and transient elliptic PDEs of second order. Section 8-1 BVPs) Initial-Boundary Value Problems (Initial Systems of parabolic and elliptic partial differential equations (PDEs) in one spatial variable and time are frequently called the initial-boundary value problems (initial BVPs). Prevailing methods of solving initial BVPs are based on repeated solutions of BVPs with varying initial guesses. In this regard, initial BVPs are treated here. ■ Syntax for Initial BVPs. The syntax for initial BVPs is bvp .@t[n=101,g=1](ta,tb) .x[n=101,g=1](xa,xb) { IC } ( DE, [ BCs] ) where the character ‘@’ is introduced to denote the partial differentiation with 1 [100] 008 Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com respect to time. Basically, three partial derivatives with respect to time {@f} ≡ 𝜕𝑓 𝜕𝑓 ′ 𝜕 𝜕𝑓 𝜕𝑓′′ 𝜕 𝜕 2 𝑓 , {@f′} ≡ ≡ ( ), {@f′′} ≡ ≡ ( 2) 𝜕𝑡 𝜕𝑡 𝜕𝑡 𝜕𝑥 𝜕𝑡 𝜕𝑡 𝜕𝑥 can be handled in Cemmath, where the prime denotes the partial differentiation with respect to a spatial variable. In using time derivatives such as {@f}, the first independent variable of Hub must be time, and proper IC should be prescribed inside the Hub field. ■ Single PDE. Let us consider a single PDE the formulation of which is discussed in ref [1] 0 ≤ 𝑥 ≤ 1, 0 ≤ 𝑡, 𝜋2 𝜕𝑢 𝜕 2 𝑢 = 𝜕𝑡 𝜕𝑥 2 where IC and BCs are given as 𝑢(0, 𝑥) = sin 𝜋𝑥, 𝑢(𝑡, 0) = 0, 𝜋𝑒 −𝑡 + 𝜕𝑢 (𝑡, 1) = 0 𝜕𝑡 A first trial to solve this example over a range of 0 t 2 is %> initial BVP #> bvp .@t[21](0,2) .x[21](0,1) { u = sin(pi*x) } ( // Hub span // Hub field (initial condition) // Stem -pi*pi*{@u} + {u''} = 0, // partial differential equation [ {u} = 0, pi*exp(-t)+{u'} = 0 ] // boundary conditions ) .peep .plot2[6](u) ; // Spoke And Figure 1 displays six curves corresponding to Spoke ‘plot2[6](u)’. Regardless of the time span defined in the Hub span, Spoke ‘plot2[n=6,g=1](u)’ adopts its own time-span 𝑡𝑖 = 𝑡𝑜 + (𝑡𝑓 − 𝑡𝑜 ) 𝑖−1 , 𝑛−1 2 𝑖 = 1,2,3, … , 𝑛 [100] 008 Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com for 𝑔 = 1, and 𝑑𝑡𝑖 = 𝑔𝑑𝑡𝑖−1 otherwise. The default values will be used if not specified explicitly. For this case, time integration is primarily based on the time grid specified as bvp .@t[21](0,2) which corresponds to t = [ 0.0, 0.1, 0.2, 0.3, … , 1.9, 2.0 ]. However, time nodes for plot are prescribed by ‘plot2[6](u)’ which corresponds to t = [0.0, 0.4, 0.8, 1.2, 1.6, 2.0 ] and six curves shown in Figure 1. Figure 1 Initial BVP Using Spoke ‘plot’ or ‘plot3’ yields a three-dimensional plot. Nevertheless, both ‘plot’ and ‘plot2’ cannot be used simultaneously. The following commands %> initial BVP #> bvp .@t[21](0,2) .x[21](0,1) { u = sin(pi*x) } ( pi*pi*{@u} - {u''} = 0, [ {u} = 0, pi*exp(-t)+{u'} = 0 ] ) .peep .plot[6] ( u, 2+0.1*sinh(u*u') ); illustrates the use of Spoke ‘plot’. The results are presented in Figure 2 where two surfaces corresponding to u and 0.1*sinh(u*u') are shown. The surface on 3 [100] 008 Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com the right of Figure 2 has no meaningful interpretation, and is just prepared to show the general capability of mathematical expressions for ‘plot’. Figure 2 3D plot for Initial BVP ■ Data Extraction. The data fields in the numerical solution can be extracted by using Spoke ‘togo’. For example, let us consider again the PDE discussed above %> #> #> #> Data extraction for initial BVP t = (0,2).span(4);; x = (0,1).span(5);; bvp [@t][x] { u = sin(pi*x) } ( pi*pi*{@u} - {u''} = 0, [ {u} = 0, pi*exp(-t)+{u'} = 0 ] ) .togo( X = x, U = u, Up = u', Un = sqrt( u*u+u'*u' ) ); #> X; U; Up; Un; u; extract the fields x, u, u', sqrt(u*u+u'*u') and save them in corresponding matrices as can be seen below. X = [ 0.0000000 [ 0.2500000 [ [ [ [ 0.5000000 0.7500000 1.0000000 U = 0.0000000 0.0000000 0.2500000 0.0000000 0.2500000 0.0000000 ] 0.2500000 ] 0.5000000 0.7500000 1.0000000 0.5000000 0.7500000 1.0000000 0.5000000 ] 0.7500000 ] 1.0000000 ] 0.0000000 0.0000000 0.0000000 ] 4 [100] 008 [ [ [ [ Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com 0.7071068 1.0000000 0.7071068 0.0000000 Up = 3.6568542 0.4088247 0.5832507 0.4323081 0.0752341 0.2419403 0.3535360 0.2865326 0.1060874 0.1492274 0.2260789 0.2032533 0.1143207 1.9112923 1.1221755 0.6826950 ] [ [ [ [ 2.0000000 0.0000000 -2.0000000 -3.6568542 Un = 1.3593053 0.0361025 -1.2436432 -1.6129484 [ [ [ [ [ 3.6568542 2.1213203 1.0000000 2.1213203 3.6568542 1.9112923 1.4194536 0.5843670 1.3166392 1.6147021 [ [ [ [ u = 0.0000000 0.1492274 0.2260789 0.2032533 0.6826950 0.5111245 0.1036875 -0.2862922 [ 0.1143207 [ ] ] ] ] 0.8133469 0.5111245 ] 0.0794188 0.1036875 ] -0.6154460 -0.2862922 ] -0.8281156 -0.4251691 ] 1.1221755 0.8485684 0.3623466 0.6788775 0.8348832 0.6826950 0.5324632 0.2487223 0.3511056 0.4402704 ] ] ] ] ] ] ] ] ] -0.4251691 ] The i -th column in each matrix corresponds to the field solution at time 𝑡𝑖 , 𝑖 = 1,2,3, … , 𝑛 where 𝑛 = 4 for this case. In addition, the variable u in the Hub field contains u = [ u, u' ] at the final stage of solution. The actual output for u is u = [ [ 0 0.14923 [ [ [ 0.22608 0.20325 0.11432 0.68269 0.51112 ] ] 0.10369 ] -0.28629 ] -0.42517 ] where −𝜋𝑒 −2 = −0.42516830 is shown in the last element of the second column, as expected from BCs. In prescribing IC, it is also possible to specify derivatives by the following syntax 5 [100] 008 Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com { u = [ u(x), u' (x) ] } When the initial guess is given as u = u(x), derivatives of the initial guess are evaluated internally with centered difference scheme. Nevertheless, it is wise to specify the known mathematical expressions of derivatives for accuracy improvement. ■ Surface Plot. Next example is the Black-Scholes PDE discussed in ref [1] 𝜕𝑢 𝜕 2 𝑢 𝜕𝑢 = 2 + (𝑘 − 1) − 𝑘𝑢, 𝜕𝑡 𝜕𝑥 𝜕𝑥 𝑎 ≤ 𝑥 ≤ 𝑏, 𝑡0 ≤ 𝑡 ≤ 𝑡𝑓 where 𝑘 = 𝑟/(𝜎 2 /2), 𝑟 = 0.065, 𝜎 = 0.8 𝑎 = log(2/5), 𝑏 = log(7/5) , 𝑡0 = 0, 𝑡𝑓 = 5 And IC and BCs are given as 𝑢(𝑥, 0) = max(𝑒 𝑥 − 1,0), 𝑢(𝑎, 𝑡) = 0, 𝑢(𝑏, 𝑡) = 7 − 5𝑒 −𝑘𝑡 5 This example is solved by %> Black-Scholes PDE #> (r,s) = (0.065,0.8); k = r/(s^2/2); #> (a,b) = (log(2/5),log(7/5)); (to,tf) = (0,5); #> bvp .@t[11](to,tf) .x[21](a,b) { u = .max(exp(x)-1,0) } ( -{@u} + {u''} + (k-1)*{u'} - k*u = 0, [ {u} = 0, {u} = (7-5*exp(-k*t))/5 ] ) .peep .plot[11](u); And the results are shown in the left of Figure 3. Changing ‘plot’ to ‘plot2’ 6 [100] 008 Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com yields a 2D plot shown in the right of Figure 3. Figure 3 3D and 2D plot for initial BVP ■ System of PDEs. An example for a system of PDEs is taken from ref [1]. The PDEs are written as 𝜕𝑢 1 𝜕 2 𝑢 1 𝜕𝑣 1 𝜕 2 𝑣 1 = + , = + 2 2 2 𝜕𝑡 2 𝜕𝑥 1+𝑣 𝜕𝑡 2 𝜕𝑥 1 + 𝑢2 where the initial conditions for 0 ≤ 𝑡 ≤ 0.2 are 1 𝑢(0, 𝑥) = 1 + cos(2𝜋𝑥) , 2 1 𝑣(0, 𝑥) = 1 − cos(2𝜋𝑥) 2 And the boundary conditions for 0 ≤ 𝑥 ≤ 1 are 𝑢′(𝑡, 0) = 𝑣′(𝑡, 0) = 0, 𝑢′(𝑡, 1) = 𝑣′(𝑡, 1) = 0 Since the utility of Umbrella is handling equations with minimum amount of modification, it is not surprising to note that the following Cemmath commands %> system of initial BVP #> bvp .@t[5](0,0.2) .x[10](0,1) { // Hub span u = [ 1+0.5*cos(2*pi*x), -pi*sin(2*pi*x) ], v = [ 1-0.5*cos(2*pi*x), pi*sin(2*pi*x) ] // Hub field } ( -{@u} + 0.5*{u''} + 1/(1+v*v) = 0, 7 [ {u'} = 0, {u'} = 0 ], [100] 008 Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com -{@v} + 0.5*{v''} + 1/(1+u*u) = 0, [ {v'} = 0, {v'} = 0 ] ).peep .togo( U = u, U1 = u', V = v, V1 = v', KE = 0.5*(u'*u'+v'*v') ) .plot[6](u,v+2, 4 + 0.5*(u'*u'+v'*v')); #> u; v; U; U1; V; V1; KE; produce the desired solutions. The results are shown in Figure 4 and Figure 5. In particular, the energy field defined as 1 𝜕𝑢 2 𝜕𝑣 2 𝐸(𝑡, 𝑥) = [( ) + ( ) ] , 2 𝜕𝑥 𝜕𝑥 𝐸(𝑡) = 1 1 𝜕𝑢 2 𝜕𝑣 2 ∫ ( ) + ( ) 𝑑𝑥 2 0 𝜕𝑥 𝜕𝑥 is known to vanish as time approaches an infinity (see [ref. 1]). Such a behavior is represented in the energy field shown in Figure 5. Figure 4 Solution to a system of PDEs (u and v) Figure 5 Solution to a system of PDEs (energy field) 8 [100] 008 Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com In addition, we extracted the fields at specified time steps by ‘.@t[5](0,0.2)’, i.e. t = [ 0.0, 0.05, 0.1, 0.15, 0.2 ] and the values are listed as follows (only two cases are listed to save space) U = [ 1.5 1.2688 1.1677 1.13 [ [ [ [ [ 1.383 1.0868 0.75 0.53015 0.53015 1.2117 1.067 0.90265 0.79542 0.79542 1.1398 1.0693 0.98904 0.93671 0.93671 1.1164 1.082 1.0428 1.0173 1.0173 1.1163 1.0996 1.0805 1.068 1.068 1.123 ] ] ] ] ] ] [ [ [ [ ... 0.75 1.0868 1.383 1.5 0.90265 1.067 1.2117 1.2688 0.98904 1.0693 1.1398 1.1677 1.0428 1.082 1.1164 1.13 1.0805 1.0996 1.1163 1.123 ] ] ] ] [ [ [ 0 4.0779 9.572 0 1.0564 2.4796 0 0.25155 0.59047 0 0.059868 0.14053 [ [ [ [ [ 7.4022 1.1545 1.1545 7.4022 9.572 1.9175 0.29908 0.29908 1.9175 2.4796 0.45662 0.07122 0.07122 0.45662 0.59047 0.10867 0.01695 0.01695 0.10867 0.14053 ... KE = 0 ] 0.01424 ] 0.033427 ] 0.025849 0.0040317 0.0040317 0.025849 0.033427 ] ] ] ] ] [ 4.0779 1.0564 0.25155 0.059868 0.01424 ] [ 5.9208e-031 4.0123e-051 8.6999e-070 3.0184e-087 1.6755e-103 ] Note that the first column of U is exactly the same as the initial condition 1 𝑢(0, 𝑥) = 1 + cos(2𝜋𝑥) 2 Our next example is also adopted from ref [1]. This problem has boundary layers at both ends of the interval, and a rapid change occurs in small time. 9 [100] 008 Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com 𝜕𝑢 𝜕2𝑢 = 0.024 − 𝐹(𝑢 − 𝑣) 𝜕𝑡 𝜕𝑥 2 𝜕𝑣 𝜕2𝑣 = 0.170 + 𝐹(𝑢 − 𝑣) 𝜕𝑡 𝜕𝑥 2 where 𝐹(𝑦) = exp(5.73𝑦) − exp(−11.46𝑦). The initial conditions for 0 ≤ 𝑡 ≤ 2 are 𝑢(0, 𝑥) = 1, 𝑣(0, 𝑥) = 0 And the boundary conditions for 0 ≤ 𝑥 ≤ 1 are 𝑢′(𝑡, 0) = 0, 𝑢(𝑡, 1) = 1, 𝑣(𝑡, 0) = 0, 𝑣′(𝑡, 1) = 0 Due to the presence of rapid change in time and the boundary layers in space, spanning numerical grids must reflect such behavior. Therefore, geometrically increasing grid spans are employed %> boundary layers and rapid change in small time #> tout = [0, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 1.5, 2];; #> bvp.@t[21,1.4](0,2) .x[21,-1.1](0,1) { u = 1, v = 0 } ( -{@u}+0.024*{u''}-( exp(5.73*(u-v))-exp(-11.46*(u-v)) ) = 0, [ {u'} = 0, {u} = 1 ], -{@v}+0.170*{v''}+( exp(5.73*(u-v))-exp(-11.46*(u-v)) ) = 0, [ {v} = 0, {v'} = 0 ] ) .relax(0.4) .maxiter(400) .peep .plot[tout](u, 2+v ); It should be noted that the function 𝐹(𝑦) = exp(5.73𝑦) − exp(−11.46𝑦) is repeated for each equation. This is because our solution is based on sequential procedure and hence iteration is imposed at each time step. Another feature worthy of note is the use of Spoke ‘plot’. If a pre-defined matrix is used inside ‘[ ]’, curves are selected from the corresponding times. Numerical results are shown in Figure 6. 10 [100] 008 Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com Figure 6 Solution to a system of PDs (u and v) Section 8-2 Steady Elliptic PDEs Steady elliptic PDEs involving two or three independent spatial variables are treated here. For generality, three spatial coordinates are considered in explaining Umbrella ‘pde’. Nevertheless, only licensed version can handle three spatial coordinates. ■ Standard Form. The standard form of elliptic PDEs with three spatial coordinates 𝑥, 𝑦, 𝑧 is written here as 𝜕2𝑢 𝜕2𝑢 𝜕2𝑢 + 𝑐 + 𝑐 𝑢𝑦𝑦 𝑢𝑧𝑧 𝜕𝑥 2 𝜕𝑦 2 𝜕𝑧 2 𝜕𝑢 𝜕𝑢 𝜕𝑢 +𝑐𝑢𝑥 + 𝑐𝑢𝑦 + 𝑐𝑢𝑧 + 𝑐𝑢 𝑢 = 𝑐𝑠 𝜕𝑥 𝜕𝑦 𝜕𝑧 𝑐𝑢𝑥𝑥 where 𝑐𝑢𝑥𝑥 ≠ 0, 𝑐𝑢𝑦𝑦 ≠ 0, 𝑐𝑢𝑧𝑧 ≠ 0. And 𝑐𝑢𝑥𝑥 , 𝑐𝑢𝑦𝑦 , 𝑐𝑢𝑧𝑧 are all of the same sign from elliptic nature. To designate the partial derivatives, our notations are innovated 𝜕2𝑢 𝜕2𝑢 𝜕2𝑢 ^^ ~~ , {u } ≡ , {u } ≡ 𝜕𝑥 2 𝜕𝑦 2 𝜕𝑧 2 𝜕𝑢 𝜕𝑢 𝜕𝑢 {u′} ≡ , {u^ } ≡ , {u~ } ≡ , 𝜕𝑥 𝜕𝑦 𝜕𝑧 {u′′} ≡ 11 [100] 008 Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com Then, the PDE of interest can be rewritten as '' ' cuxx*{u } + cuyy*{u^^} + cuzz*{u~~} + cux*{u } + cuy*{u^} + cuz*{u~} + cu*{u} = cs where nonlinear terms must be properly expressed as coefficients or source terms. Those terms with ‘{ }’ are participating the discretization procedure. The boundary conditions (BCs) also has a standard form 𝑏𝑢𝑥 𝜕𝑢 𝜕𝑢 𝜕𝑢 + 𝑏𝑢𝑦 + 𝑏𝑢𝑧 + 𝑏𝑢 𝑢 = 𝑏𝑠 𝜕𝑥 𝜕𝑦 𝜕𝑧 which can be rewritten as ' bux*{u }+buy*{u^}+buz*{u~}+bu*{u} = bs The primary limitation of Umbrella ‘pde’ at present is that it must be of secondorder in each coordinate. ■ Syntax for PDE. The syntax of Umbrella ‘pde’ for steady twodimensional space is pde .x[n=31,g=1](a,b) .y[n=31,g=1]( c(x),d(x) ) ( DE, [BCs] ) where two grid spans for x and y would be familiar to readers at this point. Therefore, discussed below is the BCs in the Stem. Since there exist two independent spatial coordinates, BCs must be specified in a pre-defined sequence for consistency. The BCs in the Stem are treated one-by-one for each coordinate [ x-left BC, x-right BC, y-left BC, y-right BC ] ■ Discretization Method. It is important to understand how the mesh is constructed and the discretization is performed in solving PDEs. With two independent spatial variables (say, 𝑥, 𝑦), the grid span in each direction is 12 [100] 008 Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com defined 𝑥𝑖 = 𝑥𝑖−1 + 𝑑𝑥𝑖−1 , 𝑦𝑖 = 𝑦𝑖−1 + 𝑑𝑦𝑖−1 , 𝑑𝑥𝑖 = 𝑔𝑥 𝑑𝑥𝑖−1 𝑑𝑦𝑖 = 𝑔𝑦 𝑑𝑦𝑖−1 Then, the nodes for solution are selected to be the center of a quadrangle enclosed by the four points (𝑥𝑖−1 , 𝑦𝑖−1 ), (𝑥𝑖 , 𝑦𝑖−1 ), (𝑥𝑖 , 𝑦𝑖 ), (𝑥𝑖−1 , 𝑦𝑖 ) For boundaries, the nodes for solution are selected to be the center of two adjacent points. It is worthy of note that the major weakness arises at four corners of the whole domain, since the solution at these corners are extrapolated from the inside or the boundaries. Therefore, for the syntax pde .x[m=31,g=1](a,b) .y[n=31,g=1]( c(x),d(x) ) ( DE, [BCs] ) the mesh grid for computation has a dimension of (𝑛 + 1) × (𝑚 + 1). This means that the column of (𝑛 + 1) × (𝑚 + 1) matrix represents [𝑦1 , 𝑦2 , … , 𝑦𝑛+1 ]. ■ Single Elliptic PDE. Our first example is very simple as shown below 𝜕2𝑢 𝜕2𝑢 + + 10 = 0 𝜕𝑥 2 𝜕𝑦 2 𝑢(−1, 𝑦) = 𝑢(1, 𝑦) = 𝑢(𝑥, −1) = 𝑢(𝑥, 1) = 1 which can be solved by %> PDE of 2nd-order #> pde .x[10](0,1) .y[10](0,1) ( {u''} + {u^^} + 10 = 0, [ {u} = 1, {u} = 1, {u} = 1, {u} = 1 ] ) .plot( u, 0 ); 13 [100] 008 Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com The results are shown in Figure 7. Note that the computational mesh corresponds to the field 0, and is shown in the right of Figure 7. Figure 7 Solution and mesh for a single PDE As was mentioned above, based on the 10 × 10 pre-defined mesh, computational mesh of dimension 11 × 11 is re-generated as shown in Figure 7. This is due to the treatment of control volume for discretizing the partial differential equation. The solution shown in the left of Figure 7 bears a symmetry in both directions as expected. ■ Comparison with Exact Solution. Another example has an exact solution 𝑢𝑒𝑥 (𝑥, 𝑦) = 𝑥 2 + 2𝑦 2 . The PDE of interest is written as 𝜕2𝑢 𝜕2𝑢 + =6 𝜕𝑥 2 𝜕𝑦 2 𝑢(−1, 𝑦) = 1 + 2𝑦 2 , 𝑢(1, 𝑦) = 1 + 2𝑦 2 𝑢(𝑥, −1) = 𝑥 2 + 2, 𝑢(𝑥, 1) = 𝑥 2 + 2 We solve this example by %> PDE with exact solution #> pde .x[10](-1,1) .y[10](-1,1) ( {u''} + {u^^} = 6, [ {u} = 1+2*y*y, {u} = 1+2*y*y, {u} = x*x+2, {u} = x*x+2 ] ) .plot( u, -u+x*x+2*y*y ) 14 [100] 008 Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com .togo( Error = -u+x*x+2*y*y ); #> Error; The u field is shown in Figure 8, and the error distribution is shown in Figure 9. Figure 8 A single PDE with exact solution Figure 9 Error distribution It is worthy of note that data at four corners are linearly extrapolated. This is the reason why there occur noticeable discrepancies at four corners in Figure 9. ■ Conservative Form. The second-order terms in some PDEs are frequently expressed in conservative forms. Thus we introduce the following syntax for conservative forms 15 [100] 008 Chapter 8 Partial Differential Equations, {(p)u′}′ ≡ Tutorial by www.msharpmath.com 𝜕 𝜕𝑢 𝜕 𝜕𝑢 𝜕 𝜕𝑢 (𝑝 ), {(p)u^ }^ ≡ (𝑝 ) , {(p)u~ }~ ≡ (𝑝 ), 𝜕𝑥 𝜕𝑥 𝜕𝑦 𝜕𝑦 𝜕𝑧 𝜕𝑧 These conservative forms can be treated as long as they are the highest terms. This implies that either {(p)u'}' or {u''} should appear once but not together. An example is 𝜕 𝜕𝑢 𝜕 𝜕𝑢 [(𝑒 5𝜉 + 1) ] + [(𝑒 5𝜂 + 1) ] + 10 = 0 𝜕𝜉 𝜕𝜉 𝜕𝜂 𝜕𝜂 where 𝜉 = −1: 𝑢(−1, 𝜂) = 0, 𝜉 = 1: 𝑢(1, 𝜂) = 0 𝜂 = −1: 𝑢(𝑥, −1) = 0, 𝜂 = 1: 𝑢(𝑥, 1) = 0 This PDE can be solved by %> PDE in conservative form #> pde .xi[21](-1,1) .eta[21]( -1,1 ) ( {(exp(5*xi)+1)u'}' + {(exp(5*eta)+1)u^}^ + 10 = 0, [ {u} = 0, {u} = 0, {u} = 0, {u} = 0 ] ) .plot(u); And the result is shown in Figure 10. Figure 10 Conservative PDE 16 [100] 008 Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com Next example is given below 𝜕 𝜕𝑢 𝜕 𝜕𝑢 𝜕𝑢 𝜕𝑢 + +𝑢+2 = 0 [(𝑒 𝑥 + 1) ] + [(𝑒 𝑦 + 1) ] + 𝑢 𝜕𝑥 𝜕𝑥 𝜕𝑦 𝜕𝑦 𝜕𝑥 𝜕𝑦 where 𝑥 = −3: 𝑢(−3, 𝑦) = 0, 𝑥 = 3: 𝑢(3, 𝑦) = 0 −3 ≤ 𝑥 ≤ 3: 𝑢(𝑥, 𝑦 = −√10 − 𝑥 2 ) = 0 , 𝑢(𝑥, 𝑦 = 4 − 0.5𝑥) = 0 For this example, we employ non-uniform grid spans in both directions %> PDE with nonuniform grid #> pde .x[21](-3,3) .y[21]( -sqrt(10-x*x),4-x/2 ) ( {(exp(x)+1)u'}' + {(exp(y)+1)u^}^ + u*{u'} + {u^} + u + 2 = 0, [ {u} = 0, {u} = 0, {u} = 0, {u} = 0 ] ) .plot(u); And the result is shown in Figure 11. Figure 11 PDE in an irregular geometry Section 8-3 System of Steady Elliptic PDEs 17 [100] 008 Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com ■ System of PDEs. For coupled steady elliptic PDEs, we have the following syntax pde .x[n=31,g=1](a,b) .y[n=31,g=1]( c(x),d(x) ) ( DE, [BCs], DE, [BCs], … ) where each PDE must have its own dependent variable as well as DE and BCs. 𝜕2𝑢 𝜕2𝑢 𝜕𝑢 𝜕𝑢 + 2+5−𝑢 −𝑣 =0 2 𝜕𝑥 𝜕𝑦 𝜕𝑥 𝜕𝑦 𝜕2𝑣 𝜕2𝑣 𝜕𝑢 𝜕𝑢 + 2−3−𝑢 −𝑣 =0 2 𝜕𝑥 𝜕𝑦 𝜕𝑥 𝜕𝑦 with 𝑢(0, 𝑦) = 𝑢(1, 𝑦) = 𝑢(𝑥, 0) = 𝑢(𝑥, 1) = 0 𝑣(0, 𝑦) = 𝑣(1, 𝑦) = 𝑣(𝑥, 0) = 𝑣(𝑥, 1) = 0 Due to the presence of nonlinear terms in both u and v, it may be helpful to use the under-relaxation for convergence. The following commands %> System of steady elliptic PDEs #> pde .x[30](0,1) .y[30](0,1) ( {u''} + {u^^} + 5 - u*{u'}-v*{u^} = 0, [ {u} = 0, {u} = 0, {u} = 0, {u} = 0 ], {v''} + {v^^} - 3 - u*{v'}-v*{v^} = 0, [ {v} = 0, {v} = 0, {v} = 0, {v} = 0 ] ).plot( u,v-0.1 ); are executed to get the results shown in Figure 12. 18 [100] 008 Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com Figure 12 system of PDEs Section 8-4 Data Extraction ■ Spoke ‘togo’. To extract field data, we use Spoke ‘togo’ as before. To illustrates this, we consider again the first example discussed above 𝜕2𝑢 𝜕2𝑢 + +5=0 𝜕𝑥 2 𝜕𝑦 2 𝑢(−1, 𝑦) = 𝑢(1, 𝑦) = 𝑢(𝑥, −1) = 𝑢(𝑥, 1) = 0 and the following Cemmath commands %> Data extraction #> pde .x[4](0,1) .y[5](0,1) ( {u''} + {u^^} + 5 = 0, [ {u} = 1, {u} = 1, {u} = 1, {u} = 1 ] ) .plot( u ) .togo( X = x, Y = y, U = u ); #> X; Y; U; Note that ‘pde .x[4](0,1) .y[5](0,1)’ results (5 + 1) × (4 + 1) = 6 × 5 in mesh grid, as shown in Figure 13. 19 [100] 008 Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com Figure 13 Data extraction Data extraction for this case yields the following matrices. X = [ [ [ 0 0 0 0.16667 0.16667 0.16667 0.5 0.5 0.5 0.83333 0.83333 0.83333 1 ] 1 ] 1 ] [ [ [ 0 0 0 0.16667 0.16667 0.16667 0.5 0.5 0.5 0.83333 0.83333 0.83333 1 ] 1 ] 1 ] [ [ [ [ [ 0 0.125 0.375 0.625 0.875 0 0.125 0.375 0.625 0.875 0 0.125 0.375 0.625 0.875 0 0.125 0.375 0.625 0.875 [ 1 1 1 1 1 ] [ [ 1 1 1 1.1445 1 1.2063 1 1.1445 1 ] 1 ] [ [ [ [ 1 1 1 1 1.2487 1.2487 1.1445 1 1.3758 1.3758 1.2063 1 1.2487 1.2487 1.1445 1 1 1 1 1 Y = 0 0.125 0.375 0.625 0.875 ] ] ] ] ] U = 20 ] ] ] ] [100] 008 Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com Section 8-5 Transient Elliptic PDEs ■ Syntax for PDE. The syntax of Umbrella ‘pde’ for transient twodimensional space is pde .@t[ntime=31,g=1](to,tf) .x[m=31,g=1](a,b) .y[n=31,g=1]( c(x),d(x) ) ( DE, [BCs] ) where time must be the first grid span. Spoke ‘togo’ for this case results in a matrix of dimension (𝑛 + 1)(𝑚 + 1) × ntime Therefore, each column contains a field solution at a give time step. ■ Single Transient PDE. Our first example for a single transient PDE is described as 𝜕𝑢 𝜕 2 𝑢 𝜕 2 𝑢 = + + 10, 𝑢(0, 𝑥, 𝑦) = 0 𝜕𝑡 𝜕𝑥 2 𝜕𝑦 2 𝑢(𝑡, −1, 𝑦) = 𝑢(𝑡, 1, 𝑦) = 𝑢(𝑡, 𝑥, −1) = 𝑢(𝑡, 𝑥, 1) = 0 which can be solved by #> pde.@t[4](0,0.1).x[4](0,1).y[4](0,1) { u=0 } ( -{@u}+{u''} + {u^^} + 10 = 0, [ {u}=0, {u}=0, {u}=0, {u}=0 ] ) .peep .plot[4]( u ) .togo( U=u ); U; First, the result from Spoke ‘togo’ is listed as U = [ [ 0 0 0 0 0 0 21 0 ] 0 ] [100] 008 Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com [ [ [ [ [ [ 0 0 0 0 0 0 0 0 0 0 0.16275 0.20392 0 0 0 0 0.24752 0.32831 0 0 0 0 0.29412 0.40445 ] ] ] ] ] ] [ [ [ [ [ 0 0 0 0 0 0.16275 0 0 0.20392 0.26275 0.24752 0 0 0.32831 0.45002 0.29412 0 0 0.40445 0.57668 ] ] ] ] ] [ [ [ [ [ 0 0 0 0 0 0.20392 0 0 0.16275 0.20392 0.32831 0 0 0.24752 0.32831 0.40445 0 0 0.29412 0.40445 ] ] ] ] ] [ [ [ [ [ 0 0 0 0 0 0.16275 0 0 0 0 0.24752 0 0 0 0 0.29412 0 0 0 0 ] ] ] ] ] [ [ 0 0 0 0 0 0 0 ] 0 ] As was mentioned, each column consists of a solution at specified time 𝑡𝑖 , 𝑖 = 1,2,3, … , 𝑁. For example, the first column corresponds to the initial condition of 𝑢 = 0. As the column index increases, it is easy to note that the maximum value increases due to evolution of transient solution to the steady-state solution. Meanwhile, time evolution of solution is drawn in Figure 14 22 [100] 008 Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com Figure 14 Time evolution of solution ■ System of Transient PDEs. An example for a system of transient elliptic PDEs is written below 𝜕𝑢 𝜕𝑢 𝜕𝑢 𝜕 2 𝑢 𝜕 2 𝑢 +𝑢 +𝑣 = + +6 𝜕𝑡 𝜕𝑥 𝜕𝑦 𝜕𝑥 2 𝜕𝑦 2 𝜕𝑣 𝜕𝑣 𝜕𝑣 𝜕 2 𝑣 𝜕 2 𝑣 +𝑢 +𝑣 = + −4 𝜕𝑡 𝜕𝑥 𝜕𝑦 𝜕𝑥 2 𝜕𝑦 2 With the initial condition 𝑢(0, 𝑥, 𝑦) = 0, 𝑣(0, 𝑥, 𝑦) = 1 And the boundary conditions 𝑢(𝑡, 0, 𝑦) = 𝑢(𝑡, 1, 𝑦) = 𝑢(𝑡, 𝑥, 0) = 𝑢(𝑡, 𝑥, 1) = 0 𝑣(𝑡, 0, 𝑦) = 𝑣(𝑡, 1, 𝑦) = 𝑣(𝑡, 𝑥, 0) = 𝑣(𝑡, 𝑥, 1) = 1 This system of transient elliptic PDEs can be solved by #> pde .@t[4](0,0.15) .x[30](0,1) .y[30](0,1) { u=0, v=1 -{@u} - u*{u'}-v*{u^} + {u''} + {u^^} + 6 = 0, 23 } ( [100] 008 Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com [ {u}=0, {u}=0, {u}=0, {u}=0 ], -{@v} - u*{v'}-v*{v^} + {v''} + {v^^} - 4 = 0, [ {v}=1, {v}=1, {v}=1, {v}=1 ] ) .peep.plot( u,v ); u;v; The results are shown in Figure 15. Figure 15 Time evolution of solution u and v 24 [100] 008 Chapter 8 Partial Differential Equations, Tutorial by www.msharpmath.com Section 8-6 Summary of Syntax ■ Syntax for Initial BVPs. The syntax for initial BVPs is bvp .@t[n=101,g=1](ta,tb) .x[n=101,g=1](xa,xb) { IC } ( DE, [ BCs] ) 𝜕𝑓 𝜕𝑓 ′ 𝜕 𝜕𝑓 𝜕𝑓′′ 𝜕 𝜕 2 𝑓 {@f} ≡ , {@f′} ≡ ≡ ( ), {@f′′} ≡ ≡ ( 2) 𝜕𝑡 𝜕𝑡 𝜕𝑡 𝜕𝑥 𝜕𝑡 𝜕𝑡 𝜕𝑥 𝜕2𝑢 𝜕2𝑢 𝜕2𝑢 ^^ ~~ , {u } ≡ , {u } ≡ 𝜕𝑥 2 𝜕𝑦 2 𝜕𝑧 2 𝜕𝑢 𝜕𝑢 𝜕𝑢 {u′} ≡ , {u^ } ≡ , {u~ } ≡ , 𝜕𝑥 𝜕𝑦 𝜕𝑧 {u′′} ≡ pde .x[m=31,g=1](a,b) .y[n=31,g=1]( c(x),d(x) ) ( DE, [BCs] ) {(p)u′}′ ≡ 𝜕 𝜕𝑢 𝜕 𝜕𝑢 𝜕 𝜕𝑢 (𝑝 ), {(p)u^ }^ ≡ (𝑝 ) , {(p)u~ }~ ≡ (𝑝 ), 𝜕𝑥 𝜕𝑥 𝜕𝑦 𝜕𝑦 𝜕𝑧 𝜕𝑧 pde .x[n=31,g=1](a,b).y[n=31,g=1](c(x),d(x)) ( DE, [BCs], DE, [BCs],..) pde .x[n=31,g=1](a,b).y[n=31,g=1](c(x),d(x)) ( DE, [BCs], DE, [BCs],.. ) pde .@t[ntime=31,g=1](to,tf) .x[m=31,g=1](a,b) .y[n=31,g=1]( c(x),d(x) ) ( DE, [BCs] ) Section 8-7 References [1] D.J. Higham and N.J. Higham, MATLAB(R) Program GuideBook, 2ed., SIAM (2005). [2] MATLAB(R) 7, Mathematics, The MathWorks Inc. (2009). 25