LengFengLee_MTH538ProjectReport

download LengFengLee_MTH538ProjectReport

of 37

Transcript of LengFengLee_MTH538ProjectReport

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    1/37

    STATE UNIVERSITY OF NEW YORK AT BUFFALO

    MTH538 NUMERICAL ANALYSIS II

    Final Project

    NAME: LENG-FENG LEE

    ADVISOR: DR. MIKHAIL KHENNER.

    DATE: 10thApril 2006.

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    2/37

    MTH538NUMERICAL ANALYSIS IIFINAL PROJECTLeng-Feng Lee (#2963-2068, [email protected])

    Advisor: Dr. Mikhail Khenner ([email protected])10 April 2006.

    ABSTRACT:In this final project, three problems involving the numerical methods for: Linear system

    of Equations; Eigen Values problem; and Linear and Nonlinear Second Order Boundary

    Value Problem (BVP) are assigned. In particular, the linear system is solved by usingboth Trapezoidal rule and Composite Simpsons rule. The Eigen values problems is solve

    using QR algorithm, and the second order boundary value problem is solved using finitedifference method (both linear and nonlinear). The problem statement, the steps to obtain

    the solution, the results (graphical or analytical), and discussion related to the solution

    were presented where necessary.

    PROBLEM 1:

    Given:

    ( ) ( ) ( ), ( )b

    au x f x K x t u t dt = + (1)

    Where a and b and the function f and K are given. To approximate the function u on the

    interval [a, b], a partition 0 1 1m mx a x x x b= < < < < = is selected and the equation:

    ( ) ( ) ( ), ( ) , 0, ,b

    i i ia

    u x f x K x t u t dt for each i m= + = (2)

    Are solved for ( ) ( ) ( )0 1, , , mu x u x u x . The integrals are approximated using quadrature

    formulas based on the nodes 0 1, , , mx x x . In this problem, 0a= , 1b= , ( )2f x x= , and

    ( ), x tK x t e = .

    Part A. Show the linear system:

    ( ) ( ) ( ) ( ) ( ) ( )

    ( ) ( ) ( ) ( ) ( ) ( )

    10 0 0,0 0 0,1 1 ;

    2

    11 1 1,0 0 1,1 1 ;

    2

    u f K u K u

    u f K u K u

    = + +

    = + +

    (3)

    must be solved when the trapezoidal rule is used.

    Part B. Set up and solve the linear system that results when the Composite Simpsons rule

    is used with 4,6,8m= .

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    3/37

    SOLUTION:

    A. The Trapezoidal rule is given by:

    ( ) ( ) ( ) ( )3

    "

    0 1[ ]2 2

    b

    a

    h hf x dx f x f x f = + (4)

    Assuming the error term ( )3

    " 02

    hf , we have 0 1, x a x b= = , and 1 0 1h x x b a= = = .

    Hence, we can write Equation (2) for 0 1, x a x b= = as follow:

    ( ) ( ) ( ) ( ) ( ) ( )

    ( ) ( ) ( ) ( ) ( ) ( )

    1, , ;

    2

    1, , ;

    2

    u a f a K a a u a K a b u b

    u b f b K b a u a K b b u b

    = + +

    = + +

    (5)

    Substitute Equation (5) with 0, 1a b= = , we get:

    ( ) ( ) ( ) ( ) ( ) ( )

    ( ) ( ) ( ) ( ) ( ) ( )

    10 0 0,0 0 0,1 1 ;

    2

    11 1 1,0 0 1,1 1

    2

    u f K u K u

    u f K u K u

    = + +

    = + +

    (6)

    Which is same as Equation (3), hence proved.

    Now, evaluate Equation (6) by substituting the know values, we obtain the following

    linear equations:

    ( ) ( ) ( )

    ( ) ( ) ( )

    0 0 1

    1 0 1

    0.5000 1.3591

    1.3591 0.5000 1

    u x u x u x

    u x u x u x

    = +

    = + + (7)

    Further write in the form ofAu b= , we have:

    0.5000 1.3591

    1.3591 0.5000A

    =

    and0

    1b

    =

    Solve for ( ) ( )0 1,u x u x using Gaussian Elimination method, we have:

    ( ) ( )0 10.8509; 0.3130u x u x= =

    This result is plotted in Figure 1.

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    4/37

    B. Now solve the problem by using the Composite Simpsons rule. The Composite

    Simpsons rule is given as:

    ( ) ( ) ( ) ( ) ( )( )

    ( ) ( )1

    2 244

    2 2 1

    1 1

    2 43 180

    n nb

    j ja

    j j

    h b af x dx f a f x f x f b h f

    = =

    = + + +

    (8)

    For 4m= ,1

    4

    b ah

    m

    = = , the interval is divided as follow:

    Now, using Equation (8), assuming the error( ) ( )44 0

    180

    b ah f

    , we can have the

    following set of linear equations:

    ( ) ( )

    ( ) ( ) ( ) ( )

    ( ) ( ) ( ) ( )

    ( ) ( )

    0 0 1 1

    2 2 3 3

    4 4

    , 4 ,1

    2 , 4 ,12

    ,

    i i

    i i i i

    i

    K x x u x K x x u x

    u x f x K x x u x K x x u x

    K x x u x

    + +

    = + + +

    (9)

    For 0 1 2 3 40, 0.25, 0.50, 0.75, 1.0x x x x x= = = = = , we can solve for ( ) ( )0 4, ,u x u x bysolving the following linear system:

    ( ) ( ) ( ) ( ) ( ) ( )

    ( ) ( ) ( ) ( ) ( ) ( )

    ( ) ( ) ( ) ( ) ( ) ( )

    ( ) ( ) ( )

    0 0 1 2 3 4

    1 0 1 2 3 4

    2 0 1 2 3 4

    3 0 1

    0.0833 0.4280 0.2748 0.7057 0.2265

    0.1070 0.3333 0.2140 0.5496 0.1764 0.0625

    0.1374 0.4280 0.1667 0.4280 0.1374 0.25

    0.1764 0.5496 0.214

    u x u x u x u x u x u x

    u x u x u x u x u x u x

    u x u x u x u x u x u x

    u x u x u x

    = + + + +

    = + + + + +

    = + + + + +

    = + + ( ) ( ) ( )

    ( ) ( ) ( ) ( ) ( ) ( )

    2 3 4

    4 0 1 2 3 4

    0 0.3333 0.1070 0.5625

    0.2265 0.7057 0.2748 0.4280 0.0833 1

    u x u x u x

    u x u x u x u x u x u x

    + + +

    = + + + + +

    (10)

    Write in the form ofAu b= , we have:

    0.9167 0.428 0.2748 0.7057 0.2265

    0.1070 0.6667 0.2140 0.5496 0.1764

    0.1374 0.4280 0.8333 0.4280 0.1374

    0.1764 0.5496 0.2140 0.6667 0.1070

    0.2265 0.7057 0.2748 0.4280 0.9167

    A

    =

    and

    0

    0.0625

    0.25

    0.5625

    1.0

    b

    =

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    5/37

    And solve for ( )iu x using Gaussian Elimination, we have:

    ( ) ( ) ( ) ( ) ( )0 1 2 3 41.2343; 0.9507; 0.7659; 0.5845; 0.4485u x u x u x u x u x= = = = =

    This result is plotted in Figure 1.

    For 6m= ,1

    6

    b ah

    m

    = = , the interval is divided as follow:

    Again, using Equation (8), assuming the error( ) ( )44 0

    180

    b ah f

    , we can have the

    following set of linear equations:

    ( ) ( )

    ( ) ( ) ( ) ( ) ( ) ( )

    ( ) ( ) ( ) ( )

    ( ) ( ) ( ) ( )

    0 0 1 1 2 2

    3 3 4 4

    5 5 6 6

    , 4 , 2 ,1

    4 , 2 ,18

    4 , ,

    i i i

    i i i i

    i i

    K x x u x K x x u x K x x u x

    u x f x K x x u x K x x u x

    K x x u x K x x u x

    + + +

    = + + +

    +

    (11)

    For 0 1 2 3 4 5 61 2 3 4 5

    0, , , , , , 16 6 6 6 6

    x x x x x x x= = = = = = = , we can solve for ( ) ( )0 6, ,u x u x

    by solving the following linear system:

    ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )

    ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )

    ( ) ( ) ( ) ( ) ( )

    0 0 1 2 3 4 5 6

    1 0 1 2 3 4 5 6

    2 0 1 2 3

    0.0556 0.2625 0.1551 0.3664 0.2164 0.5113 0.1510

    0.0656 0.2222 0.1313 0.3101 0.1832 0.4328 0.1278 0.0278

    0.0775 0.2625 0.1111 0.2625 0.1

    u x u x u x u x u x u x u x u x

    u x u x u x u x u x u x u x u x

    u x u x u x u x u x

    = + + + + + +

    = + + + + + + +

    = + + + + ( ) ( ) ( )

    ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )

    ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )

    ( )

    4 5 6

    3 0 1 2 3 4 5 6

    4 0 1 2 3 4 5 6

    5

    551 0.3664 0.1082 0.1111

    0.0916 0.3101 0.1313 0.2222 0.1313 0.3101 0.0916 0.2500

    0.1082 0.3664 0.1551 0.2625 0.1111 0.2625 0.0775 0.4444

    0.1

    u x u x u x

    u x u x u x u x u x u x u x u x

    u x u x u x u x u x u x u x u x

    u x

    + + +

    = + + + + + + +

    = + + + + + + +

    = ( ) ( ) ( ) ( ) ( ) ( ) ( )

    ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )

    0 1 2 3 4 5 6

    6 0 1 2 3 4 5 6

    278 0.4328 0.1832 0.3101 0.1313 0.2222 0.0656 0.6944

    0.1510 0.5113 0.2164 0.3664 0.1551 0.2625 0.0556 1

    u x u x u x u x u x u x u x

    u x u x u x u x u x u x u x u x

    + + + + + + +

    = + + + + + + +

    (12)

    Write in the form ofAu b= , we have:

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    6/37

    0.9444 0.2625 0.1551 0.3664 0.2164 0.5113 0.1510

    0.0656 0.7778 0.1313 0.3101 0.1832 0.4328 0.1278

    0.0775 0.2625 0.8889 0.2625 0.1551 0.3664 0.1082

    0.0916 0.3101 0.1313 0.7778 0.1313 0.3101 0.0916

    0.1082 0.3664 0.1551 0.2625 0

    A

    =

    .8889 0.2625 0.1775

    0.1278 0.4328 0.1832 0.3101 0.1313 0.7778 0.656

    0.1510 0.5113 0.2164 0.3664 0.1551 0.2625 0.9444

    and

    0

    0.0278

    0.1111

    0.25

    0.4444

    0.6944

    1

    b

    =

    Solve for ( )iu x using Gaussian Elimination, we have:

    ( ) ( ) ( ) ( )

    ( ) ( ) ( )

    0 1 2 3

    4 5 6

    1.2138; 1.0223; 0.8805; 0.7435;

    0.6340; 0.5225; 0.4283;

    u x u x u x u x

    u x u x u x

    = = = =

    = = =

    This result is plotted in Figure 1.

    For 8m= ,1

    8

    b ah

    m

    = = , the interval is divided as follow:

    Once again, using Equation (8), assuming the error ( ) ( )44 0180

    b ah f

    , we can have the

    following set of linear equations:

    ( ) ( )

    ( ) ( ) ( ) ( ) ( ) ( )

    ( ) ( ) ( ) ( ) ( ) ( )

    ( ) ( ) ( ) ( ) ( ) ( )

    0 0 1 1 2 2

    3 3 4 4 5 5

    6 6 7 7 8 8

    , 4 , 2 ,1

    4 , 2 , 4 ,18

    2 , 4 , ,

    i i i

    i i i i i

    i i i

    K x x u x K x x u x K x x u x

    u x f x K x x u x K x x u x K x x u x

    K x x u x K x x u x K x x u x

    + + +

    = + + + +

    + +

    (13)

    For 0 1 2 3 4 5 6 7 81 2 3 4 5 6 7

    0, , , , , , , , 18 8 8 8 8 8 8x x x x x x x x x= = = = = = = = = , we can solve for

    ( ) ( )0 8, ,u x u x by solving the following linear system:

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    7/37

    ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )

    ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )

    ( )

    0.0417 0.1889 0.1070 0.2425 0.1374 0.3114 0.1764 0.3998 0.1133

    0.0472 0.1667 0.0994 0.2140 0.1212 0.2748 0.1557 0.3528 0.1000 0.0156

    0.0

    0 0 1 2 3 4 5 6 7 8

    1 0 1 2 3 4 5 6 7 8

    2

    u x u x u x u x u x u x u x u x u x u x

    u x u x u x u x u x u x u x u x u x u x

    u x

    = + + + + + + + +

    = + + + + + + + + +

    = ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )

    ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )

    ( )

    535 0.1889 0.0833 0.1889 0.1070 0.2425 0.1374 0.3114 0.0882 0.0625

    0.0606 0.2140 0.0944 0.1667 0.0944 0.2140 0.1212 0.2748 0.0778 0.1406

    0.0

    0 1 2 3 4 5 6 7 8

    3 0 1 2 3 4 5 6 7 8

    4

    u x u x u x u x u x u x u x u x u x

    u x u x u x u x u x u x u x u x u x u x

    u x

    + + + + + + + + +

    = + + + + + + + + +

    = ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )

    ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )

    ( )

    687 0.2425 0.1070 0.1889 0.0833 0.1889 0.1070 0.2425 0.0687 0.2500

    0.0778 0.2748 0.1212 0.2140 0.0944 0.1667 0.0944 0.2140 0.0606 0.3906

    0.0

    0 1 2 3 4 5 6 7 8

    5 0 1 2 3 4 5 6 7 8

    6

    u x u x u x u x u x u x u x u x u x

    u x u x u x u x u x u x u x u x u x u x

    u x

    + + + + + + + + +

    = + + + + + + + + +

    = ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )

    ( )

    882 0.3114 0.1374 0.2425 0.1070 0.1889 0.0833 0.1889 0.0535 0.5625

    0.1000 0.3528 0.1557 0.2748 0.1212 0.2140 0.0944 0.1667 0.0472 0.7656

    0.1

    0 1 2 3 4 5 6 7 8

    7 0 1 2 3 4 5 6 7 8

    8

    u x u x u x u x u x u x u x u x u x

    u x u x u x u x u x u x u x u x u x u x

    u x

    + + + + + + + + += + + + + + + + + +

    = ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )133 0.3998 0.1764 0.3114 0.1374 0.2425 0.1070 0.1889 0.0417 10 1 2 3 4 5 6 7 8u x u x u x u x u x u x u x u x u x+ + + + + + + + +

    (14)

    Write in the form ofAu b= , we have:

    0.9583 0.1889 0.1070 0.2425 0.1374 0.3114 0.1764 0.3998 0.1133

    0.0472 0.8333 0.0944 0.2140 0.1212 0.2748 0.1557 0.3528 0.1000

    0.0535 0.1889 0.9176 0.1889 0.1070 0.2425 0.1374 0.3114 0.0882

    0.0606 0.2140 0.0944 0.8333 0.0944 0.

    A

    =

    2140 0.1212 0.2748 0.0778

    0.0687 0.2425 0.1070 0.1889 0.9167 0.1889 0.1070 0.2425 0.0687

    0.0778 0.2748 0.1212 0.2140 0.0944 0.8333 0.0944 0.2140 0.0606

    0.0882 0.3114 0.1374 0.2425 0.1070 0.1889 0.9167 0.1889 0.0535

    0.1000 0.3528 0

    .1557 0.2748 0.1212 0.2140 0.0944 0.8333 0.0472

    0.1133 0.3998 0.1764 0.3114 0.1374 0.2425 0.1070 0.1889 0.9583

    and

    0

    0.0156

    0.0625

    0.1406

    0.2500

    0.3906

    0.5625

    0.7656

    1.000

    b

    =

    Solve for ( )iu x using Gaussian Elimination, we have:

    ( ) ( ) ( ) ( ) ( )

    ( ) ( ) ( ) ( ) ( )

    0 1 2 3 4

    5 6 7 8 9

    1.2062; 1.0614; 0.9466; 0.8361; 0.7445;

    0.6529; 0.5735; 0.5735; 0.4927; 0.4209;

    u x u x u x u x u x

    u x u x u x u x u x

    = = = = =

    = = = = =

    Now, we plot all the solution that we have obtain thus far on the same graph, as shown inFigure 1.

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    8/37

    Figure 1: Approximation of u(x) given in Problem 1 using different methods: Trapezoidal rule, and

    Composite Simpson rule with m=4, 6, and 8.

    PROBLEM 1DISCUSSION:

    Since there is not exact solution given in the problem, we cant compare the error

    between each method and concluded that which method is superior. However, as morepoints are used in the approximation in a given method, we could expect it approach thetrue solution nonetheless. From the result shown in Figure 1, we can see that the

    Trapezoidal rule only evaluates two points and thus we would expect it is least accurate

    method (assuming that the given solution of the function, Equation (1) is nonlinear). ForComposite Simpsons rule, different number of points was being used and we can see

    that as the number of points used increase, the solution curve become smooth and we can

    expect it approaches the true solution.

    In the process of approximating the integral using different method thereby forming

    different set of linear system, we omitted the error terms associated with each method, as

    mentioned in the formulation. These errors, which is a function of h , the interval size isapproximated to zero if sufficiently small h is used. However, for the Trapezoidal rule,

    the 1h= , hence the error ( )3 "( / 2)h f is considerable large compare to the error from

    the Composite Simpsons rule, ( ) ( ) ( )44 /180b a h f . Thus we could expect the

    result obtained from the trapezoidal rule is away from the rest of the results obtained

    using Composite Simpsons rule, as seen in Figure 1.

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    9/37

    PROBLEM 2:

    Part A. The ( ) ( )1 1m m tridiagonal matrix:

    1 2 0 0

    1 2

    0 0

    0 0 1 2

    A

    =

    (15)

    is involved in the Forward Difference Method to solve the heat equation. For the stability

    of the method we need ( ) 1A < . With 11m= , approximate the eigenvalues of A for

    each of the following:1 1 3

    ; ; .4 2 4

    = = = when is the method stable?

    Part B. The actual eigen values of the matrix A is given by:

    2

    1 4 sin , 1, , 12

    i

    i for i m

    m

    = =

    (16)

    Compare with the approximations in part A, and again, when is the method stable?

    SOLUTION:

    Since A is a symmetric, tridiagonal matrix, to approximate the eigen values in matrix A ,

    QR algorithm is implemented. The QR algorithm is given as follow:

    QR algorithm:

    Step 1: Given square matrix A, form its QR factorization as: 1 1 1A Q R= ;

    Step 2: Define: 1 1 1A R Q= .

    Step 3: Continue this process for 1k :

    1

    k k k

    k k k

    A Q R

    A R Q+

    =

    =

    Step 4: Continue this until the A matrix become diagonal matrix. Or the off diagonal

    terms becomes less then tolerance, say 61 10 .

    As the QR method is slow in convergence, an accelerated method which modified the

    above algorithm is implemented. This method is explained as follow:

    Define:

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    10/37

    1 1

    1 2

    1

    1

    0 0

    0 0

    0 0

    n

    n n

    A

    =

    Step 1: Factorized k kQ R by k n k k A I Q R = ;

    Step 2: Determine 1k k k nA R Q I+ = + ;

    Step 3: When 1n is sufficiently small, set n n = and delete the last row and column of

    A and continue the Step 1 and Step 2 with the smaller matrix.

    For this question, the QR method and accelerated QR method were coded to solve the

    given problem, and the result was then compared with the one obtained using Equation(16).

    Stability issue for forward difference method used in solving heat equation:

    From the textbook, in order for the forward difference method to be stable, the

    requirement is ( ) 1A . ( )A is define as the spectral radius of matrix A and is define

    by ( ) maxA = , where is the eigen value of A . Since the actual eigen values of A

    is given by Equation (16), The condition for stability reduces to determine whether:

    ( )2

    1 1max 1 4 sin 1

    2i m

    iA

    m

    =

    (17)

    Which further simplifies to:

    2

    10 sin , 1, , 1.

    2 2

    i for i m

    m

    =

    (18)

    Since the stability requires that this inequality (18) condition hold as 0h ( h is theinterval size), or equivalently, as m . The fact that:

    2

    lim sin 12m

    i

    m

    =

    (19)

    Substitute Equation (19) into Inequality (18), implies that the stability requirement is:

    10

    2 (20)

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    11/37

    Hence, in this problem, only1 1

    ;4 2

    = = will give stable result but not3

    .4

    =

    Convergence of QR Algorithm:

    While stability issues concerning the accuracy of the forward difference method in

    solving the heat equation, there is a much important issue in solving for the eigen valuesof a tridiagonal matrix using QR algorithm The convergence criteria for this method.

    Let A be real n n and eigen values { }i is given by:

    1 2 0n > > > > (21)

    The iteration will converge to an upper triangular matrix with { }i as diagonal elements.

    Further, ifA is symmetric, as in our case, the sequence { }iA converges to a diagonal

    matrix. Equation (21) requires that in order for QR algorithm to converge, the eigenvalues of matrix A needs to have different magnitude.

    Hence, in this problem, where only 1/ 4= and 3/ 4= converged in the QR algorithm,where 1/ 2= have does not converge to obtain eigen values. By using MATLAB eig()function, we obtained the eigen values for 1/ 2= case, they are in fact repeated eigenvalues, hence no convergence can be guaranteed by using QR algorithm.

    RESULT:

    The QR algorithm is coded in MATLAB, in which the QR factorization process isprovided by the MATLAB function qr().

    For 1/ 4= case:

    Note that the tolerance for convergence is set to 61 10 (the off diagonal terms ofmatrixA ), and the number of iterations used to achieve this tolerance is 188. For this

    tolerance value, the error between the exact solution and the one obtained using QR

    algorithm is calculated, the errors are in the magnitude of 1010 .

    Eigen Values QR Algorithm Exact Solution Error( 1010 )

    1 0.97974648679230 0.97974648680725 0.14948042803553

    2 0.92062676643054 0.92062676641559 0.14945933379806

    3 0.82743036697264 0.82743036697264 0.00001443289932

    4 0.70770750650094 0.70770750650094 0.00002775557562

    5 0.57115741913664 0.57115741913664 0.00000777156117

    6 0.42884258086336 0.42884258086336 0.00000333066907

    7 0.29229249349906 0.29229249349906 0.00000222044605

    8 0.17256963302736 0.17256963302736 0.00000055511151

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    12/37

    9 0.07937323358441 0.07937323358441 0.00000069388939

    10 0.02025351319275 0.02025351319275 0.00000006938894

    For 1/ 2= case:As mentioned earlier, QR algorithm cannot guarantee convergence if the eigen values are

    not of different magnitude. i.e., repeated unsigned eigen values exist, this is the case for

    both 1/ 2= and 1/ 4= . For 1/ 2= , the simple QR algorithm that implemented heredoes not converge. Hence, in this case, the eigen values were calculated using theMATLAB eig(), which uses a much improved QR algorithm (by Wilkinson) to obtain the

    eigen values. The result is shown below and error is computed.

    Eigen Values MATLAB eig() Exact Solution Error ( 1510 )

    1 0.95949297361450 0.95949297361450 0.11102230246252

    2 0.84125353283118 0.84125353283118 0.22204460492503

    3 0.65486073394529 0.65486073394529 0.11102230246252

    4 0.41541501300189 0.41541501300189 0.277555756156295 0.14231483827329 0.14231483827329 0.22204460492503

    6 -0.14231483827329 -0.14231483827329 0.47184478546569

    7 -0.41541501300189 -0.41541501300189 0.16653345369377

    8 -0.65486073394529 -0.65486073394528 0.11102230246252

    9 -0.84125353283118 -0.84125353283118 0.66613381477509

    10 -0.95949297361450 -0.95949297361450 0.00000000000000

    For 3/ 4= case:

    The tolerance for convergence is set to 61 10 (the off diagonal terms of matrixA ), andthe number of iterations used to achieve this tolerance is 195. For this tolerance value, theerror between the exact solution and the one obtained using QR algorithm is calculated,

    the errors are in the magnitude of 1210 .

    Eigen Values QR Algorithm Exact Solution Error( 1210 )

    1 -1.93923946042174 -1.93923946042175 0.00088817841970

    2 -1.76188029924678 -1.76188029924677 0.00444089209850

    3 -1.48229110091793 -1.48229110091793 0.00377475828373

    4 -1.12312251950282 -1.12312251950283 0.00488498130835

    5 -0.71347225740928 -0.71347225740993 0.64248606435058

    6 -0.28652774259007 -0.28652774259007 0.00016653345369

    7 0.12312251950283 0.12312251950283 0.00011102230246

    8 0.48229110091793 0.48229110091793 0.00016653345369

    9 0.76188029924613 0.76188029924677 0.64315219816535

    10 0.93923946042175 0.93923946042175 0.00088817841970

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    13/37

    PROBLEM 2DISCUSSION:

    In this problem, we implemented the QR algorithm to find the eigen values of a

    tridiagonal symmetric sparse matrix that obtain from solving the heat equation using

    forward difference method. There are two important questions addressed here: the

    stability of the approximation using forward difference method to solve the heat equationand the convergence criteria of the simple QR algorithm that we implemented here.

    The first question, concerning the stability issue of the forward difference method insolving the heat equation, does not cause any implementation issue for the QR algorithm

    that we used here. It gives the boundary value for , in which the forward difference

    method is stable in solving the heat equation. This requires that 0 0.5 , as shown inEquation (20). Thus only 1/ 2= and 1/ 4= give a correct solution to the heatequation.

    The second question, which is more of our interest, concerning the convergence criteria

    of the implemented QR algorithm. From literature, the simple form of the OR algorithmwill guarantee convergence in the case where all the eigen values are of differentmagnitude. If there are eigen values that are of same magnitude, the method does not

    guarantee convergence. This is the case in for 3 / 4= and 1/ 2= , in which some ofthe eigen values are same magnitude. In these two cases, only 3/ 4= case givesconvergence result but not 1/ 2= . On the other hand, for 1/ 4= , all the eigen valuesare of different magnitude and thus we could expect convergence in this case, and this is

    in fact the case.

    The accelerated QR algorithm is also implemented in solving this problem, unfortunately

    no convergence obtained for all the cases. For all the cases ( 1/ 2= , 1/ 4= , and

    3/ 4= ), the 1n does not reduce to the tolerance value of6

    1 10

    . So no convergencecan be obtained. As a result, we are not able to see how the accelerated QR algorithm

    converges in fewer steps compare to the simple QR algorithm that we implemented here.

    Nonetheless, we included the code for accelerated QR algorithm for reference. For

    1/ 4= and 3/ 4= , the iterations needed to converge to a tolerance of 61 10 is 188and 195 steps, repectively.

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    14/37

    PROBLEM 3:

    Part A. The deflection of a beam with supported ends subject to uniform loading. Theboundary-value problem governing this physical situation is:

    ( )2

    2

    , 02

    d w S qx

    w x l x ldx EI EI

    = + < < (22)

    with boundary condition ( ) ( )0 0w w l= = .

    Given the beam is a W10-type steel I-beam with the following characteristics:

    Length, 120 ;l in= intensity of uniform, 100 100 /12q lb/ft lb/in.= = ; modulus of

    elasticity, 7 23 10 /E lb in= ; stress at end, 1000S lb= ; central moment of inertia,4625I in= .

    a. Approximately the deflection of the beam every 6 in.

    b. The actual relationship is given by:

    ( ) 1 2 ( )ax axw x c e c e b x l c= + + + (23)

    where4 4 4

    1 27.7042537 10 ; 7.9207462 10 ; 2.3094010 10 ;c c a= = = 3

    4.1666666 10b = ;

    51.5625 10c= . Is the maximum error on the interval within 0.2 in?

    c. State law requires that 0max ( ) 1/ 300x l w x< < < . Does this beam meet state code?

    Part B. A more appropriate representation of the curvature gives the differential equation:

    ( )( ) ( )23/ 2

    2

    21 ' , 0

    2

    d w S qxw x w x l x l

    dx EI EI

    + = + <

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    15/37

    where:

    ( ) ( )

    ( ) ( )

    ( )

    ( ) ( )

    2

    1 2

    2

    2

    1

    2

    1

    2 1 0 02

    1 22

    0 0

    12

    0 0 1 22

    i

    N

    N N

    hh q x q x

    hq x h q x

    A

    hq x

    hq x h q x

    + +

    +

    =

    + +

    and

    ( ) ( )

    ( )

    ( )

    ( ) ( )

    2

    1 1 0

    2

    2

    2

    1

    2

    1

    12

    12

    N

    N N N

    hh r x p x w

    h r x

    b

    h r x

    hh r x p x w

    +

    + +

    =

    + +

    and

    1

    2

    1N

    N

    w

    w

    w

    w

    w

    =

    .

    Compare Equation (22) with Equation (25), we have the following relations:

    ( ) ( ) ( ) ( )0, ,2

    S qxp x q x r x x l

    EI EI= = = (27)

    The linear finite difference method was implemented, with 20N= and 6h= (as requiredby question) and Equation (28) was then solved in MATLAB. On the other hand, in orderto obtain better accuracy, we also solve the same problem with 40N= and 3h= ; inaddition to 60N= and 1h= . All these results are then plotted on the same graph andcompare with the exact solution obtained using Equation (23).

    To study the errors in these methods, the total errors at each point of interest between the

    approximation obtained using finite difference method and the exact solution werecalculated by adding square of the difference at each point using the following equation:

    ( ) ( )

    2

    1

    N

    i iApprox Actuali

    Error w w=

    =

    (29)

    RESULT:

    The calculated deflection of the beam ( )w x is plotted using the linear finite difference

    method for different number of N intervals were obtained and plotted in Figure 2

    (N=20) , Figure 3 (N=40) and Figure 4 (N=60). Compared to the exact solution from

    Equation (23), the error is in the order of 310 inch.

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    16/37

    Figure 2: Solution obtained from solving the linear BVP problem using nonlinear finite difference

    method, with N=20.

    Figure 3: Solution obtained from solving the linear BVP problem using nonlinear finite difference

    method, with N=40.

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    17/37

    Figure 4: Solution obtained from solving the linear BVP problem using nonlinear finite difference

    method, with N=60.

    The deflection of the beam given by Equation (23) has values from negative to positive,which does not make any physical sense. Since the given load is a uniform load across

    the beam, and the two end where fixed at the boundary value (which is zero), the

    deflection should not have values fluctuated between positive and negative values. Hence,there must be a mistake in the given Equation (23). Nonetheless, Equation (23) is used to

    calculate the error. We can see that the exact deflection plotted using Equation (23) is off

    by 31 10 inch. If we added this value in Equation (23) to correct the deflection formula,

    the errors shown in all the figures here were reduced to 61 10 inch.

    Next, we will approximate the nonlinear equation of the deflection formula given in

    Equation (24) by using nonlinear finite difference method and compare with the result

    that we obtained in this section.

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    18/37

    Part B. The nonlinear second-order boundary-value problem of the form:

    ( )" , , ' , , ( ) , ( )y f x y y a x b y a y b = = = (30)

    can be solved using similar approach as the linear finite difference method (so called

    Nonlinear finite difference method). However, since the resulting system of equation isnot linear, a iterative process was then implemented to determine the solution.

    Equation (30), when solve using centered-difference method, a N N nonlinear systemcan be obtained as follow:

    2 21 2 1 1

    2 31 2 3 2 2

    2 22 1 1 1

    2 11

    2 , , 0,2

    2 , , 0,2

    2 , , 0,2

    2 , , 02

    N NN N N N N

    NN N N N

    ww w h f x w

    h

    ww w w h f x w

    h

    w ww w w h f x w

    h

    ww w h f x w

    h

    + + =

    + + =

    + + =

    + + =

    (31)

    Newtons method for nonlinear system is used to approximate the solution to this system.

    The solution is iterated and will converge to the solution of the system provided that theinitial approximation of the solution is close to the solution and the Jacobian matrix for

    the system is nonsingular. The Jacobian of the system of Equation (31) is tridiagonal withthe entry expressed as:

    ( )

    1 1'

    2 1 11

    1 1'

    1 , , , 1 2, , ,2 2

    , , 2 , , , 1, , ,2

    1 , , , 1 1,2 2

    i iy i i

    i iN y i iij

    i iy i i

    w whf x w for i j and j N

    h

    w wJ w w h f x w for i j and j N

    h

    w whf x w for i j and j

    h

    +

    +

    +

    + = =

    = + = =

    = + =

    , 1,N

    (32)

    where0

    w = and1N

    w + = .

    Newton method then required that at each iteration, the N N nonlinear system besolved for 1 2, , , Nv v v , since:

    1 , 1,2, ,k ki i iw w v for each i N = + = (33)

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    19/37

    Following the steps, re-write Equation (24) in the following form:

    ( )( ) ( )2 3/ 2

    2

    21 ' , 0

    2

    d w S qxw x w x l x l

    dx EI EI

    = + + <

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    20/37

    Figure 5: Solution obtained from solving the nonlinear BVP problem using nonlinear finite

    difference method, with N=20.

    Figure 6: Solution obtained from solving the nonlinear BVP problem using nonlinear finite

    difference method, with N=40.

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    21/37

    Figure 7: Solution obtained from solving the nonlinear BVP problem using nonlinear finite

    difference method, with N=60.

    Figure 8: Comparing the error for different number of interval N used in the approximation, for

    both linear and nonlinear finite difference method.

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    22/37

    PROBLEM 3DISCUSSION:

    From Figure 5, Figure 6, and Figure 7, we can see that there is no significant difference in

    the solution obtained using different number of N. The errors in all three cases ( 20N= ,

    40N= , 60N= ) are all in the order of 310 . However, if we compare the errors in the

    same plot, as shown in Figure 8, we can see that using higher number of intervals reducethe errors between the approximated deflection and the actual deflection. This is same for

    both either the linear equation of Equation (22) is used or the nonlinear equation of

    Equation (24) is used.

    As we mention before, as a beam with uniform loading and two fixed end, the deflections

    ( )w x cannot change its value from negative value to positive value. It should be either

    all positive values or all negative values (depending on where to measure from: -y or y in

    Figure 9 ).

    Figure 9: The beam deflection mode due to uniform distributed load with two fix boundary.

    Hence, the actual deflection given by Equation (23) does not have any physical meaning

    as the value changes from negative to positive for difference value of x .

    On the other hand, we do not observed any significant improvement when the nonlinearsecond order equation of (24) is used to approximate the actual deflection over the linear

    second order equation of (22). The errors compare to the actual deflection equation are

    same in both cases. Hence, Equation (22) is adequate to approximate the deflection whileit is less computational expensive.

    Last, let us answer the question: State law requires that 0max ( ) 1/ 300x l w x< < < , does thebeam deflection meet the requirement? From our results, we see that the maximum

    deflection (at 60x inch= ) is approximately 31.3 10 inch . Compare to 1/300 inch 33.333 10 inch

    = , we can safely say that the beam deflection met the state law.

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    23/37

    CONCLUSION:

    In this project, we investigate the numerical methods involved in: solving system of

    linear equations; solving eigen values of a tridiagonal symmetric matrix resulting from

    solving the heat equation using the forward difference method; and solving second order

    boundary value problem (both linear and nonlinear) using finite difference method.

    We solve the linear system of equations that result from approximating a integral using

    Trapezoidal rule and Composite Simpsons rule. For Composite Simpson rule, differentnumber of points is used. We then solve the linear system of equations using Gaussian

    Elimination method to obtain the approximated solution of the given integral. The final

    result is shown graphically.

    In solving the eigen values problem, we study the stability of the forward difference

    method and also study the convergence criteria for the QR algorithm. The stability

    required that 0 0.5 while the convergence criteria required that all the eigen values

    are of different values. We then show that the QR algorithm only converges for the casewhere 1/ 4= and 3/ 4= , the iterations needed to converge to a tolerance of 61 10 is188 and 195 steps. On the other hand, for 1/ 2= , convergence cannot achieve sincethe eigen values are not of different magnitude.

    In the last problem, we solve a beam deflection problem by solving the linear andnonlinear deflection model of the beam. The deflection problem form a second order

    boundary value problem and thus can be solved by using the finite difference method.

    The linear and nonlinear finite difference method is implemented to obtain the beam

    deflection at different beams locations. The result was then compare with the actualbeam deflection, which is given as a formula. Although there is doubt on the actual beam

    deflection formula (as discussed in problem 3 discussion), we used it to calculate theerror between the one obtained from finite difference method and the actual beam

    deflection equation. It is then show that the error is of the order of 31 10 . Finally, we

    also determine that the maximum beam deflection is about 31.3 10 inch , and thisdeflection value meet the state law, which required the maximum deflection to be within

    33.333 10 inch .

    In conclusion, this project gives us an in depth study of each of the numerical methods

    implemented to solve the problems. It also shows us the advantages and limitations, the

    computational cost, and the accuracy of each method.

    Finally, the code(s) implemented in this project in attached as appendix for reference.

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    24/37

    D: \ usr \ l l ee3\ Cour seWor ks\ MTH538- Numer i cal Anal y. . . \ Pr obl em1_n4. m Page 1Apr i l 20, 2006 12: 54: 17 PM

    % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -% Name: Leng- Feng Lee% Cour se: MTH 538 Numer i cal Anal ysi s% Fi nal Pr oj ect - Pr obl em 1% Descr i pt i on: Appr oxi mat e i nt egr al usi ng Tr apezoi dal r ul e, Composi t e% Si mpson r ul e wi t h n=4, 6, 8. Resul t s pl ot t ed% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -c l ear al lcl ose al lcl c

    % m = 1, sol ve usi ng Trapezoi dal Rul e.x0=l i nspace( 0, 1, 2) ;t 0=l i nspace( 0, 1, 2) ;f or i =1: 1: l engt h( x0) , UO( i ) =0. 5*exp( abs( x0( i ) - t 0( 1) ) ) ; U1( i ) =0. 5*exp( abs( x0( i ) - t 0( 2) ) ) ;end

    A0=[ UO' U1' ] - eye(2) % For m Au = bb0=( - x0. 2) '

    UU0=A0\ b0 %

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    25/37

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    26/37

    D: \ usr \ l l ee3\ Cour seWor ks\ MTH538- Numer i cal Ana. . . \ QR_Al gor i t hm2. m Page 1Apr i l 20, 2006 12: 52: 47 PM

    % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -% Name: Leng- Feng Lee% Cour se: MTH 538 Numer i cal Anal ysi s% Fi nal Pr oj ect- Pr obl em 2% Descri pt i on: Sol vi ng Ei gen val ues usi ng QR Al gor i t hm.% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -cl ose al lc l ear al lcl c

    al pha = 3/ 4;n=10;x=1: 1: 10;x=x. / xa = ( 1- 2*al pha) *x; % Val ue on t he di agonalb = al pha*x( 1: 9) ; % Val ue on t he of f di agonalc = al pha*x( 1: 9) ;

    %Cr eat e the t r i di agonal mat r i x:

    A=di ag( a) + di ag( al pha*ones( ( n- 1) , 1) , 1) + di ag( al pha*ones( n- 1, 1) , - 1)ei g( A)Max =1000;

    TOL=1e- 6;i nd=1;f or k=1: 1: Max, supi nd=1; subi nd=1; i nd=1; %[ Q, R] = qr ( A- di ag( a) ) ; [ Q, R] = qr ( A) ; A=R*Q;

    t emp=si ze( A) ; f or i =1: 1: t emp( 1, 1) , f or j =1: 1: t emp( 1, 1) , i f ( i == j && i < n) % Supper di agonal of A supA( supi nd) =A( i , j +1) ; supi nd=supi nd+1; end i f ( i == j && i > 1) % Subdi agonal of A subA( subi nd) =A( i , j - 1) ; subi nd=subi nd+1; end

    end

    end k % Check f or conver gence: i f ( normVec(subA)

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    27/37

    D: \ usr \ l l ee3\ Cour seWor ks\ MTH538- Numer i cal Ana. . . \ QR_Al gor i t hm2. m Page 2Apr i l 20, 2006 12: 52: 47 PM

    end

    sol =di ag( A) ; % Sol ut i on%sol =ei g( A) ; % Sol ut i on f or al pha = 1/ 2% sol 2=[ sol ( 1: 4, 1) ;% sol (7, 1) ;% sol (9, 1) ;% sol ( 10, 1) ;% sol (8, 1) ;% sol (6, 1) ;% sol ( 5, 1) ] ; % For al pha =3/ 4 ar r ange pr oper l y t o cal cul at e t he er r or .% Cal cul at e the exact ei genval ues usi ng t he f omul a:i =10: - 1: 1;t =si n( pi *i / ( 2*( n+1) ) ) ;l amda=1- 4*al pha*t . 2;

    %Cal cul ate t he er r or:Er r or=( ( sol 2' - l amda) . 2) . 0. 5;

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    28/37

    D: \ usr\ l l ee3\ Cour seWor ks\ MTH538- N. . . \ Accel er at ed_QR_Al gor i t hm. m Page 1Apr i l 20, 2006 12: 53: 23 PM

    % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -% Name: Leng- Feng Lee% Cour se: MTH 538 Numer i cal Anal ysi s% Cour se Pr oj ect - Pr obl em 2% Descr i pt i on: Fi nd ei gen val ue of a squar e mat r i x usi ng Accel er at ed% OR Al gor i t hm.% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    cl ose al lc l ear al lcl c

    % For m t he Tr i di agonal mat r i x:al pha = . 5;n=10;x=1: 1: 10;x=x. / x;a = ( 1- 2*al pha) *x; % Val ue on t he di agonalb =al pha*x( 1: 9) ; % Val ue on t he of f di agonal

    A=gal l er y( ' t r i di ag' , b, a, b) ;

    ei g( A)Max =50;

    TOL=1e- 3;

    f or k=1: 1: Max, supi nd=1; subi nd=1; i nd=1; [ Q, R] = qr ( A) ; A=R*Q;

    % Ext r act t he supper di agonal and subdi agonal of A

    f or i =1: 1: n, f or j =1: 1: n, i f ( i == j && i < n) % Supper di agonal of A supA( supi nd) =A( i , j +1) ; supi nd=supi nd+1; end i f ( i == j && i > 1) % Subdi agonal of A subA( subi nd) =A( i , j - 1) ; subi nd=subi nd+1; end

    i f ( i ==j ) ,

    Ei genVal ues( i nd) = A( i , j ) ; i nd=i nd+1; end end end

    % Check f or conver gence: i f ( nor mVec( subA)

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    29/37

    D: \ usr\ l l ee3\ Cour seWor ks\ MTH538- N. . . \ Accel er at ed_QR_Al gor i t hm. m Page 2Apr i l 20, 2006 12: 53: 23 PM

    k=Max; end k %pauseend

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    30/37

    D: \ usr \ l l ee3\ Cour seWor ks\ MTH538- Numer i cal An. . . \ Pr obl em3_Pr ob7. m Page 1Apr i l 20, 2006 12: 54: 54 PM

    % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -% Name: Leng- Feng Lee% Cour se: MTH 538 Numer i cal Anal ysi s% Fi nal Pr oj ect- Pr obl em 3 Par t A% Descr i pt i on: Sol ve l i near second or der PDE usi ng Li near Fi ni t e Met hod.% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    cl ose al lc l ear al lcl c

    % NonLi near Fi nt e- Di f f er ence Met hod% Sol ve t he f ol l owi ng Nonl i near Second order ODE:%% y" = p( x) *y' + q( x) *y + r ( x) , a 1) , subdi ag( i - 1) =- 1- ( h/ 2) *p_x;

    end

    % Cal cul ate the b vect or i n Ay=b: i f ( i == 1) , bvec( i ) = - h 2*r _x + ( 1+( h/ 2) *p_x) *al pha;

    el sei f ( i == N- 1) ,

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    31/37

    D: \ usr \ l l ee3\ Cour seWor ks\ MTH538- Numer i cal An. . . \ Pr obl em3_Pr ob7. m Page 2Apr i l 20, 2006 12: 54: 54 PM

    bvec( i ) =- h 2*r _x + ( 1- ( h/ 2) *p_x) *bet a;el se

    bvec( i ) =- h 2*r _x; endend

    % Now f orm t he t r i di agonal Spar se mat r i x A:A=gal l er y( ' t r i di ag' , subdi ag, di ag, supdi ag) ;

    % Cal cul at e w usi ng Gaussi an El i mi nat i on:w=A\ bvec'wf ul l =[ 0 w' 0] ;

    %Cr eate t he act ual w( x) based on Eqn.c1=7. 7042537e4;c2=7. 9207462e4;a1=2. 3094010e- 4;b1=- 4. 1666666e- 3;

    d1=- 1. 5625e5;

    wact ual = c1*exp( a1*x) + c2*exp( - a1*x) + b1*( x- b) . *x + d1 +1e- 3;% wf ul l - wact ualf or i =1: l engt h( wf ul l ) , Er r or ( i ) = ( ( wf ul l ( i ) - wact ual ( i ) ) 2) 0. 5; %Cal cul at e t he er r or at each poi nt send

    %Pl ot t i ng t he r esul t :f i gur e( 1)subpl ot ( 2, 1, 1) ;pl ot ( x, wf ul l , ' Li neWi dt h' , 2) ; hol d onpl ot ( x, wact ual , ' k' , ' Li neWi dt h' , 2) ;

    pl ot ( x, wf ul l , ' *b' ) ;pl ot ( x, wact ual , ' *k' ) ;xl abel ( ' x pos i t i on' , ' f ontwei ght ' , ' bol d' ) ;yl abel ( ' w( x) def l ect i on, i nch' , ' f ont wei ght ' , ' bol d' ) ;t i t l e( ' Appr oxi mat e w( x) usi ng Li near Fi ni t e Di f f er ence appr oach ( N=60) ' , ' f ont wei ght ' , ' bol d' ) ;l egend( ' Fi ni t e Di f f er ence Met hod' , ' Act ual def l ect i on gi ven by Equat i on' ) ;gr i d onsubpl ot ( 2, 1, 2) ;pl ot ( x, Er r or , ' Li neWi dt h' , 2) ; hol d onpl ot ( x, Er r or , ' *b' ) ;xl abel ( ' x pos i t i on' , ' f ontwei ght ' , ' bol d' ) ;yl abel ( ' Er r or , ( i nch) ' , ' f ontwei ght ' , ' bol d' ) ;

    gr i d on

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    32/37

    D: \ usr \ l l ee3\ Cour seWor ks\ MTH538- Numer i cal An. . . \ Pr obl em3_Pr ob6. m Page 1Apr i l 20, 2006 12: 55: 35 PM

    % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -% Name: Leng- Feng Lee% Cour se: MTH 538 Numer i cal Anal ysi s% Fi nal Pr oj ect- Pr obl em 3 Par t A% Descr i pt i on: Sol ve l i near second or der PDE usi ng Li near Fi ni t e Met hod.% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    cl ose al lc l ear al lcl c

    % NonLi near Fi nt e- Di f f er ence Met hod:% Sol ve t he f ol l owi ng Nonl i near Second order ODE:%% y" = f ( x, y, y' ) , a

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    33/37

    D: \ usr \ l l ee3\ Cour seWor ks\ MTH538- Numer i cal An. . . \ Pr obl em3_Pr ob6. m Page 2Apr i l 20, 2006 12: 55: 35 PM

    MaxI t er = 50;% Sol ve the Aw = b syst em, now f orm t he A mat r i x and b vect or :f or j =1: 1: MaxI t er ,

    f or i =1: 1: N- 1, xi = a + i *h;

    % Appr oxi mate w' : i f ( i ==1) , t emp = ( w( i +1) - al pha ) / ( 2*h) ; el sei f ( i ==N- 1) , t emp = ( bet a - w( i - 1) ) / ( 2*h); el se

    t emp = ( w( i +1) - w( i - 1) ) / ( 2*h) ; end

    % Cal cul ate t he di agonal t er m: di ag( i ) = 2 + h 2*f y(xi , w( i ) , t emp) ;

    % Cal cul ate the supper di agonal t er m: i f ( i < N- 1) , supdi ag( i ) = - 1 + ( h/ 2) *f yp( xi , w( i ) , t emp) ;

    end

    % Cal cul ate the sub di agonal t er m: i f ( i > 1) , subdi ag( i - 1) = - 1 - ( h/ 2) *f yp( xi , w( i ) , t emp) ;

    end

    % Cal cul ate the b vect or i n Ay=b: i f ( i == 1) , bvec( i ) = - ( 2*w( i ) - w( i +1) - al pha + h 2*f f ( xi , w( i ) , t emp) ) ;

    el sei f ( i == N- 1) , bvec(i ) = - ( 2*w( i ) - w( i - 1) - bet a + h 2*f f ( xi , w( i ) , t emp) ) ; el se bvec(i ) = - ( 2*w( i ) - w( i +1) - w( i - 1) + h 2*f f ( xi , w( i ) , t emp) ) ; endend

    % Now f orm t he t r i di agonal Spar se mat r i x A:A=gal l er y( ' t r i di ag' , subdi ag, di ag, supdi ag) ;

    % Cal cul at e v usi ng Gaussi an El i mi nat i on:v=A\ bvec'

    j% updat i ng w:w=w+v' ;

    % Check f or conver gencei f normVec( v) < TOL, j = MaxI t er ;end

    end

    wf ul l =[ 0 w 0] ;

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    34/37

    D: \ usr \ l l ee3\ Cour seWor ks\ MTH538- Numer i cal An. . . \ Pr obl em3_Pr ob6. m Page 3Apr i l 20, 2006 12: 55: 35 PM

    %Cr eate t he act ual w( x) based on Eqn.x=l i nspace(0, 120, N+1) ;c1 = 7. 7042537e4;c2 = 7. 9207462e4;a1 = 2. 3094010e- 4;b1 = - 4. 1666666e- 3;d1 = - 1. 5625e5;

    wact ual = c1*exp( a1*x) + c2*exp( - a1*x) + b1*( x- b) . *x + d1 ; %+1e- 3;%Cal cul at i ng t he er r or :f or i =1: l engt h( wf ul l ) , Er r or ( i ) = ( ( wf ul l ( i ) - wact ual ( i ) ) 2) 0. 5; %Cal cul at e t he er r or at each poi nt send

    %Pl ot t i ng t he r esul t :f i gur e( 1)subpl ot ( 2, 1, 1) ;pl ot ( x, wf ul l , ' Li neWi dt h' , 2) ; hol d on

    pl ot ( x, wact ual , ' k' , ' Li neWi dt h' , 2) ;pl ot ( x, wf ul l , ' *b' ) ;pl ot ( x, wact ual , ' *k' ) ;xl abel ( ' x pos i t i on' , ' f ontwei ght ' , ' bol d' ) ;yl abel ( ' w( x) def l ect i on, i nch' , ' f ont wei ght ' , ' bol d' ) ;t i t l e( ' Appr oxi mat e w( x) usi ng Nonl i near Fi ni t e Di f f er ence appr oach ( N=60) ' , ' f ont wei ght ' ,' bol d' ) ;l egend( ' Nonl i near Fi ni t e Di f f er ence Met hod' , ' Act ual def l ect i on gi ven by Equat i on' ) ;gr i d onsubpl ot ( 2, 1, 2) ;pl ot ( x, Er r or , ' Li neWi dt h' , 2) ; hol d onpl ot ( x, Er r or , ' *b' ) ;xl abel ( ' x pos i t i on' , ' f ontwei ght ' , ' bol d' ) ;

    yl abel ( ' Er r or , ( i nch) ' , ' f ontwei ght ' , ' bol d' ) ;gr i d on

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    35/37

    D: \ usr \ l l ee3\ CourseWorks\ MTH538- Numer i cal Anal ys i s I I \ Pro. . . \ f f . m Page 1Apr i l 20, 2006 12: 56: 31 PM

    f uncti on f out = f f ( xi , wi , wi p)

    %Equat i on Coef f i ci ent s:S=1000; %l bE=3e7; %l b/ i n 2q=100/ 12; %l b/ f t - > conver t t o l b/ i nI =625; %i n 4a=0;b=120;al pha=0;bet a=0;

    t emp1 = ( 1 + wi p 2) ( 3/ 2) ;t emp2 = ( ( S*wi ) / ( E*I ) + q*xi *( xi - b) / ( 2*E*I ) ) ;

    f out = t emp1*t emp2;

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    36/37

    D: \ usr \ l l ee3\ CourseWorks\ MTH538- Numer i cal Anal ys i s I I \ Pro. . . \ f y. m Page 1Apr i l 20, 2006 12: 56: 47 PM

    f uncti on f y = f _y( xi , wi , wi p)

    %Equat i on Coef f i ci ent s:S=1000; %l bE=3e7; %l b/ i n 2q=100/ 12; %l b/ f t - > conver t t o l b/ i nI =625; %i n 4

    % t emp1 = 3*wi p*% t emp2 = ( ( S*wi ) / ( E*I ) + q*xi *( xi - b) / ( 2*E*I ) ) ;

    f y = ( S/ ( E*I ) ) *( 1 + wi p 2) ( 3/ 2) ;

  • 8/10/2019 LengFengLee_MTH538ProjectReport

    37/37

    D: \ usr \ l l ee3\ CourseWorks\ MTH538- Numer i cal Anal ys i s I I \ Pr . . . \ f yp. m Page 1Apr i l 20, 2006 12: 57: 08 PM

    f unct i on f yp = f _yp( xi , wi , wi p)

    %Equat i on Coef f i ci ent s:S=1000; %l bE=3e7; %l b/ i n 2q=100/ 12; %l b/ f t - > conver t t o l b/ i nI =625; %i n 4a=0;b=120;al pha=0;bet a=0;

    t emp1 = 3*wi p*( 1+wi p 2) ( 1/ 2) ;t emp2 = ( ( S*wi ) / ( E*I ) + q*xi *( xi - b) / ( 2*E*I ) ) ;

    f yp = t emp1*t emp2;