Number Mathematics

download Number Mathematics

of 19

Transcript of Number Mathematics

  • 7/25/2019 Number Mathematics

    1/19

    Notes on Finite-Difference Methods forAME 301: Differential Equations, Vibrations and Controls

    Mihir Sen

    Department of Aerospace and Mechanical Engineering

    University of Notre DameNotre Dame, IN 46556, U.S.A.

    November 28, 2005

    1 Introduction

    It is common to use numerical methods to compute the solution of nonlinear or otherwise complicatedordinary differential equations. For partial differential equations it is necessitated also by a geometry forwhich an analytical solution may not exist. There are many numerical methods for solving differentialequations, both ordinary and partial, but here we will look only at the finite-difference method in somedetail.

    Since numerical solutions are usually calculated on digital computers, the use of numerical methodsrequire knowledge and efficient use of modern programming languages and techniques. There are a varietyof languages currently in use; some are compilable, such as Fortran, C and C++, while there are otherslike Matlab which are more suitable for graphing and use in conjunction with toolboxes. Matlab is usually

    sufficient to illustrate the use of a numerical method and hence will be shown below, but readers can convertthem to a compilable language for faster runs.

    2 Numerical differentiation

    2.1 Functions of a single variable

    Letu = u(x), so that on expanding in Taylor series around a pointx = x, we have

    u(x+ x) = u(x) +u(x)x +1

    2u(x)x2 +O(x3), (1)

    u(x x) = u(x) u(x)x +1

    2u(x)x2 +O(x3). (2)

    Terms which have xn are indicated simply as of the order of xn and written asO(xn).At this point we will change the notation somewhat to make it easier to write computer programs.

    Thus, referring to Fig. 1, we will write x(i 1) = x x, x(i) = x and x(i+ 1) = x+ x with x =x(i + 1)x(i) =x(i)x(i1) being the step size. Similarly, we will write u(x + x) = u(i +1),u(x) = u(i)andu(x x) = u(i 1). The indices will indicate the location where the quantity is being evaluated.

    From Eq. (1) we can obtain the forward-difference approximation

    u(i) = 1

    x[u(i+ 1) u(i)] +O(x2). (3)

    1

  • 7/25/2019 Number Mathematics

    2/19

    Similarly from Eq. (2), we have the backward-difference formula

    u(i) = 1

    x[u(i) u(i 1)] +O(x2). (4)

    Subtracting Eq. (2) from Eq. (1) gives the central difference

    u(i) = 1

    2x[u(i+ 1) u(i 1)] +O(x3)). (5)

    On adding Eqs. (1) and (2), we get the second derivative

    u(i) = 1

    x2[u(i+ 1) 2u(i) +u(i 1)] +O(x3). (6)

    u(x)

    xx(i 1) x(i) x(i+ 1)

    u(i 1) u(i) u(i+ 1)

    Figure 1: Function of a single variable.

    ExampleFind numerically the derivatives of the function u = sin(2x). Fig. 2 shows a comparison between the numerical and

    analytical values for the first and second derivative. It is seen that the smaller values of x gives better results. Thenumerical codes used to produce the results are similar to the ones shown in Section 7.2.

    2.2 Functions of two variables

    Let u = u(x, y) where (x, y) belongs to some two-dimensional area. The region may be divided up bya grid according to the coordinate system used. Here we will work with a Cartesian grid as shown inFig. 3 and use two indices to indicate where a quantity is being evaluated, the first for the x-directionand the second for the y. The mesh size is then x = x(i + 1, j) x(i, j) = x(i, j) x(i 1, j) andy= x(i, j+ 1) x(i, j) = x(i, j) x(i, j 1).

    Expansions in Taylor series around a point (i, j) give

    u(i+ 1, j) = u(i, j) +ux(i, j)x+1

    2uxx(i, j)x

    2 +O(x3), (7)

    u(i 1, j) = u(i, j) ux(i, j)x+1

    2uxx(i, j)x

    2 +O(x3), (8)

    u(i, j+ 1) = u(i, j) +uy(i, j)y+1

    2uyy(i, j)y

    2 +O(y3), (9)

    u(i, j 1) = u(i, j) uy(i, j)y+1

    2uyy(i, j)y

    2 +O(y3). (10)

    2

  • 7/25/2019 Number Mathematics

    3/19

    0 0.2 0.4 0.6 0.8 110

    5

    0

    5

    10

    0 0.2 0.4 0.6 0.8 140

    20

    0

    20

    40

    x

    x

    u(x)

    u(x)

    (a)

    (b)

    Figure 2: (a) First and (b) second derivatives ofu = sin(2x) using central differences; x = 0.2 (), 0.1(), 0.02 (); continuous line is analytical.

    These can be manipulated to give the finite-difference approximations. For example, the central-differenceapproximations for the two first-order partial derivatives are

    ux(i, j) = 1

    2x[u(i+ 1, j) u(i 1, j)] +O(x3), (11)

    uy(i, j) = 1

    2y[u(i, j+ 1) u(i, j 1)] +O(y3). (12)

    Similarly the approximations for the second-order partial derivatives are

    uxx(i, j) = 1x2 [u(i+ 1, j) 2u(i, j) +u(i 1, j)] +O(x3), (13)

    uyy(i, j) = 1

    y2[u(i, j+ 1) 2u(i, j) +u(i, j 1)] +O(y3). (14)

    The Laplacian operator defined as

    2u= uxx+uyy (15)

    can be approximated by

    2u =

    1

    x2[u(i+ 1, j) 2u(i, j) +u(i 1, j)]

    + 1

    y2[u(i, j+ 1) 2u(i, j) +u(i, j 1)] +O(max(x3, y3)). (16)

    If for simplicity we take x= y= h, then this becomes

    2u=

    1

    h2[u(i+ 1, j) +u(i 1, j) +u(i, j+ 1) +u(i, j 1) 4u(i, j)] +O(h3). (17)

    ExampleFind the Laplacian of the function u = sin[x(1 x)y(1 y)] in 0 x 1 and 0 y 1 shown in Fig. 4.The result obtained using Eq. (17) is shown in Fig. 5. The code in Section 7.3 was used to generate Figs. 4 and 5.

    3

  • 7/25/2019 Number Mathematics

    4/19

    (i 1, j) (i, j) (i+ 1, j)

    (i, j 1)

    (i, j+ 1)

    Figure 3: Cartesian mesh for two independent variables.

    0

    0.2

    0.4

    0.6

    0.8

    1

    0

    0.5

    1

    0

    0.05

    0.1

    0.15

    0.2

    xy

    u(x,y)

    Figure 4: Function u = sin[x(1 x)y(1 y)] shown using a 2020 mesh.

    3 Ordinary differential equations

    The finite differences defined in Section 2.1 can be introduced in an ordinary differential equation to reduceit to algebraic form. At this point there are an infinite number of solutions for the values of the unknown.To make the solution unique, boundary conditions have to be introduced. Boundary conditions can be ofthe following forms. Each one of them can be reduced to algebraic form and used.

    3.1 Dirichlet

    In this case the value of the function is prescribed at the boundary. For example, one can have

    u(1) =a (18)

    where i = 1 is the node at the end where the value ofu is given as a. u(1) is then no longer an unknownquantity.

    4

  • 7/25/2019 Number Mathematics

    5/19

    0

    0.2

    0.4

    0.6

    0.8

    1

    0

    0.5

    1

    0

    1

    2

    3

    4

    xy

    2u

    Figure 5: Laplacian ofu = sin[x(1 x)y(1 y)] (for clarity multiplied by 1);h = 0.1.

    3.2 Neumann

    Here the derivative of the function u is known at the boundary, so that a finite-difference approximationhas to be used. As an example, ifu =a at the boundary, we can approximate the condition by

    u(2) u(1)

    x =a (19)

    wherei = 1 lies on the boundary and i = 2 is the node next to it.

    3.3 Robin

    Sometimes a linear combination of the function u and its derivative u is known at the boundary, i.e.au+bu =c. Once again an algebraic form can be obtained using finite differences, so that

    au(1) +b u(2) u(1)

    x =c (20)

    wherei = 1 andi = 2 are again the nodes on the boundary and next to it.

    ExampleSolve

    u +u= 0, (21)

    with the Dirichlet boundary conditions u(0) =a and u(1) =b.Divide the interval [0, 1] into N sub-intervals, each of length x= 1/N, and number the nodes as i = 1, 2, . . . , N + 1

    so that x(i) = (i 1)x. Using Eq. (6) in (21), we get

    u(i+ 1) (2 x2)u(i) +u(i 1) = 0, (22)

    at i = 2, 3, . . . , N . Applying the boundary conditions u(1) = a and u(N+ 1) = b, we get N 1 algebraic equations in

    the unknowns u(2), u(3), . . . , u(N). In matrix form these are

    c 1 0 . . . 01 c 1 0 . . .0 1 c 1 . . ....

    ......

    ......

    0 0 . . . 1 c

    u(2)u(3)

    ...u(N 1)

    u(N)

    =

    a0...0b

    , (23)

    where c = 2 x2. Methods to solve Eq. (23) are in Section 5, and the solution is shown in Fig. 6.

    5

  • 7/25/2019 Number Mathematics

    6/19

    0 0.2 0.4 0.6 0.8 10

    0.1

    0.2

    0.3

    0.4

    0.5

    0.6

    0.7

    0.8

    0.9

    1

    x

    u(x)

    Figure 6: Dots indicate the numerical solution of Eq. (21) with x= 0.01, and continuous line the analytical

    solutionu = sin x/ sin(1).

    4 Partial differential equations

    Finite differences described in Section 2.2 can be applied to PDEs to reduce them to algebraic equations.Boundary conditions may be of the types indicated in Sections 3.1, 3.2 and 3.3, the only difference being thatderivatives are in a direction normal to the boundary, and they can be approximated in a similar fashion.For the three conditions, one can, for example, write

    u(n) = a (24)u(n) u(n+ 1)

    n =a (25)

    au(1) +b u(n) u(n+ 1)

    n =c (26)

    respectively, where the indices n and n + 1 refer to points at the boundary and a distance n away from itin a direction normal to the boundary.

    Numerical solutions shouldconvergeas the mesh becomes finer. Furthermore, the result obtained shouldbe consistent in that the solution obtained should correspond to that of the original PDE. The numericalmethod chosen should also be stable.

    4.1 Heat equation in one spatial variable

    The heat equation is1

    uxx= ut, (27)

    with suitable boundary conditions. An explicit marching method can be used to calculate the values ofu(x, t) at time from a previous instant using the finite-difference form of Eq. (27)

    x2 [u(i+ 1, j) 2u(i, j) +u(i 1, j)] =

    1

    t[u(i, j+ 1) u(i, j)] , (28)

    1Note that W.E. Boyce and R.C. DiPrima,Elementary Differential Equations and Boundary Value Problems, Eighth Edition,John Wiley, New York, 2005 has 2 instead of in the equation.

    6

  • 7/25/2019 Number Mathematics

    7/19

    where we have used a central difference in x and a forward difference in t. Thus

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

    x2[u(i+ 1, j) 2u(i, j) +u(i 1, j)] . (29)

    which can be repeatedly applied to calculate forward in time. It can be shown that this method is numericallystable as long ast/x2

  • 7/25/2019 Number Mathematics

    8/19

    0

    100

    200

    3000

    10

    20

    30

    40

    50

    0

    5

    10

    15

    20

    t x

    u(x,t

    )

    Figure 8: Numerical solution of Eq. (27) with = 1; x = 1, t = 0.1. The analytical solution is very

    similar.

    x= 0 x= 1/3 x= 1

    0.1

    Figure 9: Initial value f(x).

    SinceN= 6, the spatial step is x= L/N= 1/6 = 0.1667. Choose t= 0.01, so that t/x2 = 0.36 (this shouldbe less than 0.5 for stability). The calculated results are entered in Table 1. The initial conditions are given in the rowj = 1, and the boundary conditions in the columns i = 1 and i = 7. Use Eq. (29) to enter the rest of the values in thetable. As many time steps as necessary can be calculated, but three steps are shown.

    4.2 Heat equation in two spatial variables

    With two spatial variables, the heat equation is

    (uxx+uyy) = ut (33)

    with suitable initial and boundary conditions.An explicit marching method, similar to that in Section 4.1 can be used. Using central difference in space

    and forward difference in time we get

    1

    x2[u(i+ 1, j , k) 2u(i,j,k) +u(i 1, j , k)] +

    1

    y2[u(i, j+ 1, k) 2u(i,j,k) +u(i, j 1, k)]

    =

    1

    t[u(i,j,k+ 1) u(i,j,k)] . (34)

    8

  • 7/25/2019 Number Mathematics

    9/19

  • 7/25/2019 Number Mathematics

    10/19

    i

    j

    x= 0 x= 3

    y= 0

    y = 2

    Figure 10: Finite difference mesh for Eq. (36).

    0

    0.5

    1

    1.5

    2

    0

    1

    2

    3

    0

    0.2

    0.4

    0.6

    0.8

    1

    xy

    u(x,

    t)

    Figure 11: Numerical solution of Eq. (36) in functional form withh = 0.1. The analytical solution is verysimilar.

    4.4 Wave equation

    A finite difference approximation of the wave equation

    a2uxx= utt (41)

    isu(i, j+ 1) = 2(1 r2)u(i, j) +r2 (u(i+ 1, j) +u(i 1, j)) u(i, j 1), (42)

    where x and tare the spatial and time steps, and r = a t/x. For stability of the numerical method,we must take r

  • 7/25/2019 Number Mathematics

    11/19

    0.1

    0.10.1

    0.1

    0.3

    0.3

    0.30.5

    0.50.70.9

    0 0.5 1 1.5 20

    0.5

    1

    1.5

    2

    2.5

    3

    x

    y

    Figure 12: Numerical solution of Eq. (36) in contour form withh = 0.1. The analytical contours are very

    similar.

    5.2 Other algorithms

    There are many ways to solve algebraic equations of the form Ax = y where A is a square non-singularmatrix, and x and y are appropriate vectors. x is unknown while A and y are known. The solution may beschematically represented as x = A1y.

    6 Conclusions

    This has been a very brief introduction to finite-difference methods for the numerical solution of boundaryvalue problems. Many other methods such as finite element and spectral methods are also commonly used.

    7 Appendices

    7.1 Plotting using Matlab

    The following are some of the commands that may be used to display numerical results.Simple plots: plot(x,y)Plot with symbols: plot(x,y,o);Multiple plots: plot(x1,y1,s1,x2,y2,s2,x3,y3,s3,...)3D plot: plot3(x,y,z)3D surface: surf(x,y,z)3D contours: contour(x,y,z)

    7.2 Differentiation of functions of a single variable

    A Matlab code similar to the one below can be used to produce the results used in Fig. 2.

    %Finite difference derivatives

    %Function y = sin(2 pi x)

    %dy is first and ddy second derivative

    clear

    %Analytical solution

    xa=[0:0.01:1];

    11

  • 7/25/2019 Number Mathematics

    12/19

    dya=2*pi*cos(2*pi*xa);

    ddya=-4*pi*pi*sin(2*pi*xa);

    %Divide interval into N parts

    N=5;

    dx=1/N;%Evaluate needed values of function

    for i=1:N+3

    xx(i)=(i-2)/N;

    yy(i)=sin(2*pi*xx(i));

    end

    %Evaluate derivatives

    for i=2:N+2

    dery(i)=(yy(i+1)-yy(i-1))/(2*dx);

    ddery(i)=(yy(i+1)-2*yy(i)+yy(i-1))/(dx*dx);

    end

    %Transfer to vectors to be plotted

    for i=2:N+2

    x(i-1)=xx(i);dy(i-1)=dery(i);

    ddy(i-1)=ddery(i);

    end

    %Graphs

    subplot(2,1,1),plot(xa,dya,x,dy,o)

    xlabel(x)

    ylabel(dy/dx)

    title((a))

    subplot(2,1,2),plot(xa,ddya,x,ddy,o)

    title((b))

    xlabel(x)

    ylabel(d2y/dx2)

    The Fortran 77 version of the same code is below. The results are stored in text files dera.dat anddern.dat.

    C Finite difference derivatives

    C Function y = sin(2 pi x)

    C dy is first and ddy second derivative

    implicit none

    integer M1,N,i

    parameter(M1=100,N=5)

    real dx,M2,M,pi,xa,dya,ddya,x,y,dy,ddy

    dimension xa(M1+1),dya(M1+1),ddya(M1+1)

    dimension x(N+3),y(N+3),dy(N+3),ddy(N+3)

    C Open two filesopen(unit=1,file=dera.dat)

    open(unit=2,file=dern.dat)

    C Define pi

    pi=4*atan(1.0)

    C Analytical solution

    C Convert from integer to real

    M2=float(M1)

    dx=1.0/M2

    12

  • 7/25/2019 Number Mathematics

    13/19

    do 100 i=1,M1+1

    xa(i)=(i-1)*dx

    dya(i)=2*pi*cos(2*pi*xa(i))

    100 ddya(i)=-4*pi*pi*sin(2*pi*xa(i))

    C Numerical solutionC Convert from integer to real

    M=float(N)

    dx=1.0/M

    C Evaluate needed values of function

    do 200 i=1,N+3

    x(i)=(i-2)*dx

    200 y(i)=sin(2.0*pi*x(i))

    C Evaluate derivatives

    do 300 i=2,N+2

    dy(i)=(y(i+1)-y(i-1))/(2*dx)

    300 ddy(i)=(y(i+1)-2*y(i)+y(i-1))/(dx*dx)

    write(1,400) (xa(i),dya(i),ddya(i),i=1,M1+1)

    write(2,400) (x(i),dy(i),ddy(i),i=2,N+2)400 format(E15.8,2x,E15.8,2x,E15.8)

    close(1)

    close(2)

    stop

    end

    A graphing program must be used to read and plot the data in the files dera.dat and dern.dat producedby Fortran. A Matlab code that does this is shown below.

    %Plot finite difference derivatives

    %stored in files dera.dat and dern.dat

    %obtained from Fortran code

    clearload(-ascii,dera.dat)

    load(-ascii,dern.dat)

    %Graphs

    subplot(2,1,1),plot(dera(:,1),dera(:,2),dern(:,1),dern(:,2),o)

    xlabel(x)

    ylabel(dy/dx)

    title((a))

    subplot(2,1,2),plot(dera(:,1),dera(:,3),dern(:,1),dern(:,3),o)

    title((b))

    xlabel(x)

    ylabel(d2y/dx2)

    7.3 Differentiation of functions of two variables

    The following Matlab code produces Figs. 4 and 5.

    %Finite difference Laplacian

    %Function u = sin(pi x(1-x)y(1-y))

    clear

    %Divide region into N by M parts

    %for analytical purposes

    13

  • 7/25/2019 Number Mathematics

    14/19

    N=20;

    M=N;

    %Calculate function at analytical mesh points

    for i=1:N+1

    for j=1:M+1xa(i)=(i-1)/N;

    ya(j)=(j-1)/M;

    ua(i,j)=sin(pi*xa(i)*(1-xa(i))*ya(j)*(1-ya(j)));

    end

    end

    %Plot function at analytical mesh points

    surf(xa,ya,ua)

    xlabel(x)

    ylabel(y)

    zlabel(z)

    %Divide region into N by M parts

    %for numerical purposes

    N=10;M=N;

    h=1/N;

    %Calculate function at numerical mesh points

    for i=1:N+3

    for j=1:M+3

    xx(i)=(i-2)/N;

    yy(j)=(j-2)/M;

    u(i,j)=sin(pi*xx(i)*(1-xx(i))*yy(j)*(1-yy(j)));

    end

    end

    %Calculate Laplacian

    for i=2:N+2

    for j=2:M+2

    LL(i,j)=(u(i+1,j)+u(i-1,j)+u(i,j+1)+u(i,j-1)-4*u(i,j))/(h*h);

    end

    end

    %Transfer to matrices to be plotted

    for i=2:N+2

    x(i-1)=xx(i);

    end

    for j=2:M+2

    y(j-1)=yy(j);

    end

    for i=2:N+2

    for j=2:M+2L(i-1,j-1)=LL(i,j);

    end

    end

    %Plot L at numerical mesh points

    figure

    surf(x,y,-L)

    xlabel(x)

    ylabel(y)

    14

  • 7/25/2019 Number Mathematics

    15/19

    zlabel(z)

    7.4 Ordinary differential equations

    The Matlab code used to produce Fig. 6 is given below.

    %Second-order ODE

    % y+y=0, y(0)=0,y(1)=1

    clear

    N=100;

    dx=1/N;

    for i=1:N+1

    x(i)=(i-1)/N;

    end

    y(1)=0;

    y(N+1)=1;

    for i=2:N

    y(i)=0;end

    for j=1:10000

    for i=2:N

    y(i)=(y(i+1)+y(i-1))/(2-dx^2);

    end

    end

    for i=1:N+1

    ya(i)=sin(x(i))/sin(1);

    end

    plot(x,ya,x,y,.)

    xlabel(x)

    ylabel(y)

    7.5 Partial differential equations: heat equation

    The following Matlab code calculates the analytical and numerical solution of Eq. 27 and plots Fig. 8.

    %Heat equation

    %Boyce and DiPrima, 8th Ed., p. 608, Ex. 1

    clear

    %Analytial solution

    N=50; % x divisions

    M=25; %t divisions

    NT=500; % number of terms in infinite series

    for i=1:N+1

    xa(i)=50*(i-1)/N; %calculate %space vectorend

    for j=1:M+1

    ta(j)=250*(j-1)/M; % calculate time vector

    end

    % Calculate u(x,t)

    for j=1:M+1

    for i=1:N+1

    ua(j,i)=0;

    15

  • 7/25/2019 Number Mathematics

    16/19

    for k=1:2:NT

    ua(j,i)=ua(j,i)+(80/(k*pi))*exp(-k*k*pi*pi*ta(j)/2500)*sin(k*pi*xa(i)/50);

    end

    end

    endsurf(xa,ta,ua)

    xlabel(x)

    ylabel(t)

    zlabel(u)

    clear

    %Numerical solution

    N=50; %x divisions

    dx=50/N;

    for i=1:N+1

    xn(i)=(i-1)*dx;

    end

    dt=0.1;

    %Initial conditionsi=1;

    tn(i)=0;

    for j=1:N+1

    un(j,i)=20;

    end

    T=0;

    while (tn(i)

  • 7/25/2019 Number Mathematics

    17/19

    %Laplace equation

    %p. 642, Ex. 1

    clear

    %Analytial solution

    N=150; % x divisionsM=100; %t divisions

    NT=50; % number of terms in infinite series

    for i=1:N+1

    xa(i)=3*(i-1)/N; %calculate x vector

    end

    for j=1:M+1

    ya(j)=2*(j-1)/M; % calculate y vector

    end

    % Calculate u(x,y)

    for j=1:M+1

    for i=1:N+1

    ua(j,i)=0;

    for n=1:NTSn=8*sin(n*pi/2)/(n^2*pi^2*sinh(3*n*pi/2));

    ua(j,i)=ua(j,i)+Sn*sinh(n*pi*xa(i)/2)*sin(n*pi*ya(j)/2);

    end

    end

    end

    surf(xa,ya,ua)

    xlabel(x)

    ylabel(y)

    zlabel(u)

    figure

    v=[0.1,0.3,0.5,0.7,0.9];

    [cs,h]=contour(xa,ya,ua,v);

    xlabel(x)

    ylabel(y)

    zlabel(u)

    clabel(cs,h)

    %Numerical solution

    N=30;

    M=20;

    for i=1:N+1

    xn(i)=3*(i-1)/N; %calculate x vector

    end

    for j=1:M+1

    yn(j)=2*(j-1)/M; % calculate y vector

    end%Boundary conditions

    for i=1:N+1

    un(i,1)=0;

    un(i,M+1)=0;

    end

    for j=1:M/2+1

    un(1,j)=0;

    un(N+1,j)=yn(j);

    17

  • 7/25/2019 Number Mathematics

    18/19

    end

    for j=M/2+1:M+1

    un(1,j)=0;

    un(N+1,j)=2-yn(j);

    end%Relaxation

    for k=1:100

    for i=2:N

    for j=2:M

    un(i,j)=(un(i+1,j)+un(i-1,j)+un(i,j+1)+un(i,j-1))/4;

    end

    end

    end

    figure

    surf(yn,xn,un)

    xlabel(x)

    ylabel(y)

    zlabel(u)figure

    v=[0.1,0.3,0.5,0.7,0.9];

    [cs,h]=contour(yn,xn,un,v);

    xlabel(y)

    ylabel(x)

    zlabel(u)

    clabel(cs,h)

    Problems

    In the following, write Fortran codes for numerical computations and Matlab to plot.

    1. Determine the second derivativey (x) ify(x) = sin2x in 0 x 1 using finite differences for stepsizes of 0.1, 0.01, and 0.001. Plot (a) the analytical function y (x), and (b) the numerically obtainedy(x).

    2. Determineux, uy, uxx and uyy ifu(x, y) = sin 2xy in 0 x 1, 0 y 1. Make 3D plots for eachof the derivatives.

    3. Solve Eq. (21), with u(0) = 0 and u(1) = 1. Graph the solution.4. Solveu +xu +u= 0 with u(0) = 0 and u(1) = 1. Graph the solution.5. Solveuxx= ut with u(0, t) = 0, ux(1, t) = 0 and u(x, 0) = sin(x/2).6. Solveuxx+uyy = 0 with the geometry, dimensions and boundary conditions indicated in Fig. 13.7. Solve uxx+ uyy = 0 in a rectangle 0 x 2, 0 y 1 with boundary conditions u(0, y) = 0,

    u(2, y) = 2y, u(x, 0) = 0 and u(x, 1) = x.8. Solve uxx+ uyy = ut with u(x, y, t) in a square 0 x 1, 0 y 1. The initial condition is

    u(x,y, 0) = sin[x(1 x)y(1 y)], and the boundaries are all at u = 0. Plot the u contours for

    t= 0, 0.5, 1.0.9. Solveuxx + uyy = 0 with the geometry, dimensions and boundary conditions indicated in Fig. 14. Plot(a) the surfaceu(x, y), and (b) several u = constant contours.

    10. Five sides of a unit cube have u = 0 while the sixth has u(x,y, 0) = sin[x(1 x)y(1 y)]. Solvelaplaces equations in three dimensions uxx+uyy+uzz = 0.

    11. A stretched string, held firmly at both ends, is plucked at a point one-third of its length; the initialdisplacement,f(x), is shown in Fig. 9. The initial velocity is zero. Taking N= 3, use a hand calculatorto determine values of the displacement, u(i, j), for two time steps using Eq. (42). Assume a = 1 andt= 0.1. [Hint: Since the initial velocity is zero, u(i, 1) = u(i, 2).]

    18

  • 7/25/2019 Number Mathematics

    19/19

    u= 0

    u= 0

    ux= 0

    u= 1

    u= 1

    uy = 0

    10

    10

    5

    5

    x

    y

    Figure 13: Corner.

    ux= 0

    uy = 0

    u= 1

    uy = 0

    ux= 0

    u= 0

    1

    1

    0.5

    0.5

    x

    y

    Figure 14:

    19