User:Leo Trottier/PDE/Approximate and numerical methods for partial differential equations

From Scholarpedia
Jump to: navigation, search

    The preceding discussion pertains to the exact or analytical solution of PDEs. For example, in the case of a heat equation or a wave equation, an exact solution would be a function \(w=f(x,t)\) which, when substituted into the respective equation would satisfy it identically along with all of the associated initial and boundary conditions.

    Although analytical solutions are exact, they also may not be available, simply because we do not know how to derive such solutions. This could be because the PDE system has too many PDEs, or they are too complicated, e.g., nonlinear, or both, to be amenable to analytical solution. In this case, we may have to resort to an approximate solution. That is, we seek an analytical or numerical approximation to the exact solution.

    Perturbation methods are an important subset of appro:ximate analytical methods. They may be applied if the problem involves small (or large) parameters, which are used for constructing solutions in the form of asymptotic expansions. For books on perturbation methods, see Google Book Search. These and other methods for PDEs are also outlined in Zwillinger (1997).

    Unlike exact and approximate analytical methods, methods to compute numerical PDE solutions are in principle not limited by the number or complexity of the PDEs. This generality combined with the availability of high performance computers makes the calculation of numerical solutions feasible for a broad spectrum of PDEs (such as the Navier–Stokes equations) that are beyond analysis by analytical methods. The development and implementation (as computer codes) of numerical methods or algorithms for PDE systems is a very active area of research. Here we indicate in the external links just two readily available links to Scholarpedia.

    We now consider the numerical solution of a parabolic PDE, a hyperbolic PDE, and an elliptic PDE.

    Contents

    Parabolic PDE

    Analytical solutions to a parabolic PDE (heat equation) are given here. But we will proceed with a numerical solution and use one of these analytical solutions to evaluate the numerical solution.

    We can consider the numerical solution to the heat equation \[\tag{1} \frac{\partial w}{\partial t}-\frac{\partial^2w}{\partial x^2}=0 \]

    as a two-step process:

    1. Numerical approximation of the derivative \(\dfrac{\partial ^2 w}{\partial x^2}\ .\) At this point, we will have a semi-discretization of Eq. (1).
    2. Numerical approximation of the derivative \(\dfrac{\partial w}{\partial t}\ .\) At this point, we will have a full discretization of Eq. (1).

    In order to implement these two steps, we require a grid in \(x\) and a grid in \(t\ .\) For the grid in \(x\), we denote a position along the grid with the index \(i\ .\) Then we can consider the Taylor series expansion of the numerical solution at grid point \(i\) \[\tag{2} w_{i+1}=w_{i} + \dfrac{dw_i}{dx}(x_{i+1}-x_i) + \dfrac{d^2w_i}{dx^2}\dfrac{(x_{i+1}-x_{i})^2}{2!} + \dfrac{d^3w_i}{dx^3}\dfrac{(x_{i+1}-x_{i})^3}{3!} + \cdots \]

    and \[\tag{3} w_{i-1}=w_{i} + \dfrac{dw_i}{dx}(x_{i-1}-x_i) + \dfrac{d^2w_i}{dx^2}\dfrac{(x_{i-1}-x_{i})^2}{2!} + \dfrac{d^3w_i}{dx^3}\dfrac{(x_{i-1}-x_{i})^3}{3!} + \cdots \]

    If we consider a uniform grid (a grid with uniform spacing \(\Delta x = x_{i+1}-x_i = x_{i} - x_{i-1})\), addition of Eqs. (2) and (3) gives (note the cancellation of the first and third derivative terms since \(x_{i-1}-x_{i} = -\Delta x\)) \[\tag{4} w_{i+1}+w_{i-1}=2w_{i} + \dfrac{d^2w_i}{dx^2}\Delta x^2 + O(\Delta x^4) \]

    where \(O(\Delta x^4)\) denotes a term proportional to \(\Delta x^4\) or of order \(\Delta x^4\ ;\) this term can be considered a truncation error resulting from truncating the Taylor series of Eqs. (2) and (3) beyond the \(\Delta x^2\) term. Then Eq. (4) gives for the second derivative \[\tag{5} \dfrac{d^2w_i}{dx^2} \approx \dfrac{w_{i+1}-2w_{i}+w_{i-1}}{\Delta x^2} + O(\Delta x^2) \]

    Equation (5) is a second order (because of the principal error or truncation error \(O(\Delta x^2)\)) finite difference approximation of \(d^2w_i/dx^2\ .\)

    If Eq. (5) is substituted in Eq. (1) (to replace the derivative \(\frac{\partial ^2w} {\partial x^2}\)), a system of ODEs results \[\tag{6} \dfrac{dw_i}{dt}=D\dfrac{w_{i+1}-2w_{i}+w_{i-1}}{\Delta x^2}+O(\Delta x^2),\quad i=1,2,\dots,N \]

    (we have added a multiplying constant \(D\) to the right-hand side of Eq. (1), generally termed a thermal diffusivity if \(w\) in Eq. (1) is temperature and a mass diffusivity if \(w\) is concentration; \(D\) has the MKS units m2/s as expected from a consideration of Eq. (1) with \(x\) in metres and \(t\) in seconds).

    Note that the independent variable \(x\) does not appear explicitly in Eqs. (6) and that the only independent variable is \(t\) (so that they are ODEs). \(N\) is the number of points in the \(x\) grid (\(x\) is termed a boundary value variable since the terminal grid points at \(i=1\) and \(i=N\) typically refer to the boundaries of a physical system). Thus Eq. (1) is partly discretized (in \(x\)) and therefore Eqs. (6) are referred to as a semi-discretization.

    To compute a solution to Eq. (1), we could apply an established initial-value integrator in \(t\ .\) This is the essence of the method of lines (MOL). Alternatively, we could now discretize Eqs. (6). For example, if we apply Eq. (2) on a grid in \(t\) with an index \(k\) \[\tag{7} w_{i}^{k+1}=w_i^k + \dfrac{dw_i^k}{dt}(t^{k+1}-t^k) + \dfrac{d^2w_i^k}{dt^2} \dfrac{(t^{k+1}-t^{k})^2}{2!} + \cdots,\quad i=1,2,\dots,N,\quad k=1,2,\dots \]

    If the grid in \(t\) has a uniform spacing \(h = t^{k+1}-t^k\) and if truncation after the first derivative term is applied, \[\tag{8} w_{i}^{k+1}=w_i^k + \dfrac{dw_i^k}{dt}h + O(h^2) \]

    Equation (8), the classical Euler's method, can be used to step along the solution of Eq. (1) from point \(k\) to \(k+1\) (at a grid point \(i\) in \(x\)).

    Application of Eq. (8) to Eq. (6) gives the fully discretized approximation of Eq. (1) \[\tag{9} w_i^{k+1}=w_i^k+hD\dfrac{w_{i+1}^k-2w_{i}^k+w_{i-1}^k}{\Delta x^2} \]

    In Eq. (7) we do not specify the total number of grid points in \(t\) (as we did with the grid in \(x\)); \(t\) is an initial value variable since it is typically time, and is defined over the semiinfinite interval \(0 \leq t \leq \infty\ .\)

    Note that Eq. (9) explicitly gives the solution at the advanced point in \(t\) (at \(k+1\)) and therefore it is an explicit finite difference approximation of Eq. (1). We can now consider using Eq. (9) to step forward from an initial condition (IC) required by Eq. (1). Here we take as the initial condition \[\tag{10} w(x,t=0)=Ae^{-(\mu/D)x}+B \]

    where \(A, B, \mu\) are constants to be specified. The finite difference form of Eq. (10) is \[\tag{11} w_i^0=Ae^{-(\mu/D)x_i}+B \]

    (note that \(k=0\) at \(t=0\)).

    We must also specify two boundary conditions (BCs) for Eq. (1) (since it is second order in \(x\)). We will use the Dirichlet BC at \(x=0\) \[\tag{12} w(x=0,t)=Ae^{-(\mu/D)(-\mu t)}+B \]

    for which the finite difference form is (note that \(i=1\) at \(x=0\)) \[\tag{13} w_1^k=Ae^{-(\mu/D)(-\mu t^k)}+B \]


    We use the Neumann BC at \(x=1\) \[\tag{14} \dfrac{\partial w(x=1,t)}{\partial x} = A (-\mu/D) e^{-(\mu/D)(1-\mu t)} \]

    for which the finite difference form is (note that \(i=N\) at \(x=1\)) \[\tag{15} w_{N+1}^k=w_{N-1}^k+2\Delta xAe^{-(\mu/D)(-\mu t^k)}+B \]

    where \(w_{N+1}\) is a fictitious value that is outside the interval \(0 \leq x \leq 1\ ;\) it can be used to eliminate \(w_{N}\) in Eq. (9) for \(i=N\ .\)

    Equations (9), (11), (13) and (15) constitute the full system of equations for the calculation of the numerical solution to Eq. (1). Note that we have replaced the original PDE, Eq. (1), with a set of approximating algebraic equations (Eqs. (9), (11), (13) and (15)) which can easily be programmed for a computer.

    Also, an analytical solution to Eq. (1) (see particular solutions to the heat equation) can be used to evaluate the numerical solution \[\tag{16} w(x,t)=Ae^{(1/D)(\mu^2 t \pm \mu x)}+B \]

    Equation (16) can be stated in the alternative form \[\tag{17} w(x,t)=Ae^{-(\mu/D)(x-\mu t)}+B \]

    which corresponds to a traveling wave solution since \(x\) and \(t\) appear in the combination \(x-\mu t\ .\)

    A short MATLAB program is listed in Appendix 1 based on Eqs. (9), (11), (13) and (15). Representative output from this program that compares the numerical solution from Eqs. (9), (11), (13) and (15) with the analytical solution, Eq. (17), indicates that the two solutions are in agreement to five figures, as reflected in Table 1.

    Table 1: Comparison of the numerical and analytical solutions at \(x = x_l/2 = 0.5\) produced by the program in Appendix 1; w, numerical solution from Eqs. (9), (11), (13) and (15); wa, analytical solution of Eq. (17)
     t = 0.05   w(x=xl/2,t) = 1.6376   wa(x=xl/2,t) = 1.6376 
     t = 0.10   w(x=xl/2,t) = 1.6703   wa(x=xl/2,t) = 1.6703 
     t = 0.15   w(x=xl/2,t) = 1.7047   wa(x=xl/2,t) = 1.7047 
     t = 0.20   w(x=xl/2,t) = 1.7408   wa(x=xl/2,t) = 1.7408 
     t = 0.25   w(x=xl/2,t) = 1.7788   wa(x=xl/2,t) = 1.7788 
     t = 0.30   w(x=xl/2,t) = 1.8187   wa(x=xl/2,t) = 1.8187 
     t = 0.35   w(x=xl/2,t) = 1.8607   wa(x=xl/2,t) = 1.8607 
     t = 0.40   w(x=xl/2,t) = 1.9048   wa(x=xl/2,t) = 1.9048 
     t = 0.45   w(x=xl/2,t) = 1.9512   wa(x=xl/2,t) = 1.9512 
     t = 0.50   w(x=xl/2,t) = 2.0000   wa(x=xl/2,t) = 2.0000 

    The parameters that produced the numerical output in Table 1 are listed in Table 2.

    Table 2: Numerical values of parameters used in the program of Appendix 1 that produced the output of Table 1
    Parameter Description Value
    \(D\) diffusivity in Eq. (1) 1
    \(\mu\), \(A\), \(B\) constants in Eqs. (10)-(17) 1, 1, 1
    \(N\), \(x_l\) number of grid points and length in \(x\) 21, 1
    \(h\), \(t_f\) grid spacing in \(t\), final value of \(t\) 0.001, 0.5

    Additional parameters follow from the values in Table 2. Thus, the grid spacing in \(x\) is \(\Delta x=1/(21-1)=0.05\ .\) The number of steps in \(t\) taken along the solution is \(0.5/0.001=500\ .\)

    Some of the parameters, particularly \(N\) and \(h\), were determined by trial and error to achieve a numerical solution of acceptable accuracy (e.g., five significant figures). We can note two additional points about these values:

    • Acceptable values of \(N\) and \(h\) could be determined by observing the errors in the numerical solution through comparison with the exact solution (Eq. (17)) as illustrated in Table 1. However, in most PDE applications, an analytical solution is not available for assessing the accuracy of the numerical solution, and in fact, the motivation for using a numerical method is generally to produce a solution when an analytical solution is not available. In this case (no analytical solution), a useful procedure for estimating the numerical accuracy is to compute solutions for two different values of \(N\) and compare the numerical values. If the two solutions do not agree to an acceptable level, a third solution is computed with a still larger \(N\) (smaller grid spacing in \(x\)) and again the solutions are compared. Eventually, if spatial convergence is achieved, successive solutions will agree to the required accuracy. In this case, the accuracy of the numerical solution is inferred, but the exact error is not computed (or even known) when an analytical solution is not available. The same reasoning can be applied for temporal convergence with respect to \(t\), i.e., \(h\) is reduced until the successive solutions agree to a specified level.
    • The preceding discussion was directed to achieving acceptable accuracy. Additionally, the values of \(N\) and \(h\) were selected to achieve a stable solution. The criterion for stability in the case of Eq. (9) (for parabolic PDE (1)) is \(\alpha = D\Delta t/\Delta x^2<1/2\ .\) For the solution of Table 1, \(\alpha=1\times0.001/0.05^2=0.4<0.5\ .\) If the critical value of the dimensionless parameter \(\alpha=0.5\) had been exceeded, the numerical solution would have become unstable (as manifest in numerical values of ever increasing magnitude). This conclusion can easily be confirmed by running the program of Appendix 1 for a choice of \(N\) and \(h\) for which \(\alpha>0.5\ .\) The stability constraint \(\alpha<0.5\) is a distinctive feature of the explicit finite difference approximation of Eq. (9). Thus, as \(\Delta x\) is reduced (\(N\) increased) to achieve better accuracy in the numerical solution, \(h\) must also be reduced to maintain stability (\(\alpha=Dh/\Delta x^2<0.5\)).

    Finally, some descriptive comments about the details of the program in Appendix 1 are given immediately after the program listing.

    Hyperbolic PDE

    We now consider a numerical solution to the one-dimensional hyperbolic wave equation \[\tag{18} \frac{\partial^2w}{\partial t^2}-\frac{\partial^2w}{\partial x^2}=0 \]

    We again have an analytical solution to evaluate the numerical solution. First, we include a velocity, \(c\), in the equation: \[\tag{19} \dfrac{\partial^2w}{\partial t^2} = c^2\dfrac{\partial^2w}{\partial x^2} \]

    Note that \(c\) has the MKS units of m/s as expected and as inferred from Eq. (19) (note the units of the derivatives in \(x\) and \(t\)).

    Since Eq. (19) is second order in \(x\) and \(t\), it requires two ICs and two BCs. We will take these as: \[\tag{20} w(x,t=0)=e^{-\lambda x^2} \]

    \[\tag{21} \dfrac{\partial w(x,\,t=0)}{\partial t}=0 \]

    \[\tag{22} w(x\to\infty,\,t)=0 \]

    \[\tag{23} w(x\to-\infty,\,t)=0 \]

    Equation (20) indicates the IC is a Gaussian pulse with the positive constant \(\lambda\) to be specified. Equation (21) indicates \(w(x,t)\) starts with zero "velocity". Equations (22)–(23) indicate that the solution \(w(x,t)\) does not depart from the initial value of zero specified by IC (20)–(21). In other words, \(\lambda\) is chosen large enough that the IC is effectively zero at \(x=\pm\infty\) and remains at this value for subsequent \(t\ .\)

    An important difference between the parabolic problem of Eq. (1) and the hyperbolic problem of Eq. (19) is that the former is first order in \(t\) while the latter is second order in \(t\ .\) Therefore, in order to develop a numerical method for Eq. (18) (or Eq. (19)), we need an algorithm that can accommodate second derivatives in \(t\ .\) While such algorithms do exist, they generally are not required. Rather, we can express a PDE second order in \(t\) as two PDEs first order in \(t\ .\) For example, Eq. (19) can be written as \[\tag{24} \dfrac{\partial w}{\partial t} = u \]

    \[\tag{25} \dfrac{\partial u}{\partial t} = c^2\dfrac{\partial^2w}{\partial x^2} \]

    Equations (24)–(25) are first order in \(t\), and therefore an integration algorithm for first order equations, such as the Euler method of Eq. (8), can be used to move \(w(x,t)\) and \(u(x,t)\) forward in \(t\ .\) Thus, the fully discretized form of Eqs. (24)–(25) can be written as \[\tag{26} w_i^{k+1}=w_i^k+hu_{i}^k \]

    \[\tag{27} u_{i}^{k+1}=u_{i}^k+hc^2\dfrac{w_{i+1}^k-2w_{i}^k+w_{i-1}^k}{\Delta x^2} \]


    ICs (20)–(21) become (with \(k=0\) corresponding to \(t=0\)) \[\tag{28} w_i^0=e^{-\lambda x_i^2} \]

    \[\tag{29} u_i^0=0 \]


    For BCs (22)–(23), the infinite interval \(-\infty\leq x\leq\infty\) must be replaced by a finite one \(-x_l\leq x\leq x_l\) (since computers can accommodate only finite numbers) where \(x_l\) is selected so that it is effectively infinite; that is, the solution \(w(x,t)\) does not depart from IC (20) at \(x=-x_l,x_l\) for \(t>0\ .\) The value of \(x_l\) and the corresponding number of grid points in \(x\), \(N\), are specified subsequently.

    The finite difference approximations of BCs (22)–(23) are \[\tag{30} w_1^k=0 \]

    \[\tag{31} w_N^k=0 \]

    Equations (26), (27), (28), (29), (30), (31) constitute the complete finite difference approximation of Eqs. (24), (25), (20), (21), (22), (23). A small MATLAB program for this approximation is given in Appendix 2, including some descriptive comments immediately after the program.

    The general analytical solution to Eq. (19) can be written as (see also here) \[\tag{32} w(x,t)={\textstyle\frac12}[\varphi(x+ct)+\psi(x-ct)] \]

    Let us take \(\varphi = \psi\) in the form of the Gaussian pulse of Eq. (20), i.e., \[\tag{33} w(x,t)={\textstyle\frac12}\bigl[e^{-\lambda(x+ct)^2}+e^{-\lambda(x-ct)^2}\bigr] \]


    Figure 1: Comparison of the numerical and analytical solutions for \(t=0,10,20,30\) produced by the program in Appendix 2; w, numerical solution from Eqs. (26), (27), (28), (29), (30), (31); wa, analytical solution of Eq. (33)

    The plotted output from the program is given in Figure 1 and includes both the numerical solution of Eqs. (26), (27), (28), (29), (30), (31) and the analytical solution of Eq. (33).

    We can note the following points about Figure 1:

    • The initial Gaussian pulse at \(t=0\) (centered at \(x=0\) with unit maximum value) splits into two pulses traveling left and right with velocity \(c=1\) and maximum value of 0.5 according to Eq. (33).
    • The pulses traveling left are centered at \(x=-10,-20,-30\) corresponding to \(t=10,20,30\) since \(c=1\ .\) The pulses traveling right are centered at \(x=10,20,30\) corresponding to \(t=10,20,30\ .\) These properties are characteristic of the traveling wave functions of Eq. (33) with arguments \(x+ct\) and \(x-ct\), respectively. In fact, the use of the word characteristic is particularly appropriate since the relations \(x+ct=\kappa\) and \(x-ct=\kappa\), where \(\kappa\) is a constant, are termed the characteristics of Eq. (19). Note that at the points along the solution given by these characteristics, the solution has a constant value. For example, for the peak values in Figure 1, \(\kappa=0\) and the solution is constant at the peak value 0.5 for \(x+ct=x-ct=0\ .\)
    • The solution remains at zero for \(x=x_l=50\) so that the interval \(-50\leq x\leq50\) is equivalent to the infinite interval \(-\infty\leq x\leq\infty\ .\)

    The parameters that produced the numerical output in Figure 1 are listed in Table 3.

    Table 3: Numerical values of parameters used in the program of Appendix 2 that produced the output of Figure 1
    Parameter Description Value
    \(c\) velocity in Eq. (19) 1
    \(\lambda\) constant in Eqs. (20), (28), (33) 0.05
    \(N\), \(x_l\) number of grid points and half length in \(x\) 201, 50
    \(h\), \(t_f\) grid spacing in \(t\), final value of \(t\) 0.0025, 30

    Additional parameters follow from the values in Table 3. Thus, the grid spacing in \(x\) is \(\Delta x=2\times50/(201-1)=0.5\ .\) The number of steps in \(t\) taken along the solution is \(30/0.0025=12000\), which is large, but was selected to achieve good accuracy in the numerical solution.

    To explore the accuracy of the numerical solution, we can consider the peak values of \(w(x,t)\) in Figure 1. This is a stringent test of the numerical solution since the curvature of the solution is greatest at these peaks. The results are summarized in Table 4.

    Table 4: Numerical values of \(w(x,t)\) at the peak values displayed in Figure 1
    \(t\) \(-x,\ x\) Peak values
    0 0 1
    10 -10, 10 0.5006, 0.5006
    20 -20, 20 0.5011, 0.5011
    30 -30, 30 0.5015, 0.5015

    Of course, the peak analytical values given by Eq. (33) are \(w(x=0,\,t=0)=1\ ,\) \(w(x=\pm t,\,t>0)=0.5\ .\) Table 4 indicates these peak values were attained within 0.5015 even for the largest value of \(t\ (=30)\) so that errors did not accumulate excessively as the solution progressed through \(t\ .\) These errors could be reduced by increasing the number of grid points in \(x\) above \(N=201\ .\) These errors could also presumably be reduced by using a more accurate (higher order) finite difference equation than the second order approximation of Eq. (5); to this end, MATLAB routines for second, fourth, sixth, eighth and tenth finite difference approximations are given in Hamdi, et al.

    This explicit finite difference numerical solution also has a stability limit (like the preceding parabolic problem). In this case \[\tag{34} c\Delta t/\!\Delta x<1 \]

    Stability constraint (34) is the Courant–Friedrichs–Lewy (or CFL) condition. For the present numerical solution, \(1\times0.0025/0.5=0.005\) so the CFL condition is easily satisfied. In other words, the parameters of Table 3 were chosen primarily for accuracy and not stability.

    Next, we consider an elliptic problem.

    Elliptic PDE

    The elliptic PDE (Laplace's equation) \[\tag{35} \dfrac{\partial^2 w}{\partial x^2}+\dfrac{\partial^2 w}{\partial y^2}=0 \]

    has two boundary value independent variables, \(x\) and \(y\), and no initial value variable. Thus, since the preceding numerical methods required an integration with respect to an initial value variable (\(t\)), and was accomplished by Euler's method, Eq. (8), we cannot develop a numerical solution for Eq. (35) directly using these methods. Rather, we will convert Eq. (35) from an elliptic problem to an associated parabolic problem by adding a derivative in an initial value variable. Thus, the PDE we will now consider is \[\tag{36} \dfrac{\partial w}{\partial t}=\dfrac{\partial^2 w}{\partial x^2}+\dfrac{\partial^2 w} {\partial y^2} \]

    The idea then is to integrate Eq. (36) forward in \(t\) until the numerical solution approaches the condition \(\frac{\partial w}{\partial t}\to 0\) so that Eq. (36) then reverts back to Eq. (35), i.e., the solution under this condition is for Eq. (35) as required.

    Equation (36) is first order in \(t\), and second order in \(x\) and \(y\ .\) It therefore requires one IC and two BCs (for \(x\) and \(y\)). For the IC, since \(t\) has been added to the problem only to provide a solution to Eq. (35) through Eq. (36), the choice of an IC is completely arbitrary (it is not part of the original problem). For the present analysis, we will use \[\tag{37} w(x,\,y,\,t=0)=\kappa \]

    where \(\kappa\) is a constant to be selected (logically, it should be in the neighborhood of the expected solution to Eq. (35), but it's precise value is not critical to the success of the numerical method).

    For the two BCs in \(x\), we will use homogeneous (zero) Dirichlet BCs \[\tag{38} w(x=0,\,y,\,t)=0 \]

    \[\tag{39} w(x=x_l,\,y,\,t)=0 \]

    where \(x_l\) is the upper boundary value of \(x\ .\)

    For the first BC in \(y\), we will use a homogeneous Neumann BC \[\tag{40} \dfrac{\partial w(x,\,y=0,\,t)}{\partial y}=0 \]


    For the second BC in \(y\), we will use a nonhomogeneous Neumann BC \[\tag{41} \dfrac{\partial w(x,\,y=y_l,\,t)}{\partial y} = \sin (\pi x)\,\pi \sinh (\pi y_l) \]

    where \(y_l\) is the upper boundary value of \(y\ .\) Note that \(\dfrac{\partial w(x,y=y_l)} {\partial y}\) in BC (41) is a function of \(x\ .\)

    The analytical solution to Eqs. (35) (note, not Eq. (36)), (38)–(41) is a special case of one of the solutions stated previously \[\tag{42} w(x,y) = \sin (\pi x)\cosh(\pi y) \]

    The analytical solution of Eq. (42) will be used to evaluate the numerical solution.

    To develop a numerical solution to Eq. (36), we first replace all of the derivatives with finite differences in analogy with the preceding numerical solutions. The positions in \(x\), \(y\) and \(t\) will be denoted with indices \(i\), \(j\) and \(k\), respectively. The corresponding increments are \(\Delta x\ ,\) \(\Delta y\) and \(h\ .\) Application of these ideas to Eq. (36) gives the finite difference approximation \[ w_{i,j}^{k+1}=w_{i,j}^{k}+h\left (\dfrac{w_{i+1,j}^k-2w_{i,j}^k+w_{i-1,j}^k}{\Delta x^2} +\dfrac{w_{i,j+1}^k-2w_{i,j}^k+w_{i,j-1}^k}{\Delta y^2} \right ) \] \[\tag{43} i=1,2,\dots,N_x;\quad j=1,2,\dots,N_y;\quad k=1,2,\dots \]


    BCs (38)–(39) in the difference notation are \[\tag{44} w_{1,j}^k = 0 \]

    \[\tag{45} w_{N_x,j}^k = 0 \]


    BC (40) in difference notation is \[\tag{46} w_{i,0}^k = w_{i,2}^k \]

    where \( w_{i,0}^k\) is a fictitious value that can be used in Eq. (43) for \(j=1\ .\)

    BC (41) in difference notation is \[\tag{47} w_{i,N_y+1}^k = w_{i,N_y-1}^k+2\,\Delta y\sin (\pi x_i)\,\pi \sinh (\pi y_{N_y}) \]

    where \( w_{i,N_y+1}^k\) is a fictitious value that can be used in Eq. (43) for \(j=N_y\ .\)

    A short MATLAB program for Eqs. (43), (44), (45), (46) and (47) is listed in Appendix 3, followed by some explanatory comments. The output from this program is listed in Table 5.

    Table 5: Numerical values of \(w(x=x_l/2,\,y=y_l/2,\,t)\) from the program in Appendix 3
    \(t\) \(w(x_l/2,\,y_l/2,\,t)\)
    0.10 1.6254
    0.20 2.1785
    0.30 2.3883
    0.40 2.4664
    0.50 2.4956
    0.60 2.5064
    0.70 2.5105
    0.80 2.5120
    0.90 2.5125
    1.00 2.5127

    The midpoint values \(w(x=x_l/2,\,y=y_l/2,\,t)\) are listed in Table 5. The convergence of the solution of Eq. (36) to that of Eq. (35) is apparent, e.g., at \(t=1\ ,\) \(w(x=x_l/2,\,y=y_l/2,\,t)=2.5127\) while the value from the analytical solution, Eq. (42), is \(w_a(x=x_l/2,\,y=y_l/2)=2.5092\ ;\) the difference is \((2.5127-2.5092)/2.5092 \times 100 =0.14\%\ .\) Of course, the agreement will not be perfect because of the approximations used in Eqs. (43), (44), (45), (46) and (47). The parameters that produced the numerical output in Table 5 are listed in Table 6.

    Table 6: Numerical values of parameters used in the program of Appendix 3 that produced the output of Table 5
    Parameter Description Value
    \(N_x\), \(x_l\) number of grid points and half length in \(x\) 21, 1
    \(N_y\), \(y_l\) number of grid points and half length in \(y\) 21, 1
    \(h\), \(t_f\) grid spacing in \(t\), final value of \(t\) 0.0005, 1

    Additional parameters follow from the values in Table 6. Thus, the grid spacing in \(x\) is \(\Delta x = 1/(21-1) = 0.05\ .\) Similarly the spacing in \(y\) is \(\Delta y = 0.05\ .\) The spacing in \(x\) and \(y\) could be different if the variation of the solution \(u(x,y,t)\) in one direction is substantially greater than in the other; in other words, some tuning of the 2D grid in \(x\) and \(y\) could be required. The number of steps in \(t\) taken along the solution is \(1/0.0005 = 2000\), which is large, but was selected to achieve good accuracy in the numerical solution.

    The stability constraint for the 2D problem of Eq. (36) (with a constant \(D\) multiplying the derivatives in \(x\) and \(y\)) is \[ D\left (\dfrac{1}{\Delta x^2}+\dfrac{1}{\Delta y^2}\right )h < \dfrac12 \] For the preceding solution, \(1\times(1/0.05^2 + 1/0.05^2)\times0.0005=0.4\) which meets the stability constraint.

    The procedure of adding a derivative in \(t\) to elliptic Eq. (35), then solving the resulting parabolic problem, Eq. (36), is termed the method of false transients or the method of pseudo transients to suggest that the parabolic problem appears to have a transient phase that is not part of the original elliptic problem. The actual path that the parabolic problem takes to the solution of the elliptic problem is not relevant so long as the parabolic solution converges to the elliptic solution. In the present case, \(\kappa\) in IC (37) was taken as 1. Some other trial values indicated that this initial value is not critical (but it should be as close to the final value, for example 2.5092, as knowledge about the final value can provide).

    Also, \(t\) can be considered a parameter in the solution of Eq. (36). This parametrization is an example of continuation in which the solution is continued from the given (assumed) starting value of Eq. (37) to the final value of 2.5127. The concept of continuation has been applied in many forms (and not just through the addition of a derivative as in Eq. (36)).

    In general, the errors in the numerical solution of PDEs can result from the limited accuracy of all of the approximations used in the calculation. For example, the 0.14% error in the preceding solution can result from the discretization errors in \(x\), \(y\) and \(t\) in Eqs. (43), (44), (45), (46) and (47). In formulating a numerical method or algorithm for the solution of a PDE problem, it is necessary to balance the discretization errors so that one source of error does not dominate, and generally degrade, the numerical solution. This might, for example, require the choice of balanced values for \(N_x\), \(N_y\) and \(h\ .\) The effect of the numbers of discretization points generally can be inferred by varying these numbers and observing the effect on the numerical solution.

    Remarks

    Thus, control of approximation errors is central to the calculation of a numerical solution of acceptable accuracy. In the preceding examples, this control of errors can be accomplished in three ways:

    1. The number of grid points can be varied. Since in the numerical analysis literature, the grid spacing is often given the symbol \(h\) (as in Eq. (8)), systematic variation of the grid spacing to investigate accuracy is usually termed h refinement.
    2. The order of the approximation can be varied. For example, Euler's method of Eq. (8) is \(O(h^2)\) (second order correct) for one step or \(O(h)\) (first order correct) for a series of steps over a complete solution. In general, if the approximation is of order \(O(h^p)\), it is termed \(p\)th order. The symbol \(p\) is frequently used in the numerical analysis literature, and varying the order \(p\) to investigate accuracy is referred to as p refinement.
    3. The discretization errors can possibly be estimated and where the error is considered too large, the numerical algorithm can automatically insert grid points. Beyond that, the grid spacing does not have to be uniform, e.g., \(h\) in Eq. (8) does not have to remain constant throughout the numerical solution, and the numerical algorithm can automatically vary the spacing to concentrate the grid points where they are needed to achieve acceptable accuracy. This form of refinement is termed usually r refinement; we mention r refinement only to initiate possible interest in more advanced numerical methods.

    The three preceding numerical solutions were developed using basic finite differences such as in Eqs. (5) and (8). However, many approaches to approximating derivatives in PDEs have been developed and used. Among these are finite elements, finite volumes, weighted residuals, e.g., collocation, Galerkin and spectral methods. Each of these methods has advantages and disadvantages, often according to the characteristics of the problem of interest (starting with the parabolic, hyperbolic and elliptic geometric classifications). Thus, an extensive literature for the numerical solution of PDEs is available, and we have only presented here a few basic concepts and examples.

    The principal advantage of numerical methods applied to PDEs is that, in principle, PDEs of any number and complexity can be solved which is particularly useful when analytical solutions are not available. To illustrate how this might be done, the heat conduction equation with a nonlinear source term \(f(w)\) can easily be programmed by extending Eq. (9) to \[\tag{48} w_i^{k+1}=w_i^k+h\left [D\dfrac{w_{i+1}^k-2w_{i}^k+w_{i-1}^k}{\Delta x^2}+f(w_i^k)\right ] \]

    where \(f(w)\) could be a MATLAB function to compute the nonlinearity in \(w(x,t)\ .\) Alternatively, the nonlinearity could be programmed directly in Eq. (48). For example, for a second order reaction, \[\tag{49} w_i^{k+1}=w_i^k+h\left[ D\dfrac{w_{i+1}^k-2w_{i}^k+w_{i-1}^k}{\Delta x^2}+(w_i^k)^2\right] \]

    Note in particular how easily the nonlinearity is programmed.

    As another example, a solution to the Burgers equation could be computed by extending Eq. (9) (with \(D = 1\)) to \[\tag{50} w_i^{k+1}=w_i^k+h\left [\dfrac{w_{i+1}^k-2w_{i}^k+w_{i-1}^k}{\Delta x^2}- w_i^k\dfrac{w_{i+1}^k-w_{i-1}^k}{2\,\Delta x}\right ] \]

    where we have used the second order central finite difference approximation \[ \dfrac{\partial w}{\partial x}\approx\dfrac{w_{i+1}^k-w_{i-1}^k}{2\,\Delta x} \] Again, the nonlinear term in the Burgers equation is easily programmed as \[ w\dfrac{\partial w}{\partial x}\approx w_i^k\dfrac{w_{i+1}^k-w_{i-1}^k}{2\,\Delta x} \]

    Finally, to conclude this introductory discussion of the numerical solution of PDEs, we used in the various examples integration with respect to an initial value variable, \(t\), by using the Euler method of Eq. (8). While Euler's method is general with respect to the form of the initial value integration, it does have two important limitations:

    • The accuracy is first order (\(O(h)\)) and is therefore exact only for functions that vary linearly in \(t\ ;\) for higher order variations in \(t\), it is only approximate and generally requires a small \(h\) to achieve acceptable accuracy. One way around this accuracy limitation is to use a higher order integration algorithm in \(t\) such as the Runge-Kutta method (e.g., see the article by Shampine et al).
    • Stability limits the step \(h\), such as in the stability constraint for Eq. (9), \(\alpha = D\Delta t/\Delta x^2 < 1/2\ .\) Such stability constraints for explicit integration methods such as Eq. (8) can be circumvented by using an implicit integration method, often termed a stiff method. We will not pursue various types of initial value integration methods here, but additional information is available (Shampine et al).

    Thus, the Euler method is limited by both accuracy and stability. To circumvent these constraints, initial value integrators are used which are higher order (for improved accuracy) and stable (to provide a larger stable step \(h\) that may actually be unlimited, depending on the integrator and the application). As might be expected, such higher order methods are more complicated than the Euler method, but fortunately, they have been programmed in library routines that can easily be called and used. As an example, the MATLAB integrator ode15s has the following features:

    • Good stability (it is a stiff integrator). The enhanced stability is achieved through implicit integration that requires the solution of algebraic equations at each step along the solution (each step of length \(h\)). An option for ode15s in the solution of the algebraic equations is the use of sparse matrix methods that are very efficient for large algebraic systems.
    • Variable step and order, so that it automatically performs \(h\) and \(p\) refinement as the solution evolves.
    • Library routines such as ode15s are written by experts who have included features that make them robust and reliable. Further, these routines have been used extensively and are therefore thoroughly tested.

    The use of library routines for initial value integration is the basis for much of the work in the numerical method of lines solution of PDEs. This approach has been applied to a broad spectrum of PDE problems in 1D, 2D and 3D, including all of the major classes of PDEs (e.g., parabolic, hyperbolic and elliptic) in various orthogonal coordinate systems (e.g., Cartesian, cylindrical and spherical). The use of quality library routines provides an important step in the timely development of computer codes for new applications of PDEs whereby the analyst can take advantage of the work of experts, which is generally much more efficient and reliable than developing codes starting with just a general programming language.

    Appendix 1. MATLAB program for a parabolic PDE

    The MATLAB program that produced the results described in the Parabolic PDE for equation (1) follows.

     clear all; clc
     D=1; mu=1; A=1; B=1;
     nx=21; xl=1; dx=0.05; x=[0:0.05:xl]; nx2=11;
     nt=50; nout=10; h=0.001; t=0;
     for i=1:nx; w(i)=A*exp(1/D*(mu^2*t-mu*x(i)))+B; end
     for i1=1:nout
       for i2=1:nt
         for i=1:nx
           if(i==1)w(1)=A*exp(1/D*(mu^2*t-mu*x(1)))+B; wt(1)=0;
           elseif(i==nx)wf=w(nx-1)+(2*dx)*A*(-mu/D)*exp(1/D*(mu^2*t-mu*x(nx)));
                        wt(nx)=D*(wf-2*w(nx)+w(nx-1))/dx^2;
           else wt(i)=D*(w(i+1)-2*w(i)+w(i-1))/dx^2; end
         end
         w=w+wt*h; t=t+h;
       end
       fprintf('t = %4.2f   w(x=xl/2,t) = %6.4f   wa(x=xl/2,t) = %6.4f\n', ...
               t, w(nx2), A*exp(1/D*(mu^2*t-mu*x(nx2)))+B);
     end
    

    Listing 1: MATLAB program for the numerical solution of Eqs. (1), (10), (12), and (14)

    We can note the following points about this program:

    • Any previous files are first cleared. Then the parameters for the numerical solution of Eq. (1) are defined numerically as in Table 2. Note that a grid in \(x\) is set up as \(x=0,\,0.05,\,0.10,\,\dots,\,1\ .\)

     clear all; clc
     D=1; mu=1; A=1; B=1;
     nx=21; xl=1; dx=0.05; x=[0:0.05:xl]; nx2=11;
     nt=50; nout=10; h=0.001; t=0;
    

    • IC (11) is then implemented in a for loop (note that t=0).

     for i=1:nx; w(i)=A*exp(1/D*(mu^2*t-mu*x(i)))+B; end
    

    • Three nested for loops step Eq. (9) through \(x\) and \(t\)

     for i1=1:nout
       for i2=1:nt
         for i=1:nx
    

    Specifically, the outer loop (in it) gives the nout = 10 outputs in Table 1. Within each output interval (0.05), 50 steps in \(t\) are taken by the loop in i2 (in this way, the 500 steps in \(t\) produce outputs at only 10 points as displayed in Table 1). Within the loop in i, \(x\) spans the interval \(0\leq x\leq 1\ .\)

    • BC (13) is programmed (at i=1) as

           if(i==1)w(1)=A*exp(1/D*(mu^2*t-mu*x(1)))+B; wt(1)=0;
    

    Also, since \(w(x=0,t)\) is specified by BC (12), the \(t\) derivative of this boundary value is set to zero so that the integration in \(t\) at \(x=0\) does not move \(w(x=0,t)\) from its prescribed value, i.e., wt(1)=0;).

    • BC (15) is used to calculate the fictitious point wf which is then used in the finite difference calculation of Eq. (6).

           elseif(i==nx)wf=w(nx-1)+(2*dx)*A*(-mu/D)*exp(1/D*(mu^2*t-mu*x(nx)));
                        wt(nx)=D*(wf-2*w(nx)+w(nx-1))/dx^2;
    

    • For the interior points in \(x\) (\(x \neq 0, 1\)), Eq. (6) is programmed.

           else wt(i)=D*(w(i+1)-2*w(i)+w(i-1))/dx^2; end
         end
    

    The second end terminates the inner loop in i, so that all of the values of \(x\) are handled.

    • Euler's method, Eq. (8), is then used to advance the solution through nt=50 steps of length \(h=0.001\) through the intermediate for loop in i2.

         w=w+wt*h; t=t+h;
       end
    

    Note the use of the matrix facility of MATLAB (w and wt are vectors of length nx = 21). The end completes the intermediate loop in i2.

    • The numerical solution is displayed to produce the output in Table 1, including the analytical solution of Eq. (16)

       fprintf('t = %4.2f   w(x=xl/2,t) = %6.4f   wa(x=xl/2,t) = %6.4f\n', ...
               t, w(nx2), A*exp(1/D*(mu^2*t-mu*x(nx2)))+B);
     end
    

    The end terminates the outer loop in i1.

    Appendix 2. MATLAB program for a hyperbolic PDE

    The MATLAB program that produced the results described in the Hyperbolic PDE section for equation (18) (and Eq. (19)) follows.

     clear all; clc
     c=1;
     nx=201; xl=50; dx=0.5; x=[-xl:dx:xl];
     nt=4000; nout=3; h=0.0025; t=0;
     for i=1:nx; w(i)=exp(-0.05*x(i)^2); wt(i)=0; ...
                 wplot(1,i)=w(i); waplot(1,i)=exp(-0.05*x(i)^2); end
     for i1=1:nout
       for i2=1:nt
         for i=1:nx
           if(i==1)     w( 1)=0; wt( 1)=0; wtt( 1)=0;
           elseif(i==nx)w(nx)=0; wt(nx)=0; wtt(nx)=0;
           else wtt(i)=c^2*(w(i+1)-2*w(i)+w(i-1))/dx^2; end
         end
         w=w+wt*h; wt=wt+wtt*h; t=t+h;
       end
     for i=1:nx
       wplot (i1+1,i)=w(i);
       waplot(i1+1,i)=0.5*(exp(-0.05*(x(i)-t)^2)+exp(-0.05*(x(i)+t)^2));
       fprintf('\n %6.2f %6.2f,%8.4f %8.4f',t, x(i),wplot(i1+1,i),waplot(i1+1,i));
     end
     end
     plot(x,wplot,'-',x,waplot,'o'); xlabel('x'); ylabel('w(x,t)');
     title('w(x,t), t=0,10,20,30, solid - num, o - anal')
    

    Listing 2: MATLAB program for the numerical solution of Eqs. (19), (20)–(23)

    We can note the following points about this program:

    • Any previous files are first cleared. Then the parameters for the numerical solution of Eq. (18) (or Eq. (19)) are defined numerically as in Table 3. Note that a grid in \(x\) is set up as \(x=-50,-49.5,\dots,50\), a total of 201 points. The choice of the upper and lower limits for \(x\), was made so that domain in \(x\) is essentially infinite (it accommodates BCs (22)–(23), (30)–(31) as discussed subsequently).

     clear all; clc
     c=1;
     nx=201; xl=50; dx=0.5; x=[-xl:dx:xl];
     nt=4000; nout=3; h=0.0025; t=0;
    

    • ICs (20)–(21), or (28)–(29), are then implemented in a for loop (note that t=0).

     for i=1:nx; w(i)=exp(-0.05*x(i)^2); wt(i)=0; ...
                 wplot(1,i)=w(i); waplot(1,i)=exp(-0.05*x(i)^2); end
    

    Both \(w(x,t)\) and \(\dfrac{\partial w(x,t)}{\partial t}\) are programmed (as w and wt) which is required since Eq. (19) is second order in \(t\) (as explained subsequently). Also, the initial value of \(w(x,t=0)\), both numerical and analytical, is stored for subsequent plotting (so that the plot will include IC (20)).

    • Three nested for loops step Eqs. (26) and (27) through \(x\) and \(t\)

     for i1=1:nout
       for i2=1:nt
         for i=1:nx
    

    Specifically, the outer loop (in it) gives the nout = 3 outputs in Table 3. Within each output interval (1), 4000 steps in \(t\) are taken by the loop in i2 (in this way, the 4000 steps in \(t\) produce outputs at only 3 points as displayed in Figure 1). Within the loop in i, \(x\) spans the interval \(-50\leq x\leq 50\ .\)

    • BCs (22)–(23), or (30)–(31), are programmed (at i=1 and i=nx corresponding to \(x=\pm\infty\)) as

           if(i==1)     w( 1)=0; wt( 1)=0; wtt( 1)=0;
           elseif(i==nx)w(nx)=0; wt(nx)=0; wtt(nx)=0;
    

    Also, since \(w\) is specified by BCs (22)–(23), the first and second derivatives in \(t\) of these boundary values are set to zero so that the integration in \(t\) does not move \(w\) from its zero values.

    • For the interior points in \(x\) (\(x \neq -50, 50\)), Eq. (25) (discretized in \(x\)) is programmed.

           else wtt(i)=c^2*(w(i+1)-2*w(i)+w(i-1))/dx^2; end
         end
    

    The second end terminates the inner loop in i, so that all of the values of \(x\) are handled.

    • Euler's method (Eq. (8)) is then used to advance the solution through nt=4000 steps of length \(h=0.0025\) through the intermediate for loop in i2 according to Eqs. (26) and (27).

        w=w+wt*h; wt=wt+wtt*h; t=t+h;
       end
    

    Note the use of the matrix facility of MATLAB (w, wt and wtt are vectors of length nx = 201). The end completes the intermediate loop in i2.

    • The numerical and analytical solutions are then stored at \(t=10,20,30\) (three passes through the outer loop in i1) followed by plotting (of Figure 1).

     for i=1:nx
       wplot (i1+1,i)=w(i);
       waplot(i1+1,i)=0.5*(exp(-0.05*(x(i)-t)^2)+exp(-0.05*(x(i)+t)^2));
       fprintf('\n %6.2f %6.2f,%8.4f %8.4f',t, x(i),wplot(i1+1,i),waplot(i1+1,i));
     end
     end
     plot(x,wplot,'-',x,waplot,'o'); xlabel('x'); ylabel('w(x,t)');
     title('w(x,t), t=0,10,20,30, solid - num, o - anal')
    

    The final end terminates the outer loop in i1. Also, as a word of caution, the fprintf statement displays the complete numerical solution at \(t=10,20,30\) so that the numerical solution can be examined in detail (the peak values reported in Table 4 were taken from this output); if the program in Listing 2 is executed, the fprintf statement could be converted to a comment to reduce the numerical output.

    Appendix 3. MATLAB program for an elliptic PDE

    The MATLAB program that produced the results described in the Elliptic PDE section for equation (35) follows.

     clear all; clc
     nx=21; xl=1; dx=0.05; x=[0:0.05:xl]; nx2=11; mu=pi/xl;
     ny=21; yl=1; dy=0.05; y=[0:0.05:yl]; ny2=11;
     nt=200; nout=10; h=0.0005; t=0;
     w=ones(nx,ny);
     for i1=1:nout
       for i2=1:nt
         for i=1:nx
           for j=1:ny
             if(i== 1)      w( 1,j)=0; wt( 1,j)=0;
               elseif(i==nx)w(nx,j)=0; wt(nx,j)=0;
               elseif(j== 1)wt( i,1)=(w(i+1,j)-2*w(i,j)+w(i-1,j))/dx^2 ...
                                    +2*(w(i,2)-w(i,1))/dy^2;
               elseif(j==ny)wf=w(i,ny-1)+2*dy*mu*sin(mu*x(i))*sinh(mu*y(ny));
                            wt(i,ny)=(w(i+1,ny)-2*w(i,ny)+w(i-1,ny))/dx^2 ...
                                    +(wf-2*w(i,ny)+w(i,ny-1))/dy^2;
               else wt(i,j)=(w(i+1,j)-2*w(i,j)+w(i-1,j))/dx^2 ...
                           +(w(i,j+1)-2*w(i,j)+w(i,j-1))/dy^2;
             end
           end
         end
         w=w+wt*h;
         t=t+h;
       end
       fprintf('t = %5.2f   w(xl/2,yl/2,t) = %7.4f \n',t,w(nx2,ny2))
     end
     fprintf('\n wa(xl/2,yl/2) = %7.4f\n',sin(mu*x(nx2))*cosh(mu*y(ny2)));
    

    Listing 3: MATLAB program for the numerical solution of Eqs. (36)–(41)

    We can note the following points about this program:

    • Any previous files are first cleared. Then the parameters for the numerical solution of Eq. (36) are defined numerically as in Table 6. Note grids in \(x\) and \(y\) are set up as \(x=0,0.05,0.10,\dots,1\), \(y=0,0.05,0.10,\dots,1\ .\)

     clear all; clc
     nx=21; xl=1; dx=0.05; x=[0:0.05:xl]; nx2=11; mu=pi/xl;
     ny=21; yl=1; dy=0.05; y=[0:0.05:yl]; ny2=11;
     nt=200; nout=10; h=0.0005; t=0;
    

    • IC (37) is then implemented as

     w=ones(nx,ny);
    

    \(k=1\) in Eq. (37) is programmed with the MATLAB utility ones over the entire grid in \(x\) and \(y\), a total of nx\(\,\times\,\)ny points.

    • Four nested for loops step Eq. (43) through \(x\), \(y\) and \(t\)

     for i1=1:nout
       for i2=1:nt
         for i=1:nx
           for j=1:ny
    

    Specifically, the outer loop (in it) gives the nout = 10 outputs in Table 5. Within each output interval (0.0005), 200 steps in \(t\) are taken by the loop in i2 (in this way, the 2000 steps in \(t\) produce outputs at only 10 points as displayed in Table 5). Within the loop in i, \(x\) spans the interval \(0\leq x\leq 1\) and within the loop in j, \(y\) spans the interval \(0\leq y\leq 1\ .\)

    • BC (38) is programmed (at i=1 for j=1 to j=ny) as

             if(i== 1)      w( 1,j)=0; wt( 1,j)=0;
    

    Also, since \(w(x=0,y,t)\) is specified by BC (38), the \(t\) derivative of this boundary value is set to zero so that the integration in \(t\) at \(x=0\) does not move \(w(x=0,y,t)\) from its prescribed value, i.e., wt(1,j)=0;).

    • BC (39) is programmed (at i=nx for j=1 to j=ny) as

               elseif(i==nx)w(nx,j)=0; wt(nx,j)=0;
    

    • Equation (43) (with subsequent application of Euler's method) is programmed using BC (40) (at i=1 to i=nx for j=1) as

              elseif(j== 1)wt( i,1)=(w(i+1,j)-2*w(i,j)+w(i-1,j))/dx^2 ...
                                   +2*(w(i,2)-w(i,1))/dy^2;
    

    Note that we have used a finite difference approximation of Eq. (40), w(i,0) = w(i,2), to eliminate the fictitious value w(i,0) in Eq. (43).

    • Equation (43) (with subsequent application of Euler's method) is programmed using BC (41) (at i=1 to i=nx for j=ny) as

              elseif(j==ny)wf=w(i,ny-1)+2*dy*mu*sin(mu*x(i))*sinh(mu*y(ny));
                            wt(i,ny)=(w(i+1,ny)-2*w(i,ny)+w(i-1,ny))/dx^2 ...
                                    +(wf-2*w(i,ny)+w(i,ny-1))/dy^2;
    

    Note that we have used a finite difference approximation of Eq. (41) to eliminate the fictitious value w(i,ny+1)=wf in Eq. (43).

    • For the interior points in \(x\) (\(x \neq 0, 1\)) and \(y\) (\(x \neq 0, 1\)), Eq. (43) (with subsequent application of Euler's method) is programmed.

               else wt(i,j)=(w(i+1,j)-2*w(i,j)+w(i-1,j))/dx^2 ...
                           +(w(i,j+1)-2*w(i,j)+w(i,j-1))/dy^2;
             end
           end
         end
    

    The second and third end statements terminate the inner loops in i and j, so that all of the values of \(x\) and \(y\) are handled.

    • Euler's method (Eq. (8)) is then used to advance the solution through nt=200 steps of length \(h=0.0005\) through the intermediate for loop in i2.

         w=w+wt*h;
         t=t+h;
       end
    

    Note the use of the matrix facility of MATLAB (w and wt are arrays of dimensions nx = 21, ny = 21). The end completes the intermediate loop in i2.

    • The numerical solution is displayed to produce the output in Table 5.

       fprintf('t = %5.2f   w(xl/2,yl/2,t) = %7.4f \n',t,w(nx2,ny2))
     end
    

    The end terminates the outer loop in i1.

    • The analytical solution, Eq. (42), is then printed at the end (as reflected in Table 5).

     fprintf('\n wa(xl/2,yl/2) = %7.4f\n',sin(mu*x(nx2))*cosh(mu*y(ny2)));
    

    The programs in Listings 1, 2 and 3 have an essential feature that should be pointed out: only the operations of storing and retrieving numbers, arithmetic and looping are used (which are done naturally and very efficiently by computers). In other words, the integration of the three PDEs was not done by the usual analytical mathematics, but rather, was done essentially with arithmetic. This is the essence of the numerical method, that is, to replace mathematics of differentiation and integration with something much simpler, but performed naturally by computers with extraordinary speed and precision. This simplification was accomplished by replacing the partial derivatives in the PDEs with algebraic approximations, in this case, finite differences.

    A central question then is how accurate the numerical solution is if approximations are used to compute it. We have observed the accuracy can be improved with more calculations (e.g., by reducing \(\Delta x\), \(\Delta y\) and \(h\)). In other words there is a tradeoff between accuracy and calculations, and we basically assume the computer can do enough calculations to achieve the required accuracy. Historically, the increasing speed of computers has produced solutions to PDE problems with acceptable accuracy and continually increasing complexity. Thus, for the future, we can expect to compute numerical solutions of PDEs with essentially unlimited complexity if sufficient computing power is available.

    Personal tools
    Namespaces

    Variants
    Actions
    Navigation
    Focal areas
    Activity
    Tools