partial diff with scilab.pdf

Upload: afiqjenoba

Post on 02-Jun-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 partial diff with scilab.pdf

    1/49

    Partial Differential Equations withSCILAB

    By

    Gilberto E. Urroz, Ph.D., P.E.

    Distributed by

    infoClear inghouse.com

    2001 Gilberto E. UrrozAll Rights Reserved

  • 8/10/2019 partial diff with scilab.pdf

    2/49

    A "zip" file containing all of the programs in this document (and otherSCILAB documents at InfoClearinghouse.com) can be downloaded at the

    following site:

    http://www.engineering.usu.edu/cee/faculty/gurro/Software_Calculators/Scilab_Docs/ScilabBookFunctions.zip

    The author's SCILAB web page can be accessed at:

    http://www.engineering.usu.edu/cee/faculty/gurro/Scilab.html

    Please report any errors in this document to: [email protected]

    http://www.engineering.usu.edu/cee/faculty/gurro/Software_Calculators/Scilab_Docs/ScilabBookFunctions.ziphttp://www.engineering.usu.edu/cee/faculty/gurro/Software_Calculators/Scilab_Docs/ScilabBookFunctions.ziphttp://www.engineering.usu.edu/cee/faculty/gurro/Software_Calculators/Scilab_Docs/ScilabBookFunctions.ziphttp://www.engineering.usu.edu/cee/faculty/gurro/Scilab.htmlhttp://www.engineering.usu.edu/cee/faculty/gurro/Scilab.htmlmailto:[email protected]:[email protected]:[email protected]://www.engineering.usu.edu/cee/faculty/gurro/Scilab.htmlhttp://www.engineering.usu.edu/cee/faculty/gurro/Software_Calculators/Scilab_Docs/ScilabBookFunctions.ziphttp://www.engineering.usu.edu/cee/faculty/gurro/Software_Calculators/Scilab_Docs/ScilabBookFunctions.zip
  • 8/10/2019 partial diff with scilab.pdf

    3/49

    Download at InfoClearinghouse.com 1 2001 Gilberto E. Urroz

    PARTIAL DIFFERENTIAL EQUATIONS 2

    DDeeffiinniittiioonnss 2

    CCllaassssiiffiiccaattiioonnoofflliinneeaarr,,sseeccoonndd--oorrddeerrPPDDEEss 3

    Analytical solutions of PDEs 3Analytical solutions to parabolic equations: one-dimensional solution of the heat equation 3Analytical solutions to parabolic equations: One-dimensional solution of the waveequation 9Analytical solutions to hyperbolic equations: Two-dimensional solution to Laplace'sequation in a rectangular domain. 13

    More solutions to Laplace equation in a rectangular domain 17Superposition of solutions for cases [1] and [2] 21Laplacian in polar-cylindrical coordinates 24Solution to Laplace's equation in an annulus 24Solution to the Laplace equation in a disk 28

    Numerical solutions to partial differential equations 32

    Numerical solution to parabolic PDEs: heat equation 32A function for the explicit numerical solution of the heat equation 33Numerical solution to hyperbolic PDEs: the wave equation 35A function for the solution of the wave equation 36Numerical solution to elliptic PDEs: Laplace equation 38A function to solve Laplace equation in a rectangular domain 40

    Exercises 42

  • 8/10/2019 partial diff with scilab.pdf

    4/49

    Download at InfoClearinghouse.com 2 2001 Gilberto E. Urroz

    Partial Differential EquationsThis chapter introduces basic concepts and definitions for partial differential equations (PDEs)and solutions to a variety of PDEs. Applications of the method of separation of variables arepresented for the solution of second-order PDEs. The application of this method involves the

    use of Fourier series that were introduced in Chapter 13. This chapter also presents numericalsolutions to simple second-order PDEs that describe physical systems. The aim of the chapteris to demonstrate SCILAB applications in the solution of well-known PDEs from mathematicalphysics, rather than being a comprehensive presentation on partial differential equations.

    DDeeffiinniittiioonnss

    Equations involving one or more partial derivatives of a function of two or moreindependent variables are calledpartial differential equations (PDEs).

    Well known examples of PDEs are the following equations of mathematical physics in

    which the notation: u =u/

    x, u

    xy=u/

    yx, u

    xx=

    2u/x2, etc., is used:

    [1] One-dimensional wave equation: utt = c2uxx

    [2] One-dimensional heat equation: ut = c2uxx

    [3] Laplace equation: uxx+uyy= 0,(2-D), or uxx+uyy+uzz= 0(3-D)

    [4] Poisson equation: uxx+uyy= f(x,y ),(2-D), or uxx+uyy+uzz= f(x,y,z) (3-D)

    The order of the highest derivative is the order of the equation. For example, all ofthe PDEs in the examples shown above are of the second order.

    A PDE is linearif the dependent variable and its functions are all of first order. All ofthe PDEs shown above are also linear.

    A PDE is homogeneous if each term in the equation contains either the dependentvariable or one of its derivatives. Otherwise, the equation is said to be non-homogeneous.Equations [1], [2], and [3] above are homogeneous equations. Equation [4] is non-homogeneous.

    A solution of a PDE in some region R of the space of independent variables is afunction, which has all the derivatives that appear on the equation, and satisfies theequation everywhere in R. For example, u = x2 y2, u = excos(y), and u = ln(x2+y2), are allsolutions to the two-dimensional Laplace equation (equation [3] above).

    In general there should be as many boundary or initial conditions as the highest orderof the corresponding partial derivative. For example, the one dimensional heat equation(equation [2]) applied to a insulated bar of length L, will require an initial condition, say

    u(x,t=0) = f(x),0 < x < L,

    as well as two boundary conditions, e.g., u(x=0,t) = u0and u(x=L,t) = uL, or, ux(x=0,t) = ux0and ux(x=L) = uxL, or some combination of these, for t >0.

  • 8/10/2019 partial diff with scilab.pdf

    5/49

    Download at InfoClearinghouse.com 3 2001 Gilberto E. Urroz

    CCllaassssiiffiiccaattiioonnoofflliinneeaarr,,sseeccoonndd--oorrddeerrPPDDEEss

    Linear, second-order PDEs, as the examples shown above as equations [1] through [4], arecommonly encountered in science and engineering applications. For that reason specialattention is paid in this section to this type of equations. First, we learn how to classify linear,

    second-order PDEs as follows:

    An equation of the form:Auxx+ 2Bux+ Cuyy= F(x,y,u,ux,uy),

    is said to be:

    elliptic, ifAC B2>0, e.g., heat flow and diffusion-type problems.

    parabolic, ifAC B2= 0, e.g., vibrating systems and wave motion problems.

    hyperbolic, ifAC B2< 0, e.g., steady-state, potential-type problems.

    Analytical solutions of PDEs

    There are a variety of methods for obtaining symbolic, or closed-form, solutions to differentialequations. The method of separation of variables can be used to obtain analytical solutionsfor some simple PDEs. The method consists in writing the general solution as the product offunctions of a single variable, then replacing the resulting function into the PDE, andseparating the PDE into ODEs of a single variable each. The ODEs are solved separately andtheir solutions combined into the solution of the PDE.

    In many cases, the ODEs resulting from the separation of variables produce solutions thatdepend on a parameter known as an eigenvalue(if the eigenvalue appears in a sine or cosinefunction that depends on time, it is referred to as an eigenfrequency). The solutions involving

    eigenvalues are known as eigenfunctions.

    AAnnaallyyttiiccaall ssoolluuttiioonnss ttoo ppaarraabboolliicc eeqquuaattiioonnss:: oonnee--ddiimmeennssiioonnaall

    ssoolluuttiioonnoofftthheehheeaatteeqquuaattiioonn

    The flow of heat in a thin, laterally insulated homogeneous rod is modeled by

    u/t = k(2u/x2),

    where u = temperature, k = a parameter resulting from combining thermal conductivity anddensity. The PDE is subject to the initial condition

    u(x,0) = f(x)

    and constant-value boundary conditions

    u(0,t) = u0, andu(L,t) = uL.

    The physical phenomenon described by this PDE and its initial and boundary conditions isillustrated in the figure below with u0= uL= 0.

  • 8/10/2019 partial diff with scilab.pdf

    6/49

    Download at InfoClearinghouse.com 4 2001 Gilberto E. Urroz

    We will try to find a solution by the method of separation of variables. This method assumesthat the solution, u(x,t), can be expressed as the product of two functions, X(x) and T(t):

    u(x,t) = X(x)T(t).

    With this substitution, the initial condition, u(x,t=0) = f(x) = X(x)T(t), can be treated as the setof conditions: X(x) = f(x),when t = 0[i.e., T(t) = 1]. Also, the boundary conditions, u(0,t) =X(0)T(t) = u0,and u(L,t) = X(L)T(t) = uL, can be treated as X(0) = u0, andX(L) = uL, as long as

    T(t) 0.

    The derivatives of u(x,t) are calculated as follows:

    and

    Replacing these derivatives in the heat equation we get:

    2

    x2 ( )X x ( )T t

    t( )u ,x t ( )X x

    t

    ( )T t

    =( )X x

    t

    ( )T t k

    2

    x2

    ( )X x ( )T t

    2

    x2 ( )u ,x t

  • 8/10/2019 partial diff with scilab.pdf

    7/49

    Download at InfoClearinghouse.com 5 2001 Gilberto E. Urroz

    Dividing by u(x,t) = X(x)T(t):

    This result is only possible if both sides of the equation are equal to a constant, say -, sincethe left-hand side is only a function of t and the right hand side is only function of x. The left-hand side of the heat equation produces an ODE with independent variable t:

    Whose solution is:

    On the other hand, the right-hand side of the heat equation produces an ODE with independentvariable is x:

    A general solution forX(x)is:

    Next, we replace the boundary condition X(0) = 0, which results in the equation 0 = _C2, or_C2 = 0. With this result, the solution simplifies to:

    =( )T t e( ) t

    =( )X x _C1

    sin

    k

    x

  • 8/10/2019 partial diff with scilab.pdf

    8/49

    Download at InfoClearinghouse.com 6 2001 Gilberto E. Urroz

    The second boundary condition, X(L) = 0, produces:

    The latter result indicates an eigenfunction problem. We need to find all possible values of

    for which this equation is satisfied. Since we want _C1 0, then we set

    This equationhas multiple solutions located at,

    !! ,3,2,,0,,2,3 =k

    L

    i.e.,

    or,

    Therefore, with these values of the solution forX(x)now becomes:

    =

    sin L

    k

    0

    := n

    2 2

    k

    L2

    =( )X x _C1

    sin

    n2

    2

    L2

    x

  • 8/10/2019 partial diff with scilab.pdf

    9/49

    Download at InfoClearinghouse.com 7 2001 Gilberto E. Urroz

    The value of _C1 remains somewhat arbitrary, requiring a different approach to find it. Tosimplify notation we will replace _C1 with bn:

    With the value of found earlier, the solution for T(t)is now:

    There will be a different expression for u(x,t) = X(t)T(t)for each value of n = 0 , 1, 2, 3, ....Therefore, we will call the solution corresponding to a particular value of n un(x,t) and write:

    The form of the n-th solution, un, suggests an expansion similar to a Fourier series expansionfor the overall solution, u(x,t), restricting the values of n to positive integers, i.e.,

    .expsin),(),(2

    22

    11

    ==

    =

    = L

    ktn

    L

    xnbyxuyxu

    n

    n

    n

    nn

    with the values of bnobtained from the boundary condition, u(x,0) = f(x),i.e.,

    The latter result is a Fourier sine series with the coefficients bngiven by:

    =( )X x bn

    sinn

    2 2

    L2

    x

    =( )T t e

    n2

    2k t

    L2

    ==n 1

    sin

    n xL

    bn ( )fx

  • 8/10/2019 partial diff with scilab.pdf

    10/49

  • 8/10/2019 partial diff with scilab.pdf

    11/49

    Download at InfoClearinghouse.com 9 2001 Gilberto E. Urroz

    AAnnaallyyttiiccaallssoolluuttiioonnssttooppaarraabboolliicceeqquuaattiioonnss::OOnnee--ddiimmeennssiioonnaallssoolluuttiioonnooff

    tthheewwaavveeeeqquuaattiioonn

    The wave equation, shown below, can be used to model the displacement of an elastic string orthe longitudinal vibration of a beam:

    For the case of an elastic string, =c2 T

    , where T is the constant tension in the string and is

    the mass per unit length of the string. For the case of longitudinal vibration of a beam,

    =c2 g E

    , where g is the acceleration of gravity, E is the modulus of elasticity, and is the

    density of the beam.

    Suppose we solve the wave equation for a vibrating string of length L using separation of

    variables with the boundary conditions u(0,t) = u(L,0)= 0. Also, the initial shape of the string is

    given by u(x,0) = f(x), and the initial speed of the string is given by =

    t( )u ,x t ( )g x at =t 0 . We

    postulate a solution of the form u(x,t) = X(x)T(t),and replace this result in the original PDE:

    =( )X x

    2

    t2( )T t c2

    2

    x2( )X x ( )T t

    Dividing both sides of the equation by u(x,t),we get:

  • 8/10/2019 partial diff with scilab.pdf

    12/49

    Download at InfoClearinghouse.com 10 2001 Gilberto E. Urroz

    This equation is only possible if the two sides of the equations are equal to a constant, say,2 . With this we can write two ODEs, one for each side of the equation WaveEqn1, i.e.,

    The solutions to these equations are:

    Note: the constants _C1 and _C2 in the two solutions are not the same. The boundaryconditions u(0,t) = u(L,t) = 0translate intoX(0) = X(L) = 0. With these boundary conditions, wecan form the following algebraic equations:

    :=_C2 0

    We have an eigenvalue equation given by =

    sin

    Lc

    0 . The solution to this equation is L

    c=

    0, , 2 ,..., or = 0,cL

    ,2 c

    L,.... Using only the positive values, we can write =

    n cL

    ,

    n = 0,1,2,.... Next, using the value of and _C2 = 1, we obtain an expression for X(x) asfollows:

    := n c

    L

    :=Sol2 =( )X x sin

    n xL

    Function T(t)gets written as:

    =( )T t +_C1 cos

    n c tL

    _C2 sin

    n c tL

    The function u(x,t) is now:

  • 8/10/2019 partial diff with scilab.pdf

    13/49

    Download at InfoClearinghouse.com 11 2001 Gilberto E. Urroz

    Application of the initial conditions provide the following equations:

    Since the last two equations need to apply for n = 0,1,2, ..., we recognize in them the

    equations that define Fourier series if we use _C1 = an , and _C2 = bn , i.e.,

    =( )f x an

    sin

    n xL

    =( )g x sin n x

    L bnn c

    L

    The equations defining coefficients an and bn are given by:

    an =2

    L d

    0

    L

    ( )f x

    sin

    n xL

    x , and bn =2

    n c d

    0

    L

    ( )g x

    sin

    n xL

    x , for n = , ,1 2 3 ,...

    The final solution is, therefore,

    Example 1 - Consider the case of a vibrating string with the initial displacement given by f(x)

    =x

    L( 1

    x

    L), and the initial velocity given by g(x) =

    x

    L

    2

    ( 1 x

    L). The boundary conditions

    are u(0,t) = 0, u(L,t) = 0. Determine the solution u(x,t)for this problem using components ofthe resulting Fourier series for n = 1, 2, ..., 20, if c = 1and L = 1.

    The first three definitions correspond to functionf(x),the integrand for an, and a

    nitself. The

    next three definitions correspond to functiong(x), the integrand for bn, and bnitself.

    -->deff('[w]=f(x)','w=(x/L)*(1-x/L)')

    -->deff('[w]=ff(x)','w=f(x)*sin(n*%pi*x/L)')

    -->deff('[aa]=a(n)','aa=(2/L)*intg(0,L,ff,0.001)')

    -->deff('[w]=g(x)','w=(x/L)^2*(1-x/L)')

    -->deff('[w]=gg(x)','w=g(x)*sin(n*%pi*x/L)')

    -->deff('[bb]=b(n)','bb=(2/(n*%pi*c))*intg(0,L,gg,0.001)')

    Next, we define the values of L and cand calculate the coefficients anand bn:

  • 8/10/2019 partial diff with scilab.pdf

    14/49

    Download at InfoClearinghouse.com 12 2001 Gilberto E. Urroz

    -->L=1;c=1;

    -->aa=[];for n=1:20, aa=[aa a(n)]; end;

    -->bb=[];for n=1:20, bb=[bb b(n)]; end;

    The next step is to define the functionu(x,t)and calculate values of the same for x in therange 0x=[0:0.05:1];t=[0:0.1:4];

    -->uu=feval(x,t,u);

    -->plot3d(x,t,uu,45,45,'x@t@u(x,t)')

    An alternative way to present the result is to plot u(x,t0)vs.xfor selected values of toas shownin the next SCILAB commands:

    -->plot2d([x' x' x' x' x'],[uu(:,1),uu(:,5),uu(:,10),uu(:,15),uu(:,20)],...

    -->[-1:-1:-5],'111','t=0.05@t=0.25@t=0.50@t=0.75@t=1.0',[0 -0.3 1 0.3])

    -->plot2d([x' x' x' x' x'],[uu(:,1),uu(:,5),uu(:,10),uu(:,15),uu(:,20)],...

    -->[1:1:5],'011','t=0.05@t=0.25@t=0.50@t=0.75@t=1.0',[0 -0.3 1 0.3])

    -->xtitle('Wave equation solution','x','u(x,t)')

    The plot thus generated is shown below:

  • 8/10/2019 partial diff with scilab.pdf

    15/49

    Download at InfoClearinghouse.com 13 2001 Gilberto E. Urroz

    AAnnaallyyttiiccaall ssoolluuttiioonnss ttoo hhyyppeerrbboolliicc eeqquuaattiioonnss:: TTwwoo--ddiimmeennssiioonnaallssoolluuttiioonnttooLLaappllaaccee''sseeqquuaattiioonniinnaarreeccttaanngguullaarrddoommaaiinn..

    Laplace's equation in two-dimensions is given by

    =+

    2

    x2( )u ,x y

    2

    y2( )u ,x y 0 .

    In problems related to heat transfer, the two-dimensional Laplace equation describes thesteady state distribution of temperature u(x,y)in the x-y plane. In fluid mechanics, u(x,y)could describe the velocity potential or the streamfunction for a two-dimensional potentialflow. The problem requires two boundary conditions in the two independent variables x andy.

    Laplace equation is solved in a rectangular domain so that 0

  • 8/10/2019 partial diff with scilab.pdf

    16/49

    Download at InfoClearinghouse.com 14 2001 Gilberto E. Urroz

    Separation of variables suggests that we use a solution of the form,

    =( )u ,x y ( )X x ( )Y y .

    Solving the equation through separation of variables proceeds in the following fashion:

    =

    2

    x2( )X x ( )Y y ( )X x

    2

    y2( )Y y

    Dividing by u(x,y) = X(x)Y(y)results in:

    For the two sides of the resulting equation to be equal, they both must be equal to a constant,2 , resulting in the following two ordinary differential equations:

    The solution to the first ODE is:

    We next use the boundary conditions: =( )X 0 0 , and X(L) = 0 , to determine the constants ofintegration:

    _C2 = 0

  • 8/10/2019 partial diff with scilab.pdf

    17/49

    Download at InfoClearinghouse.com 15 2001 Gilberto E. Urroz

    This second equation produces an eigenvalue equation with the eigenvalues given by = n

    L.

    := n

    L

    The solution for X(x), with _C1 = 1 (since the value _C1 is arbitrary), is, therefore:

    =( )X x cos

    n xL

    The solution to the second ODE is:

    Utilizing the boundary condition: Y(0) = 0, we find for Y(y):

    :=_C3 0

    =( )Y y _C4 sinh n yL

    The product X(x)Y(y), which now depends on the value of the eigenvalue =nn L

    , is referred

    to as =( )vn ,x y ( )X x ( )Y y , with the constant replaced by an :

    The solution will be the sum of all possible functions ( )vn ,x y , i.e.,

    :=u ( ),x y =n 1

    ( )vn ,x y

    The expression for the function ( )u ,x y is:

    If we now evaluate the boundary condition, =( )u ,x H ( )g x , we find the following equation:

    This result is a Fourier series expansion to ( )g x , such that the constants an are calculated by

  • 8/10/2019 partial diff with scilab.pdf

    18/49

    Download at InfoClearinghouse.com 16 2001 Gilberto E. Urroz

    Example 1: Suppose that the dimensions of the solution domain are L = 2 and H = 1, and the

    boundary condition at y = H is given by =( )g x 100 x ( L x )3.

    We start by defining functiong(x), the integrand for the Fourier series coefficients,gg(x), andthe Fourier series coefficients themselves, a(n).

    -->deff('[w]=g(x)','w=100*x*(L-x)^3')

    -->deff('[w]=gg(x)','w=g(x)*sin(n*%pi*x/L)')-->deff('[aa]=a(n)','aa=2*intg(0,L,gg,0.0001)/(L*sinh(n*%pi*H/L))')

    Next, we define the values of Land H, calculate 20 Fourier coefficients, and define andevaluate the u(x,y)in the ranges 0'uu=uu+aa(n)*sin(n*%pi*x/L)*sinh(n*%pi*y/L)';'end'])

    -->x=[0:L/20:L];y=[0:H/20:H];

    -->uu=feval(x,y,u);

    -->plot3d(x,y,uu,45,45,'x@y@u(x,y)')

    Solutions to Laplaces equation in two-dimensions can also be represented by contour plots asshown below:

    -->contour(x,y,uu,15)

    -->xtitle('Contour plots for Laplace equation solution','x','y')

  • 8/10/2019 partial diff with scilab.pdf

    19/49

    Download at InfoClearinghouse.com 17 2001 Gilberto E. Urroz

    More solutions to Laplace equation in a rectangular domain

    The solution obtained above was facilitated by the use of zero boundary conditions in three ofthe boundaries. The zero boundary conditions at x = 0 and x = L produced the eigenvalues

    =n

    n L

    ,

    while the zero boundary condition at y = 0 produced the series solution

    =( )u ,x y =n 1

    an

    sin

    n xL

    sinh

    n yL

    .

    Finally, the non-zero boundary condition at y = H, produced the coefficients an for the

    corresponding Fourier series. The case solved above is referred to as Case [1] in the figurebelow.

    Solutions to the case of a rectangular domain where only one of the boundaries is non-zero canbe found for cases [2] through [4] in the figure below using a procedure similar to that outlinedabove for case [1].

  • 8/10/2019 partial diff with scilab.pdf

    20/49

  • 8/10/2019 partial diff with scilab.pdf

    21/49

    Download at InfoClearinghouse.com 19 2001 Gilberto E. Urroz

    The solution to the first ODE is:

    We next use the boundary conditions: =( )X 0 0 , and X(L) = 0 , to determine the constants ofintegration:

    0 = _C2

    0 = _C1 sin(x)

    This second equation produces an eigenvalue equation with the eigenvalues given by = n

    L

    .

    The solution forX(x),with_C2 = 1(since the value _C2 is arbitrary), is, therefore:

    =( )X x

    cos

    n xL

    The solution to the second ODE is:

    Utilizing the boundary condition: Y(H) = 0, we find for Y(y):

    or

    :=_C4 _C3

    cosh

    n HL

    sinh

    n HL

    =( )Y y _C3

    +

    cosh

    n yL

    sinh

    n HL

    cosh

    n HL

    sinh

    n yL

    sinh n H

    L

    The productX(x)Y(y),which now depends on the value of the eigenvalue =nn L

    , is referred

    to as =( )vn ,x y ( )X x ( )Y y , with the constant replaced by an :

  • 8/10/2019 partial diff with scilab.pdf

    22/49

    Download at InfoClearinghouse.com 20 2001 Gilberto E. Urroz

    The solution will be the sum of all possible functions ( )vn ,x y , i.e.,

    The expression for the function ( )u ,x y is:

    If we now evaluate the boundary condition, =( )u ,x 0 ( )g x , we find the following equation:

    This result is a Fourier series expansion to ( )f x , such that the constants an are calculated by

    Example 1: Suppose that the dimensions of the solution domain are L = 2 and H = 1, and the

    boundary condition at y = H is given by =( )f x 100 x ( L x )3.

    -->L=2;H=1;

    -->deff('[w]=f(x)','w=100*x*(L-x)^3') //Function f(x)

    -->deff('[w]=ff(x)','w=f(x)*sin(n*%pi*x/L)') //Integrand Fourier series coeff.

    -->deff('[aa]=a(n)','aa=(2/L)*intg(0,L,ff,0.0001)') //Fourier coeff. defined

    -->aa=[]; for n=1:20, aa=[aa a(n)]; end; //Calculate Fourier coeff.

    The following statements define the solution u(x,y):

    -->deff('[uu]=u(x,y)',['uu=0';'for n=1:20';

    -->'uu=uu+aa(n)*sin(n*%pi*x/L)/sinh(n*%pi*H/L)*...

    -->(cosh(n*%pi*y/L)*sinh(n*%pi*H/L)-cosh(n*%pi*H/L)*sinh(n*%pi*y/L))';

    -->'end'])

    To produce a three-dimensional plot of the solution we use:

    -->x=[0:L/20:L];y=[0:H/20:H];uu=feval(x,y,u);

    -->plot3d(x,y,uu,45,45,'x@y@u(x,y)')

  • 8/10/2019 partial diff with scilab.pdf

    23/49

    Download at InfoClearinghouse.com 21 2001 Gilberto E. Urroz

    The solution can also be shown as a contour plot.

    -->contour(x,y,uu,15)

    -->xtitle('Laplace equation - case 2','x','y')

    Superposition of solutions for cases [1] and [2]

    The superposition of the solutions for cases [1] and [2] will be the solution to the problemwhose boundary conditions are illustrated in the figure below:

  • 8/10/2019 partial diff with scilab.pdf

    24/49

    Download at InfoClearinghouse.com 22 2001 Gilberto E. Urroz

    We use for the solution =( )f x x ( )L x 3 , and =( )g x x3 ( )L x . The following SCILAB statementsproduce the solution to this problem.

    -->deff('[w]=f(x)','w=x*(L-x)^3')

    -->deff('[w]=g(x)','w=x^3*(L-x)')

    -->deff('[w]=ff(x)','w=f(x)*sin(n*%pi*x/L)')

    -->deff('[w]=gg(x)','w=g(x)*sin(n*%pi*x/L)')

    -->deff('[aa1]=a1(n)','aa1=2*intg(0,L,gg,0.0001)/(L*sinh(n*%pi*H/L))')

    -->deff('[aa2]=a2(n)','aa2=(2/L)*intg(0,L,ff,0.0001)')

    -->L=2;H=1;

    -->aa1=[]; for n=1:20, aa1=[aa1 a1(n)]; end;

    -->aa2=[]; for n=1:20, aa2=[aa2 a2(n)]; end;

    -->deff('[uu1]=u1(x,y)',['uu1=0';'for n=1:20';...

    -->'uu1=uu1+aa1(n)*sin(n*%pi*x/L)*sinh(n*%pi*y/L)';'end'])

    -->deff('[uu2]=u2(x,y)',['uu2=0';'for n=1:20';...

    -->'uu2=uu2+aa2(n)*sin(n*%pi*x/L)/sinh(n*%pi*H/L)*...

    -->(cosh(n*%pi*y/L)*sinh(n*%pi*H/L)-cosh(n*%pi*H/L)*sinh(n*%pi*y/L))';...

    -->'end'])

    -->x=[0:L/20:L];y=[0:H/20:H];

    -->uu1=feval(x,y,u1);uu2=feval(x,y,u2);uu=uu1+uu2;

    -->plot3d(x,y,uu,45,45,'x@y@u(x,y)')

    -->contour(x,y,uu,15)

    -->xtitle('Laplace equation - cases 1 & 2','x','y')

  • 8/10/2019 partial diff with scilab.pdf

    25/49

    Download at InfoClearinghouse.com 23 2001 Gilberto E. Urroz

    Suppose now, that the boundary conditions are such that =( )f1 x 3 ( )f x = 3x ( )L x3and

    =( )g1

    x 5 ( )g x = 5x3 ( )L x . Since we already have the solutions corresponding to f(x) and g(x),

    we can obtain the solution to the problem with the new set of boundary conditions by

    constructing the following solution =( )u ,x y +3 ( )u1 ,x y 5 ( )u2 ,x y :

    -->uu=3*uu1+5*uu2;

    The three-dimensional plot corresponding to this solution is shown below:

    -->plot3d(x,y,uu,45,45,'x@y@u(x,y)')

    Contour plots of the solution are produced by using:

    -->contour(x,y,uu,15)

    -->xtitle('Laplace equation - cases 1 & 2','x','y')

  • 8/10/2019 partial diff with scilab.pdf

    26/49

    Download at InfoClearinghouse.com 24 2001 Gilberto E. Urroz

    Laplacian in polar-cylindrical coordinates

    Consider the function =u ( )u , ,r z in polar coordinates. The Laplacian of this function in polarcoordinates can be obtained from Maple using:

    + + +

    r

    ( )u , ,r z r

    2

    r2( )u , ,r z

    2

    2( )u , ,r z

    r r

    2

    z2( )u , ,r z

    r

    You can check that the first two terms are equivalent to r

    r

    r

    ( )u , ,r z , i.e.,

    +

    r

    ( )u , ,r z r

    2

    r2( )u , ,r z

    Thus, the Laplacian of u(x,y,z) can be written as:

    =1

    r +

    r

    r

    r

    ( )u , ,r z1

    r2

    2

    2( )u , ,r z +

    2

    z2( )u , ,r z

    In the next section we will discuss the solution of the Laplace equation in two dimensions using

    polar-cylindrical coordinates, the corresponding Laplacian, taking =u ( )u ,r and =z

    u 0 , is

    =1

    r +

    r

    r

    r

    ( )u ,r 1

    r2

    2

    2( )u ,r

    Solution to Laplace's equation in an annulusConsider the domain of solution to Laplace equation to be an annulus defined, in polar

    coordinates, as r1 < r< r2 , and 0 < < 2 , subjected to the boundary conditions:=( )u ,r

    1 u

    1 = constant, and =( )u ,r2 u2 = constant, as illustrated in the figure below:

  • 8/10/2019 partial diff with scilab.pdf

    27/49

    Download at InfoClearinghouse.com 25 2001 Gilberto E. Urroz

    In polar coordinates, Laplace's equation is written as:1

    r +

    r

    r

    r

    ( )u ,r 1

    r2

    2

    2( )u ,r = 0.

    If the solution is assumed to depend only on the radial coordinate, =u ( )u r , and =

    u 0 .

    Thus, Laplace's equation reduces to1

    r

    r

    r

    r

    ( )u r = 0. The later result represents an

    ordinary differential equation and we could write it as

    1

    r

    d

    dr(r

    du

    dr) = 0,

    ord

    dr(r

    du

    dr) = 0.

    Integration of this equation produces: u(r) = _C1 + _C2 ln(r).

    Using the boundary conditions indicated above we obtain:

    .ln

    )ln()()ln()ln(

    )(

    2

    1

    122112

    =r

    r

    ruururu

    ru

    For example, if u1=1, r1=1, u2= 10, r2= 5, the distribution of u(r)is illustrated in the followingfigure.

    -->u1=1;r1=1;u2=10;r2=5;

    -->deff('[uu]=u(r)','uu=(u2*log(r1)-u1*log(r2)-(u2-u1)*log(r))/log(r1/r2)')

    -->r=[r1:(r2-r1)/100:r2];uu=u(r);

    -->plot(r,uu,'r','u(r)','Laplace equation in a disk')

  • 8/10/2019 partial diff with scilab.pdf

    28/49

    Download at InfoClearinghouse.com 26 2001 Gilberto E. Urroz

    __________________________________________________________________________________

    Three-dimensional surface plot in polar coordinates

    To produce a three-dimensional surface plot of a function z = f(r,)we propose the followingfunction,plotpolar. The call to the function is

    plotpolar(r_range,theta_range,nx,ny,f)

    where r_rangeis the vector [rmin,rmax], theta_rangeis the vector [theta_min, theta_max]where the functionfis defined. Since the function uses functionplot3dto produce the surfaceplot, we need to produce a rectangularx-ygrid. The number of divisions in thexand ydirections are given by the numbers nxand ny, respectively. The function returns two plots, athree-dimensional surface plot and a contour plot of the functionf. A listing of functionpolarplotfollows:

    function [] = plotpolar(rrange,trange,n,m,f)

    //A function to produce a three-dimensional//plot out of a function z = f(r,theta)

    xmin=-rrange(2);xmax=+rrange(2);xrange=xmax-xmin;

    ymin=-rrange(2);ymax=+rrange(2);yrange=ymax-ymin;

    xx=[xmin:xrange/n:xmax];

    yy=[ymin:yrange/m:ymax];

    nx=length(xx);ny=length(yy);

    zz=zeros(nx,ny);

    for i = 1:nx

    for j = 1:ny

    rr=norm([xx(i) yy(j)]);

    if xx(i) == 0 & yy(j) == 0 then

    th = 0.0 else

    th=atan(xx(i),yy(j));

    end;

    if rr>=rrange(1) & rr=trange(1) & th

  • 8/10/2019 partial diff with scilab.pdf

    29/49

    Download at InfoClearinghouse.com 27 2001 Gilberto E. Urroz

    xset('window',1);xbasc();plot3d(xx,yy,zz);

    xset('window',2);xbasc();contour(xx,yy,zz,10);

    The range of values for both x and y is [-rmax,rmax]. To obtain a full surface plot of thefunctionfuse theta_range = [-%pi,%pi]. To obtain half-a-plot use theta_range=[0,%pi].

    The functionfmust be defined as a function of both rand , even if it depends only on one ofthe variables. Thus, for the solution of the Laplace equation in an annulus obtained above, wewill re-define the function uas shown below.

    -->u1=1;r1=1;u2=10;r2=5;

    -->deff('[uu]=u(r,t)','uu=(u2*log(r1)-u1*log(r2)-(u2-u1)*log(r))/log(r1/r2)')

    To produce a half-plot of the function u(r)we use:

    -->r_range = [r1,r2]; theta_range = [0,%pi];-->plotpolar(r_range,theta_range,40,40,u)

    Next, we redefine the range of to produce a full plot of the function:

    -->r_range = [r1,r2]; theta_range = [-%pi,%pi];

  • 8/10/2019 partial diff with scilab.pdf

    30/49

    Download at InfoClearinghouse.com 28 2001 Gilberto E. Urroz

    -->plotpolar(r_range,theta_range,40,40,u)

    __________________________________________________________________________________

    Solution to the Laplace equation in a disk

    Consider the case in which =u ( )u ,r as solution to the Laplace equation on a disk centered atthe origin and subjected to the boundary condition, =( )u ,R ( )f , where R is the radius of thedisk. Using separation of variables we can write =( )u ,r ( )R r ( )T , requiring that ( )T beperiodic in with period 2 . Thus, we can write ( )T as a Fourier series, i.e.,

    ( )T = +

    a0

    2

    =k 1

    ( )+ak ( )cos k bk ( )sin k .

    The procedure for the solution using separation of variables proceeds as follows. The Laplaceequation in cylindrical coordinates is written as:

    To separate the equation into ordinary differential equations we use u(r,) = R(r)T():

  • 8/10/2019 partial diff with scilab.pdf

    31/49

    Download at InfoClearinghouse.com 29 2001 Gilberto E. Urroz

    The differential equations are:

    Since the expression ( )ln r is equivalent to ( )ln r , we can re-write R(r)as:

    +_C1

    1

    2r

    1

    2

    1

    r _C2

    +1

    2r

    1

    2

    1

    r

    Or, redefining the constants,

    Typically, the values of are positive values, therefore, the term r( )

    grows unbounded as

    r 0 . This requires that we eliminate the term r( )

    from the solution by making _C2 = 0,thus:

    =( )R r _C1 r

    The second ODE obtained from separation of variables and its solution are:

    The latter result indicates that the initial assumption of a periodic function for ( )T isacceptable if we take = k. We now replace the solution to the second ODE with:

    The combined solution, ( )u ,r = ( )R r ( )T , is now:

    The boundary condition, =( )u ,R ( )f , produces:

    With the coefficients of the resulting Fourier series given by:

    =a01

    d

    0

    2

    ( )f , ak =1

    R k d

    0

    2

    ( )f ( )cos k , and bk =1

    R k d

    0

    2

    ( )f ( )sin k .

  • 8/10/2019 partial diff with scilab.pdf

    32/49

    Download at InfoClearinghouse.com 30 2001 Gilberto E. Urroz

    For example, if R = 10, and =( )f +( )sin 2.5 ( )sin 2 1.5 ( )cos 3 , we can obtain the solutionu(r,)using the following SCILAB commands:

    -->deff('[w]=f(t)','w=sin(t)-2.5*sin(2*t)+1.5*cos(3*t)') //define f(theta)

    -->R = 10;

    -->a0=(1/%pi)*intg(0,2*%pi,f,0.0001) //Calculate a0

    a0 = - 1.414E-16

    -->deff('[w]=fc(t)','w=f(t)*cos(k*t)') //Integrand for cosine coefficients

    -->deff('[w]=fs(t)','w=f(t)*sin(k*t)') //Integrand for sine coefficients

    -->deff('[aa]=a(k)','aa=intg(0,2*%pi,fc,0.0001)/(%pi*R k)')//cosine coeff. def

    -->deff('[bb]=b(k)','bb=intg(0,2*%pi,fs,0.0001)/(%pi*R k)')//sine coeff. def.

    -->aa=[];for k=1:20, aa=[aa a(k)]; end; aa = clean(aa) //cosine coeff.

    aa =

    column 1 to 11

    ! 0. 0. .0015 0. 0. 0. 0. 0. 0. 0. 0. !

    column 12 to 20

    ! 0. 0. 0. 0. 0. 0. 0. 0. 0. !

    -->bb=[];for k=1:20, bb=[bb b(k)]; end; bb = clean(bb) //sine coeff.

    bb =

    column 1 to 11

    ! .1 - .025 0. 0. 0. 0. 0. 0. 0. 0. 0. !

    column 12 to 20

    ! 0. 0. 0. 0. 0. 0. 0. 0. 0. !

    Next, we define the function u(r,), and produce a plot of the solution using functionplotpolar, first on an x-y grid of 3030and then on a 4040grid.

    -->deff('[uu]=u(r,t)',['uu=a0/2';'for k=1:20';

    -->'uu=uu+r^k*(aa(k)*cos(k*t)+bb(k)*sin(k*t))';'end'])

    -->r_range=[0,R]; theta_range=[-%pi,%pi];-->getf('plotpolar')

    -->plotpolar(r_range,theta_range,30,30,u)

  • 8/10/2019 partial diff with scilab.pdf

    33/49

    Download at InfoClearinghouse.com 31 2001 Gilberto E. Urroz

    -->plotpolar(r_range,theta_range,40,40,u)

    A contour plot of the function u(r,)on a 4040x-y grid is shown next.

  • 8/10/2019 partial diff with scilab.pdf

    34/49

    Download at InfoClearinghouse.com 32 2001 Gilberto E. Urroz

    Numerical solutions to partial differential equations

    The numerical solution to partial differential equations is a subject that may fill severalvolumes. In this section we present some simple numerical solutions to elliptic, parabolic, andhyperbolic partial differential equations. The examples presented herein are aimed atdemonstrating the use of SCILAB in simple numerical solutions to PDEs.

    Numerical solution to parabolic PDEs: heat equation

    The unsteady heat equation in one-dimension is given by

    u/t = K(2u/x2),

    for 0

  • 8/10/2019 partial diff with scilab.pdf

    35/49

    Download at InfoClearinghouse.com 33 2001 Gilberto E. Urroz

    ,)(

    )2(2

    ,1,11,

    x

    uuuK

    t

    uu jiijjiijji

    +

    =

    ++

    or,

    ui,j+1= uij+(ui-1,j-2uij+ui+1,j),

    for i=1,2,,n, andj=1,2,, with

    = Kt/(x)2.

    The result shown above for ui,j+1= u(xi,tj+1) is an explicit solution for the temperature. Stability

    conditions for this explicit solution requires that < 0.5.

    To produce a solution we use a solution grid as shown below:

    We load the initial conditions at t=0and the boundary conditions at x = 0 and x = L for any time

    t > 0, and proceed to calculate ui,j+1= u ij+(ui-1,j-2uij+ui+1,j), for i=2,3,,n-1, andj=2,3,. Theresult is a matrix usuch that uij= u(xi,tj).

    AAffuunnccttiioonnffoorrtthheeeexxpplliicciittnnuummeerriiccaallssoolluuttiioonnoofftthheehheeaatteeqquuaattiioonn

    The following function, HeatPDE1, produces the explicit solution to the heat equation. The

    call to the function is

    [u]=HeatPDE1(xrange,trange,uinit,u0bound,uLbound,K)

    wherexrangeis a vector of length n containing the range of values of x uniformly distributed,i.e., xrange = [x1:Dx:xn], trange is a vector of length m containing the range of values of t,also uniformly distributed, i.e., trange = [t0:Dt:tm]. The vector uinit is a vector of length ncontaining the initial conditions for u(x,t). Vectors u0boundand uLboundare vectors of lengthmcontaining the values of the lower and upper boundary conditions for the different times tin

  • 8/10/2019 partial diff with scilab.pdf

    36/49

    Download at InfoClearinghouse.com 34 2001 Gilberto E. Urroz

    trange. The value Kis the constant from the heat equation. The function return the matrix uof size nxmrepresenting the solution of the heat equation.

    function [u]=HeatPDE1(xrange,trange,uinit,u0bound,uLbound,K)

    n=length(xrange);m = length(trange);

    u = zeros(n,m);

    Dx = (xrange(n)-xrange(1))/(n-1);

    Dt = (trange(m)-trange(1))/(m-1);

    u(:,1)=uinit';

    u(1,:)=u0bound;

    u(n,:)=uLbound;

    alpha = K*Dt/(Dx)^2;

    if alpha >= 0.5 then

    printf('WARNING: The value of alpha is larger than or equal to 0.5.');

    printf('The explicit solution is unstable and it will not be calculated.');

    abort;

    end;

    for j = 1:m-1

    for i = 2:n-1

    u(i,j+1) = u(i,j)+alpha*(u(i-1,j)-2*u(i,j)+u(i+1,j));

    end;

    end;

    Example of application of function HeatPDE1

    We will solve the heat equation using anxrange of [0:0.1:1] with a trange [0:0.005:1.5] and K= 1.0. The initial conditions will be simply zero values, while the boundary conditions will beu(0,t) = exp(-2t)sin(50t) and u(1,t) = exp(-3t)cos(50t).

    -->K=1.0; //Heat eqn. constant-->x=[0:0.1:1];t=[0:0.005:1.5];ui=zeros(x); //x,t,initial conditions

    -->u0=exp(-2*t).*sin(50*t);uL=exp(-3*t).*cos(50*t); //boundary conditions

    -->[u]=HeatPDE1(x,t,ui,u0,uL,K); //Solution u(x,t)

    -->plot3d(x,t,u,45,45,'x@t@u(x,t)') //Three-dim. plot

    -->xtitle('Heat equation solution')

  • 8/10/2019 partial diff with scilab.pdf

    37/49

  • 8/10/2019 partial diff with scilab.pdf

    38/49

    Download at InfoClearinghouse.com 36 2001 Gilberto E. Urroz

    an explicit solution for ui,j+1= u(xi,tj+1)is

    ui,j+1= 2(ui-1,j+ui+1,j)+2(1-

    2)uij- ui,j-1.

    To introduce the initial conditions into the solution we first use the fact that ui1 = u(xi,t1) =

    g(xi).

    The result obtained above for ui,j+1, whenj=1introduces the term ui0which is not defined:

    ui,2= 2(ui-1,1+ui+1,1)+2(1-

    2)ui1- ui0.

    However, when we introduce the derivative initial condition, u/t|t=0= g(x),re-writing it interms of the centered finite-difference approximation,

    (ui,2-ui,0)/(2t) = g(xi),

    the term ui0appears again. From the last expression, we can write

    ui0= -2tg(xi) + ui2,

    which replaced in the expression for ui2results in

    ui2= 2(ui-1,1+ui+1,1)+2(1-

    2)ui1+ 2tg(xi) - ui2.

    Solving for ui2we get

    ui2=2(ui-1,1+ui+1,1)/2 + (1-

    2)ui1+ tg(xi) .

    Thus, the latter result is used to calculate ufor the first time step. For values ofj=2,3,, wecalculate the solution with

    ui,j+1= 2(ui-1,j+ui+1,j)+2(1-

    2)uij- ui,j-1.

    AAffuunnccttiioonnffoorrtthheessoolluuttiioonnoofftthheewwaavveeeeqquuaattiioonn

    The following solution, WavePDE1, can be used to obtain the solution u(x,t)for the waveequation. The call to the function is

    [u] = WavePDE1(xrange,trange,uinit,duinit,u0bound,uLbound,c)

    wherexrangeis a vector of length n containing the range of values of x uniformly distributed,i.e.,xrange = [x1:Dx:xn], trangeis a vector of length m containing the range of values of t,also uniformly distributed, i.e., trange = [t0:Dt:tm]. Vector uinitis a vector of length ncontaining the initial conditions for u(x,t), while vector duinitis also a vector of length n

    containing the derivative boundary condition,u/t|t=0= g(x). Vectors u0boundand uLbound

    are vectors of length mcontaining the values of the lower and upper boundary conditions forthe different times tin trange. The value cis the constant from the wave equation. Thefunction return the matrix uof size nxmrepresenting the solution of the wave equation.

    function [u] = WavePDE1(xrange,trange,uinit,duinit,u0bound,uLbound,c)

    n=length(xrange);

    m = length(trange);

    u = zeros(n,m);

    Dx = (xrange(n)-xrange(1))/(n-1);

  • 8/10/2019 partial diff with scilab.pdf

    39/49

    Download at InfoClearinghouse.com 37 2001 Gilberto E. Urroz

    Dt = (trange(m)-trange(1))/(m-1);

    u(:,1)=uinit';

    u(1,:)=u0bound;

    u(n,:)=uLbound;

    alpha2 = c^2*Dt^2/Dx^2;

    if alpha2 > 1.0 then

    printf('WARNING: The value of alpha is larger than 1.0.');

    printf('The explicit solution is unstable and it will not be calculated.');

    abort;

    end;

    //first time step

    for i = 2:n-1

    u(i,2) = ...

    alpha2*(u(i-1,1)+u(i+1,1))/2+(1-alpha2)*u(i,1)+Dt*duinit(i);

    end;

    //subsequent time steps

    for j = 2:m-1

    for i = 2:n-1

    u(i,j+1)=...

    alpha2*(u(i-1,j)+u(i+1,j))+2*(1-alpha2)*u(i,j)-u(i,j-1);

    end;

    end;

    Example of application of function WavePDE1

    In this example we solve the wave equation in the range 0 < x < 1, for 0 < t < 1.5, with initialconditionsf(x) = x(1-x),andg(x) = 0.2. The boundary conditions are u(0,t) = u(1,t) = 0. Theresults obtained are shown as a three-dimensional surface u(x,t).

    -->x=[0:0.1:1];t=[0:0.01:1.5];uinit=x.*(1-x);duinit=0.2*ones(x);

    -->u0=zeros(t);uL=zeros(t);c=1;

    -->u=WavePDE1(x,t,uinit,duinit,u0,uL,c);

    -->plot3d(x,t,u,45,45,'x@t@u(x,t)')

    -->xtitle('Wave Equation Solution')

  • 8/10/2019 partial diff with scilab.pdf

    40/49

    Download at InfoClearinghouse.com 38 2001 Gilberto E. Urroz

    Next, we re-calculate the solution to the wave equation for the time range 0 < t < 9 in order toproduced an animation of the function u(x,t) vs. x for different values of t. The instructionsfor the animation follow. The user is invited to try the animation in his or her own SCILABapplication.

    -->x=[0:0.1:1];t=[0:0.01:9];uinit=x.*(1-x);duinit=0.2*ones(x);

    -->u0=zeros(t);uL=zeros(t);c=1;

    -->u=WavePDE1(x,t,uinit,duinit,u0,uL,c);

    -->size(u)

    ans =

    ! 11. 901. !

    -->min(u),max(u)ans = - .2770746

    ans = .2821966

    -->xset('pixmap',1);xbasc();

    -->for j = 1:901,plot2d(x',u(:,j),1,'011',' ',[0 -0.3 1 0.3]),...

    -->xset('wshow'),xset('wwpc'),end

    NNuummeerriiccaallssoolluuttiioonnttooeelllliippttiiccPPDDEEss::LLaappllaacceeeeqquuaattiioonn

    Consider the solution to the two-dimensional Laplace equation

    2u/x2+ 2u/y2= 0,

    in the solution region R = {x1

  • 8/10/2019 partial diff with scilab.pdf

    41/49

    Download at InfoClearinghouse.com 39 2001 Gilberto E. Urroz

    To proceed with the solution we divide the solution region Rinto a grid defined by

    x1= 0, xn= L, y1= 0, ym= H, x = (xn-x1)/(n-1), y = (ym-y1)/(m-1),

    so that the grid in the x direction consists of the values [x1, x2, , xn] and the grid in the ydirection consists of the values [y1, y2, , ym]. The grid values are calculated as

    xi= x1+ (i-1)x, yj= y1+ (j-1)y.

    The figure below shows a sketch of the solution grid.

    The original PDE gets replaced by an algebraic equation by using centered finite differenceapproximations for the second order derivatives, i.e.,

    2u/x2(ui+1,j- 2uij+ ui-1,j)/(x)2, 2u/y2(ui,j+1- 2uij+ ui,j-1)/(y)

    2.

    The resulting algebraic equation is

    (ui+1,j- 2uij+ ui-1,j)/(x)2+ (ui,j+1- 2uij+ ui,j-1)/(y)

    2= 0,

    from which we can get an explicit expression for uij:

    .])()[(2

    )()()()(22

    ,1,1

    2

    1,1,

    2

    yx

    uuyuuxu

    jijijiji

    ij ++++

    = ++

    To proceed with the solution we will first load the boundary conditions in vectors uy1, uym,ux1, uxn. Vectors uy1, uymare vectors of length n, while vectors ux1, uxnare vectors oflength m. Then, we calculate improved values for uij, i=1,2,,n,andj=1,2,,m, using theequation developed above. We will repeat the calculations foruijand keep recalculating untilthe values of uijconverge to their final values. The convergence criteria to be used will be to

    ensure that |(uij)k+1-(uij)k| < , where is a tolerance value, and krepresents the currentapproximation step.

  • 8/10/2019 partial diff with scilab.pdf

    42/49

    Download at InfoClearinghouse.com 40 2001 Gilberto E. Urroz

    AAffuunnccttiioonnttoossoollvveeLLaappllaacceeeeqquuaattiioonniinnaarreeccttaanngguullaarrddoommaaiinn

    The following function, LaplacePDF1, calculates the solution to Laplace equation in arectangular domain. The general call to the function is

    [u,k] = LaplacePDE1(xrange,yrange,ux1,uxn,uy1,uym,epsilon,nmax)

    wherexrangeis a vector of nelements, i.e.,xrange = [x1:Dx:xn], and yrange is a vector of melements, i.e.,yrange = [y1:Dy:ym]. Vectorsxrangeand yrangedefine the solution grid. Thevalues ux1, uxn, uy1, uym,are vectors representing the boundary conditions atx = x1, x = xn, y= y1, and y = ym, respectively. The value epsilonrepresents the tolerance for convergence,and nmaxrepresents the maximum number of iterations allowed. The function returns a nxmmatrix u, whose elements represent the solution, i.e., uij=u(xi,yj), and the value kwhichindicates the number of the iteration at which a solution was achieved, if any.A listing of the function follows:

    function [u,kk] = LaplacePDE1(xrange,yrange,ux1,uxn,uy1,uym,epsilon,nmax)

    n=length(xrange);m=length(yrange);

    Dx=(xrange(n)-xrange(1))/(n-1);Dy=(yrange(m)-yrange(1))/(m-1);

    u=ones(n,m);uk=ones(n,m);

    u(:,1)=uy1';u(:,m)=uym';

    u(1,:)=ux1;u(n,:)=uxn;

    printf('Iteration started.');

    for k =1:nmax

    ke = 0;kk=k;

    if modulo(kk,10) == 0 then

    printf('Current iteration is number %g.',k);

    end;

    for i = 2:n-1

    for j = 2:m-1

    uk(i,j)=...

    (Dx^2*(u(i,j-1)+u(i,j+1))+Dy^2*(u(i-1,j)+u(i+1,j)))/(2*(Dx^2+Dy^2)); if abs(uk(i,j)-u(i,j))>epsilon then

    ke = ke+1

    end;

    u(i,j)=uk(i,j);

    end;

    end;

    if ke == 0 then

    break

    end;

    end;

    if kk==nmax then

    printf('Maximum number of iterations %g reached',kk);

    end;

    Example of application of function LaplacePDE1

    Consider the case in which the solution region is defined by R = {0

  • 8/10/2019 partial diff with scilab.pdf

    43/49

    Download at InfoClearinghouse.com 41 2001 Gilberto E. Urroz

    -->getf('LaplacePDE1')

    -->x=[0:0.1:1];y=[0:0.1:1];

    -->ux1=zeros(y);uxn=ones(y);uy1=1-x^2;uym=zeros(x);

    -->epsilon=0.001;nmax=1000;

    -->[u,k]=LaplacePDE1(x,y,ux1,uxn,uy1,uym,epsilon,nmax);

    (Output suppressed)

    -->k

    k = 42

    -->plot3d(x,y,u,45,45,'x@y@u(x,y)')

    A solution with a more refined grid, x = y = 0.05, is produced next. Convergence is achievedafter 128 iterations.

    -->x=[0:0.05:1];y=[0:0.05:1];

    -->ux1=zeros(y);uxn=ones(y);uy1=1-x^2;uym=zeros(x);

    -->epsilon=0.001;nmax=1000;

    -->[u,k]=LaplacePDE1(x,y,ux1,uxn,uy1,uym,epsilon,nmax);

    (output suppressed)

    -->k

    k = 128.

    -->plot3d(x,y,u,45,45,'x@y@u(x,y)')

  • 8/10/2019 partial diff with scilab.pdf

    44/49

    Download at InfoClearinghouse.com 42 2001 Gilberto E. Urroz

    The solution is also shown as contour curves:

    -->contour(x,y,u,10)

    -->xtitle('Solution to Laplace equation','x','y')

    Exercises

    In the following exercises we use the following PDEs from physical science:

    One-dimensional wave equation: utt = c2uxx

    One-dimensional heat equation: ut = c2uxx

    Two-dimensional Laplace equation: uxx+uyy= 0

    Two-dimensional Poisson equation: uxx+uyy= f(x,y)

    With the notation ut= u/t, uxx= 2u/2x, etc.

    [1]. Determine if the following functions u(x,t)satisfy the one-dimensional wave equation:(a) u(x,t) = cxt (b) u(x,t) = ln(x2-c2t2)(c) u(x,t) = x2 + c2t2 (d) u(x,t) = x/(x2+c2t2)

    [2]. Determine if the following functions u(x,t)satisfy the one-dimensional heat equation:(a) u(x,t) = exp(k(x+kc2t)) (b) u(x,t) = t+x2/(2c2)

    (c) u(x,t) = 2c2/(2c2t+x2) (d) u(x,t) = x2+ 2c2t2

    [3]. Determine if the following functions u(x,y)satisfy the two-dimensional Laplace equation:(a) u(x,t) = k(x2+y2) (b) u(x,t) = tan-1(y/x)(c) u(x,t) = ln(x2+y2) (d) u(x,t) = x3-3xy2

  • 8/10/2019 partial diff with scilab.pdf

    45/49

    Download at InfoClearinghouse.com 43 2001 Gilberto E. Urroz

    [3]. Determine if the functions u(x,y) satisfy the two-dimensional Poisson equation for thegiven functionf(x,y):

    (a) u(x,y) = x cos y, f(x,y) = -x cos y(b) u(x,y) = x2-2xy+y2, f(x,y) = 4(c) u(x,y) = x ln y, f(x,y) = -x/y2

    (d) u(x,y) = (x+y)3, f(x,y) = 12(x+y)

    [4]. Classify the following second-order partial differential equations as parabolic, hyperbolic,or elliptic:(a) ut- utx- uxx= 0 (b) uxx - 2uxy+ uyy = xy(c) uxx+ uxt- utt+ ux+ ut= 0 (d) uxx + uyy= 0

    Solve problems [5] through [12] using separation of variables and Fourier series expansions.

    [5]. Solution to the heat equation with derivative boundary conditions. Using separation ofvariables, solve the one-dimensional heat equation for the temperature u(x,t) on a bar of

    length L = 1, using as boundary conditions u/x = 0forx = 0andx = L. Assume that the initialtemperature distribution is given by u(x,0) = f(x) = x(1-x),and use k=1.

    [6]. Solution to the heat equation with heat convection loss . Consider the one-dimensional

    heat equation including convection losses: u/t = k(2u/x2) - u, and subject to the boundaryconditions: u(0,t) = 0, u(L,t) = 0, and the initial condition: u(x,0) = f(x).

    (a) Using the transformation u(x,t) = exp(-t)w(x,t), verify that the original PDE is

    transformed into w/t = k(2w/x2), and that the corresponding boundary and initialconditions transform into w(0,t) = 0, w(L,t) = 0, and w(x,0) = f(x).

    (b). For L = 1, k = 1, = 0.01, and f(x) = x(1-x) determine the solution u(x,t) to the heatequation with convection loss.

    [7]. Solution to the diffusion-convection equation with constant flow velocity. Manyequations related to diffusion in moving fluids include a term involving the flow velocity v in

    the x-direction: u/t + v(u/x)= k(2u/x2). If vis a constant, this equation can be reduced

    to the form: w/t = k(2w/x2),by using the transformation

    (a) Verify that the transformation indicated above produces the modified PDE: w/t =

    k(2w/x2).(b) Solve the diffusion-convection equation with constant flow velocity in the domain

    0

  • 8/10/2019 partial diff with scilab.pdf

    46/49

    Download at InfoClearinghouse.com 44 2001 Gilberto E. Urroz

    [10]. Referring to the following figure, solve case [3] of Laplaces equation in the rectangulardomain L = 2, H = 1, if p(y) = (y/H)(1-y/H). Produce a surface plot as well as a contour plot ofthe results.

    [11]. Referring to the figure of problem [12], solve case [4] of Laplaces equation in therectangular domain L = 2, H = 1, if q(y) = (y/H) 2(1-y/H). Produce a surface plot as well as acontour plot of the results.

    [12]. Using the results of problems [12] and [14] determine the solution to Laplaces equationin the rectangular domain L = 2, H = 1, if the boundary conditions are u(x,0) = u(x,H) = 0, u(0,y)= p(y) = (y/H)(1-y/H), and u(L,y) = q(y) = (y/H)2(1-y/H). Produce a surface plot as well as a

    contour plot of the results.

    [13]. Solve problem [5] numerically using finite differences.

    [14]. Solve problem [6] numerically using finite differences.

    [15]. Solve problem [7] numerically using finite differences.

    [16]. Solve problem [8] numerically using finite differences.

    [17]. Solve problem [9] numerically using finite differences.

    [18]. Solve problem [10] numerically using finite differences.

    [19]. Solve problem [11] numerically using finite differences.

    [20]. Solve problem [12] numerically using finite differences.

    [21]. The solution to the first degree PDE

    u/t + c (u/x) = 0

  • 8/10/2019 partial diff with scilab.pdf

    47/49

    Download at InfoClearinghouse.com 45 2001 Gilberto E. Urroz

    can be accomplished by using the following finite-difference explicit scheme (known as the Laxmethod)

    )(2

    )(2

    1,1,1,1,11, kikikikiki uu

    x

    tcuuu +++

    += ,

    where ui,k= u(xi,tk),xi=x1+(i-1)x, for i=1,2,,n,and tk=t1+(k-1)t, for k=1,2,,m. For the

    method to be stable -- i.e., to dampen out any error in the solution as the solution progresses -- the Lax method must satisfy the so-called Courant-Friedrichs-Lewy stability condition, i.e.,

    .1||

    x

    tc

    Write a SCILAB function to solve the PDE: u/t + c (u/x) = 0, with c = 1 subject to the initialcondition u(x,0) = f(x) = (x/L)(1-x/L), in the interval 0 < x < L, with L = 1,for 0 < t < 10, using

    (a) x = 0.10, t = 0.05

    (b) x = 0.10, t = 0.1

    (c) x = 0.10, t = 0.2

    [22]. A finite-difference approximation to the first-order PDE: u/t + c (u/x) = 0, is givenby

    ).(2

    ,1,1

    1,

    kiki

    ikkiuu

    x

    c

    t

    uu+

    +

    =

    Re-write the finite-difference approximation as an equation of the form

    ui,k+1-uik+ (/2)(ui+1,k-ui-1,k) = 0,

    with = ct/x, and obtain an implicit solution to the PDE for the conditions of problem [21].

  • 8/10/2019 partial diff with scilab.pdf

    48/49

    Download at InfoClearinghouse.com 46 2001 Gilberto E. Urroz

    REFERENCES (for all SCILAB documents at InfoClearinghouse.com)

    Abramowitz, M. and I.A. Stegun (editors), 1965,"Handbook of Mathematical Functions with Formulas, Graphs, andMathematical Tables," Dover Publications, Inc., New York.

    Arora, J.S., 1985, "Introduction to Optimum Design," Class notes, The University of Iowa, Iowa City, Iowa.

    Asian Institute of Technology, 1969, "Hydraulic Laboratory Manual," AIT - Bangkok, Thailand.

    Berge, P., Y. Pomeau, and C. Vidal, 1984,"Order within chaos - Towards a deterministic approach to turbulence," JohnWiley & Sons, New York.

    Bras, R.L. and I. Rodriguez-Iturbe, 1985,"Random Functions and Hydrology," Addison-Wesley Publishing Company,Reading, Massachussetts.

    Brogan, W.L., 1974,"Modern Control Theory," QPI series, Quantum Publisher Incorporated, New York.

    Browne, M., 1999, "Schaum's Outline of Theory and Problems of Physics for Engineering and Science," Schaum'soutlines, McGraw-Hill, New York.

    Farlow, Stanley J., 1982, "Partial Differential Equations for Scientists and Engineers," Dover Publications Inc., NewYork.

    Friedman, B., 1956 (reissued 1990), "Principles and Techniques of Applied Mathematics," Dover Publications Inc., New

    York.

    Gomez, C. (editor), 1999, Engineering and Scientific Computing with Scilab, Birkhuser, Boston.

    Gullberg, J., 1997, "Mathematics - From the Birth of Numbers," W. W. Norton & Company, New York.

    Harman, T.L., J. Dabney, and N. Richert, 2000, "Advanced Engineering Mathematics with MATLAB - Second edition,"Brooks/Cole - Thompson Learning, Australia.

    Harris, J.W., and H. Stocker, 1998, "Handbook of Mathematics and Computational Science," Springer, New York.

    Hsu, H.P., 1984, "Applied Fourier Analysis," Harcourt Brace Jovanovich College Outline Series, Harcourt BraceJovanovich, Publishers, San Diego.

    Journel, A.G., 1989, "Fundamentals of Geostatistics in Five Lessons," Short Course Presented at the 28th InternationalGeological Congress, Washington, D.C., American Geophysical Union, Washington, D.C.

    Julien, P.Y., 1998,Erosion and Sedimentation, Cambridge University Press, Cambridge CB2 2RU, U.K.

    Keener, J.P., 1988, "Principles of Applied Mathematics - Transformation and Approximation," Addison-WesleyPublishing Company, Redwood City, California.

    Kitanidis, P.K., 1997,Introduction to Geostatistics - Applications in Hydogeology, Cambridge University Press,Cambridge CB2 2RU, U.K.

    Koch, G.S., Jr., and R. F. Link, 1971, "Statistical Analysis of Geological Data - Volumes I and II," Dover Publications,Inc., New York.

    Korn, G.A. and T.M. Korn, 1968, "Mathematical Handbook for Scientists and Engineers," Dover Publications, Inc., NewYork.

    Kottegoda, N. T., and R. Rosso, 1997, "Probability, Statistics, and Reliability for Civil and Environmental Engineers,"The Mc-Graw Hill Companies, Inc., New York.

    Kreysig, E., 1983, "Advanced Engineering Mathematics - Fifth Edition," John Wiley & Sons, New York.

    Lindfield, G. and J. Penny, 2000, "Numerical Methods Using Matlab,"Prentice Hall, Upper Saddle River, New Jersey.

    Magrab, E.B., S. Azarm, B. Balachandran, J. Duncan, K. Herold, and G. Walsh, 2000, "An Engineer's Guide toMATLAB", Prentice Hall, Upper Saddle River, N.J., U.S.A.

    McCuen, R.H., 1989,Hydrologic Analysis and Design - second edition, Prentice Hall, Upper Saddle River, New Jersey.

    Middleton, G.V., 2000, "Data Analysis in the Earth Sciences Using Matlab,"Prentice Hall, Upper Saddle River, NewJersey.

  • 8/10/2019 partial diff with scilab.pdf

    49/49