43
COMPUTATIONAL METHODS & STATISTICS MTH 2212 -2011/2012 SEM 1 LECTURER DR ZAHARAH WAHID EXT 4514, ROOM E1-4-8- 13 1

Lecture Note 10 math 4

Embed Size (px)

DESCRIPTION

math 4 statistic

Citation preview


  • COMPUTATIONAL METHODS
    &
    STATISTICS
    MTH 2212 -2011/2012 SEM 1

    LECTURER

    DR ZAHARAH WAHID

    EXT 4514, ROOM E1-4-8-13

    *

    *

  • *

    Gauss-Siedel Method

    Commonly used iterative method

    Employs initial guesses & then iterates

    to obtain estimate of the solutions

    *

  • Gauss-Seidel Method

    Advantages of the Gauss-Seidel Method

    Algorithm for the Gauss-Seidel Method

    Pitfalls of the Gauss-Seidel Method

    *

  • Gauss-Seidel Method

    An iterative method.

    Basic Procedure:

    Algebraically solve each linear equation for xi

    Assume an initial guess solution array

    Solve for each xi and repeat

    Use absolute relative approximate error after each iteration to check if error is within a pre-specified tolerance.

    *

    *

  • Gauss-Seidel Method

    Why?

    The Gauss-Seidel Method allows the user to control round-off error.

    Elimination methods such as Gaussian Elimination and LU Decomposition are prone to prone to round-off error.

    Also: If the physics of the problem are understood, a close initial guess can be made, decreasing the number of iterations needed.

  • Gauss-Seidel Method

    Algorithm

    A set of n equations and n unknowns:

    . .

    . .

    . .

    If: the diagonal elements are non-zero

    Rewrite each equation solving for the corresponding unknown

    ex:

    First equation, solve for x1

    Second equation, solve for x2

    *

  • Gauss-Seidel Method

    Algorithm

    Rewriting each equation

    From Equation 1

    From equation 2

    From equation n-1

    From equation n

    *

  • Gauss-Seidel Method

    Algorithm

    General Form of each equation

    *

  • *

    If the diagonal elements are all non-zero then:

  • *

    With an initial guess of

  • Gauss-Seidel Method

    Algorithm

    General Form for any row i

    How or where can this equation be used?

    Particularly well suited for large numbers of equations

    *

  • Gauss-Seidel Method

    Solve for the unknowns

    Assume an initial guess for [X]

    Use rewritten equations to solve for each value of xi.

    Important: Remember to use the most recent value of xi. Which means to apply values calculated to the calculations remaining in the current iteration.

    *

  • Gauss-Seidel Method

    Calculate the Absolute Relative Approximate Error

    So when has the answer been found?

    The iterations are stopped when the absolute relative approximate error is less than a prespecified tolerance for all unknowns.

    *

    *

  • Example: Surface Shape Detection

    To infer the surface shape of an object from images taken of a surface from three different directions, one needs to solve the following set of equations

    The right hand side values are the light intensities from the middle of the images, while the coefficient matrix is dependent on the light source directions with respect to the camera. The unknowns are the incident intensities that will determine the shape of the object.

    Find the values of x1, x2, and x3 use the Gauss-Seidel method.

    *

  • Example: Surface Shape Detection

    The system of equations is:

    Initial Guess:

    Assume an initial guess of

    *

  • Example: Surface Shape Detection

    Rewriting each equation

    *

  • Example: Surface Shape Detection

    Iteration 1

    Substituting initial guesses into the equations

    *

  • Example: Surface Shape Detection

    At the end of the first iteration

    The maximum absolute relative approximate error is 101.28%

    *

  • Example: Surface Shape Detection

    Iteration 2

    Using

    *

  • Example: Surface Shape Detection

    Finding the absolute relative approximate error for the second iteration

    At the end of the first iteration

    The maximum absolute relative approximate error is 197.49%

    *

  • *

    ERROR

    Perfect accuracy in most computational

    processes is impossible

    Error = true value- approximate value

    Absolute error = |true value- approximate value|

    The relative error is a measure of the error in relation to the size of

    true being sought

  • *

    ERROR

  • Example: Surface Shape Detection

    Repeating more iterations, the following values are obtained

    Notice: The absolute relative approximate errors are not decreasing.

    *

    Iterationx1x2x3123456 1058.62117.0 4234.88470.1 169423388899.055150.00149.99150.00149.99150.00 1062.72112.9 4238.98466.0 169463388499.059150.30149.85150.07149.96150.01783.81 803.982371.9 3980.58725.7 16689101.28197.49133.90159.59145.62152.28
  • Gauss-Seidel Method: Pitfall

    What went wrong?

    Even though done correctly, the answer is not converging to the correct answer

    This example illustrates a pitfall of the Gauss-Siedel method: not all systems of equations will converge.

    Is there a fix?

    One class of system of equations always converges: One with a diagonally dominant coefficient matrix.

    Diagonally dominant: [A] in [A] [X] = [C] is diagonally dominant if:

    for all i and

    for at least one i

    *

  • Gauss-Seidel Method: Pitfall

    Diagonally Dominant: In other words.

    For every row: the element on the diagonal needs to be equal than or greater than the sum of the other elements of the coefficient matrix

    For at least one row: The element on the diagonal needs to be greater than the sum of the elements.

    What can be done? If the coefficient matrix is not originally diagonally dominant, the rows can be rearranged to make it diagonally dominant.

    *

  • Example: Surface Shape Detection

    Examination of the coefficient matrix reveals that it is not diagonally dominant and cannot be rearranged to become diagonally dominant

    This particular problem is an example of a system of linear equations that cannot be solved using the Gauss-Seidel method.

    Other methods that would work:

    1. Gaussian elimination2. LU Decomposition

    *

  • Gauss-Seidel Method

    The Gauss-Seidel Method can still be used

    The coefficient matrix is not diagonally dominant

    But this is the same set of equations used in example #2, which did converge.

    If a system of linear equations is not diagonally dominant, check to see if rearranging the equations can form a diagonally dominant matrix.

    *

  • Gauss-Seidel Method

    Not every system of equations can be rearranged to have a diagonally dominant coefficient matrix.

    Observe the set of equations

    Which equation(s) prevents this set of equation from having a diagonally dominant coefficient matrix?

    *

  • Gauss-Seidel Method: Example 2

    Given the system of equations

    With an initial guess of

    The coefficient matrix is:

    Will the solution converge using the Gauss-Siedel method?

    *

  • Gauss-Seidel Method: Example 2

    Checking if the coefficient matrix is diagonally dominant

    The inequalities are all true and at least one row is strictly greater than:

    Therefore: The solution should converge using the Gauss-Siedel Method

    *

  • Gauss-Seidel Method: Example 2

    Rewriting each equation

    With an initial guess of

    *

  • Gauss-Seidel Method: Example 2

    The absolute relative approximate error

    The maximum absolute relative error after the first iteration is 100%

    *

    *

  • Gauss-Seidel Method: Example 2

    After Iteration #1

    Substituting the x values into the equations

    After Iteration #2

    *

  • Gauss-Seidel Method: Example 2

    Iteration #2 absolute relative approximate error

    The maximum absolute relative error after the first iteration is 240.62%

    This is much larger than the maximum absolute relative error obtained in iteration #1. Is this a problem?

    *

  • Gauss-Seidel Method: Example 2

    Repeating more iterations, the following values are obtained

    The solution obtained

    is close to the exact solution of

    *

    Iterationa1a2a31234560.500000.146790.742750.946750.991770.9991967.662240.6280.2321.5474.53940.742604.9003.71533.16443.02813.00343.0001100.0031.88717.4094.50120.822400.110003.09233.81183.97083.99714.00014.000167.66218.8764.00420.657980.074990.00000
  • Gauss-Seidel Method: Example 3

    Given the system of equations

    With an initial guess of

    Rewriting the equations

    *

  • Gauss-Seidel Method: Example 3

    Conducting six iterations, the following values are obtained

    The values are not converging.

    Does this mean that the Gauss-Seidel method cannot be used?

    *

    Iterationa1A2a312345621.000196.151995.0201492.03641052.057910595.238110.71109.83109.90109.89109.890.8000014.421116.021204.6121401.2272105100.0094.453112.43109.63109.92109.8950.680462.304718.1476364.81441054.865310698.027110.96109.80109.90109.89109.89
  • *

  • Gauss-Seidel Method: Example 3

    Given the system of equations

    With an initial guess of

    Rearrange the equations

    *

  • Gauss-Seidel Method:example2

    Iteration #1

    With an initial guess of

    *

  • Gauss-Seidel Method: Example 4

    Rewriting the equations

    *

    Relaxation

  • Gauss-Seidel Method: Example 4

    Rewriting the equations

    *

  • Gauss-Seidel Method: cont..

    Iteration #1

    *

    1

    1

    3

    13

    2

    12

    1

    11

    ...

    b

    x

    a

    x

    a

    x

    a

    x

    a

    n

    n

    =

    +

    +

    +

    +

    2

    3

    23

    2

    22

    1

    21

    ...

    b

    x

    a

    x

    a

    x

    a

    x

    a

    n

    2n

    =

    +

    +

    +

    +

    n

    n

    nn

    n

    n

    n

    b

    x

    a

    x

    a

    x

    a

    x

    a

    =

    +

    +

    +

    +

    ...

    3

    3

    2

    2

    1

    1

    11

    1

    3

    13

    2

    12

    1

    1

    a

    x

    a

    x

    a

    x

    a

    c

    x

    n

    n

    -

    -

    -

    =

    K

    K

    nn

    n

    n

    n

    n

    n

    n

    n

    n

    n

    n

    n

    n

    n

    n

    n

    n

    n

    n

    n

    n

    n

    a

    x

    a

    x

    a

    x

    a

    c

    x

    a

    x

    a

    x

    a

    x

    a

    x

    a

    c

    x

    a

    x

    a

    x

    a

    x

    a

    c

    x

    1

    1

    ,

    2

    2

    1

    1

    1

    ,

    1

    ,

    1

    2

    2

    ,

    1

    2

    2

    ,

    1

    1

    1

    ,

    1

    1

    1

    22

    2

    3

    23

    1

    21

    2

    2

    -

    -

    -

    -

    -

    -

    -

    -

    -

    -

    -

    -

    -

    -

    -

    -

    =

    -

    -

    -

    -

    =

    -

    -

    -

    =

    K

    K

    K

    K

    M

    M

    M

    K

    K

    11

    1

    1

    1

    1

    1

    a

    x

    a

    c

    x

    n

    j

    j

    j

    j

    =

    -

    =

    22

    2

    1

    2

    2

    2

    a

    x

    a

    c

    x

    j

    n

    j

    j

    j

    =

    -

    =

    1

    ,

    1

    1

    1

    ,

    1

    1

    1

    -

    -

    -

    =

    -

    -

    -

    -

    =

    n

    n

    n

    n

    j

    j

    j

    j

    n

    n

    n

    a

    x

    a

    c

    x

    nn

    n

    n

    j

    j

    j

    nj

    n

    n

    a

    x

    a

    c

    x

    =

    -

    =

    1

    =

    +

    +

    =

    +

    +

    =

    +

    +

    3

    3

    33

    2

    32

    1

    31

    2

    3

    23

    2

    22

    1

    21

    1

    3

    13

    2

    12

    1

    11

    b

    x

    a

    x

    a

    x

    a

    b

    x

    a

    x

    a

    x

    a

    b

    x

    a

    x

    a

    x

    a

    33

    2

    32

    1

    31

    3

    3

    22

    3

    23

    1

    21

    2

    2

    11

    3

    13

    2

    12

    1

    1

    a

    x

    a

    x

    a

    b

    x

    a

    x

    a

    x

    a

    b

    x

    a

    x

    a

    x

    a

    b

    x

    -

    -

    =

    -

    -

    =

    -

    -

    =

    33

    1

    2

    32

    1

    1

    31

    3

    1

    3

    22

    3

    23

    1

    1

    21

    2

    1

    2

    11

    3

    13

    2

    12

    1

    1

    1

    a

    x

    a

    x

    a

    b

    x

    a

    x

    a

    x

    a

    b

    x

    a

    x

    a

    x

    a

    b

    x

    i

    i

    i

    i

    i

    i

    i

    i

    i

    +

    +

    +

    +

    +

    +

    -

    -

    =

    -

    -

    =

    -

    -

    =

    =

    0

    0

    0

    3

    2

    1

    x

    x

    x

    .

    ,

    ,

    2

    ,

    1

    ,

    1

    n

    i

    a

    x

    a

    c

    x

    ii

    n

    i

    j

    j

    j

    ij

    i

    i

    K

    =

    -

    =

    =

    n

    -

    n

    2

    x

    x

    x

    x

    1

    1

    M

    100

    x

    x

    x

    new

    i

    old

    i

    new

    i

    i

    a

    -

    =

    e

    =

    -

    -

    -

    -

    -

    239

    248

    247

    9428

    .

    0

    2357

    .

    0

    2357

    .

    0

    9701

    .

    0

    2425

    .

    0

    0

    9701

    .

    0

    0

    2425

    .

    0

    3

    2

    1

    x

    x

    x

    =

    10

    10

    10

    3

    2

    1

    x

    x

    x

    2425

    .

    0

    )

    9701

    .

    0

    (

    0

    247

    3

    2

    1

    x

    x

    x

    -

    -

    -

    =

    2425

    .

    0

    )

    9701

    .

    0

    (

    0

    248

    3

    1

    2

    x

    x

    x

    -

    -

    -

    =

    9428

    .

    0

    )

    2357

    .

    0

    (

    )

    2357

    .

    0

    (

    239

    2

    1

    3

    -

    -

    -

    -

    -

    =

    x

    x

    x

    (

    )

    6

    1058

    2425

    0

    10

    9701

    0

    10

    0

    247

    1

    .

    .

    .

    x

    =

    -

    -

    -

    =

    (

    )

    7

    1062

    2425

    0

    10

    9701

    0

    6

    1058

    0

    248

    2

    .

    .

    .

    .

    x

    =

    -

    -

    -

    =

    (

    )

    (

    )

    81

    783

    9428

    0

    7

    1062

    2357

    0

    6

    1058

    2357

    0

    239

    3

    .

    .

    .

    .

    .

    .

    x

    -

    =

    -

    -

    -

    -

    -

    =

    (

    )

    %

    .

    .

    .

    %

    .

    .

    .

    %

    .

    .

    .

    x

    x

    x

    a

    a

    a

    new

    i

    old

    i

    new

    i

    i

    a

    28

    101

    100

    81

    783

    10

    81

    783

    059

    99

    100

    7

    1062

    10

    7

    1062

    055

    99

    100

    6

    1058

    10

    6

    1058

    100

    3

    2

    1

    =

    -

    -

    -

    =

    =

    -

    =

    =

    -

    =

    -

    =

    -

    =

    81

    783

    7

    1062

    56

    1058

    3

    2

    1

    .

    .

    .

    x

    x

    x

    -

    =

    81

    .

    783

    7

    .

    1062

    6

    .

    1058

    x

    x

    x

    3

    2

    1

    (

    )

    (

    )

    (

    )

    (

    )

    (

    )

    (

    )

    (

    )

    (

    )

    (

    )

    98

    803

    9428

    0

    9

    2112

    2357

    0

    0

    2117

    2357

    0

    239

    9

    2112

    2425

    0

    81

    783

    9701

    0

    0

    2117

    0

    248

    0

    2117

    2425

    0

    81

    783

    9701

    0

    7

    1062

    0

    247

    3

    2

    1

    .

    .

    .

    .

    .

    .

    x

    .

    .

    .

    .

    .

    x

    .

    .

    .

    .

    .

    x

    =

    -

    -

    -

    -

    -

    -

    -

    =

    -

    =

    -

    -

    -

    -

    -

    =

    -

    =

    -

    -

    -

    -

    =

    (

    )

    (

    )

    (

    )

    %

    .

    .

    .

    .

    %

    .

    .

    .

    .

    %

    .

    .

    .

    .

    a

    a

    a

    49

    197

    100

    98

    803

    81

    783

    98

    803

    30

    150

    100

    9

    2112

    7

    1062

    9

    2112

    00

    150

    100

    0

    2117

    6

    1058

    0

    2117

    3

    2

    1

    =

    -

    -

    =

    =

    -

    -

    -

    =

    =

    -

    -

    -

    =

    -

    -

    =

    98

    .

    803

    9

    .

    2112

    0

    .

    2117

    3

    2

    1

    x

    x

    x

    %

    1

    a

    %

    2

    a

    %

    3

    a

    =

    n

    j

    j

    ij

    a

    a

    i

    1

    ii

    =

    >

    n

    i

    j

    j

    ij

    ii

    a

    a

    1

    -

    -

    -

    -

    -

    9428

    .

    0

    2357

    .

    0

    2357

    .

    0

    9701

    .

    0

    2425

    .

    0

    0

    9701

    .

    0

    0

    2425

    .

    0

    [

    ]

    -

    =

    5

    3

    12

    3

    5

    1

    13

    7

    3

    A

    [

    ]

    -

    =

    13

    7

    3

    3

    5

    1

    5

    3

    12

    A

    3

    3

    2

    1

    =

    +

    +

    x

    x

    x

    9

    4

    3

    2

    3

    2

    1

    =

    +

    +

    x

    x

    x

    9

    7

    3

    2

    1

    =

    +

    +

    x

    x

    x

    1

    5x

    -

    3x

    12x

    3

    2

    1

    =

    +

    28

    3x

    5x

    x

    3

    2

    1

    =

    +

    +

    76

    13x

    7x

    3x

    3

    2

    1

    =

    +

    +

    =

    1

    0

    1

    3

    2

    1

    x

    x

    x

    4

    3

    1

    5

    5

    23

    21

    22

    =

    +

    =

    +

    =

    =

    a

    a

    a

    10

    7

    3

    13

    13

    32

    31

    33

    =

    +

    =

    +

    =

    =

    a

    a

    a

    8

    5

    3

    12

    12

    13

    12

    11

    =

    -

    +

    =

    +

    =

    =

    a

    a

    a

    =

    -

    76

    28

    1

    13

    7

    3

    3

    5

    1

    5

    3

    12

    3

    2

    1

    a

    a

    a

    12

    5

    3

    1

    3

    2

    1

    x

    x

    x

    +

    -

    =

    5

    3

    28

    3

    1

    2

    x

    x

    x

    -

    -

    =

    13

    7

    3

    76

    2

    1

    3

    x

    x

    x

    -

    -

    =

    (

    )

    (

    )

    50000

    .

    0

    12

    1

    5

    0

    3

    1

    1

    =

    +

    -

    =

    x

    (

    )

    (

    )

    9000

    .

    4

    5

    1

    3

    5

    .

    0

    28

    2

    =

    -

    -

    =

    x

    (

    )

    (

    )

    0923

    .

    3

    13

    9000

    .

    4

    7

    50000

    .

    0

    3

    76

    3

    =

    -

    -

    =

    x

    %

    0

    .

    100

    100

    50000

    .

    0

    0000

    .

    1

    50000

    .

    0

    1

    =

    -

    =

    a

    %

    00

    .

    100

    100

    9000

    .

    4

    0

    9000

    .

    4

    2

    a

    =

    -

    =

    %

    662

    .

    67

    100

    0923

    .

    3

    0000

    .

    1

    0923

    .

    3

    3

    a

    =

    -

    =

    =

    8118

    .

    3

    7153

    .

    3

    14679

    .

    0

    3

    2

    1

    x

    x

    x

    (

    )

    (

    )

    14679

    .

    0

    12

    0923

    .

    3

    5

    9000

    .

    4

    3

    1

    1

    =

    +

    -

    =

    x

    (

    )

    (

    )

    7153

    .

    3

    5

    0923

    .

    3

    3

    14679

    .

    0

    28

    2

    =

    -

    -

    =

    x

    (

    )

    (

    )

    8118

    .

    3

    13

    900

    .

    4

    7

    14679

    .

    0

    3

    76

    3

    =

    -

    -

    =

    x

    =

    0923

    .

    3

    9000

    .

    4

    5000

    .

    0

    3

    2

    1

    x

    x

    x

    %

    62

    .

    240

    100

    14679

    .

    0

    50000

    .

    0

    14679

    .

    0

    1

    =

    -

    =

    a

    %

    887

    .

    31

    100

    7153

    .

    3

    9000

    .

    4

    7153

    .

    3

    2

    =

    -

    =

    a

    %

    876

    .

    18

    100

    8118

    .

    3

    0923

    .

    3

    8118

    .

    3

    3

    =

    -

    =

    a

    1

    a

    e

    2

    a

    e

    3

    a

    e

    =

    4

    3

    1

    3

    2

    1

    x

    x

    x

    =

    0001

    .

    4

    0001

    .

    3

    99919

    .

    0

    3

    2

    1

    x

    x

    x

    76

    13

    7

    3

    3

    2

    1

    =

    +

    +

    x

    x

    x

    28

    3

    5

    3

    2

    1

    =

    +

    +

    x

    x

    x

    1

    5

    3

    12

    3

    2

    1

    =

    -

    +

    x

    x

    x

    =

    1

    0

    1

    3

    2

    1

    x

    x

    x

    3

    13

    7

    76

    3

    2

    1

    x

    x

    x

    -

    -

    =

    5

    3

    28

    3

    1

    2

    x

    x

    x

    -

    -

    =

    5

    3

    12

    1

    2

    1

    3

    -

    -

    -

    =

    x

    x

    x

    %

    1

    a

    %

    2

    a

    %

    3

    a

    Relaxation

    Designed to Enhance converge nce.

    After each new value of x is computed, that value is

    modified using:

    Where

    20

    is a weighting factor.

    The choice of

    is problem-specific and is often

    determined empirically.

    old

    i

    new

    i

    new

    i

    xxx 1

    (

    )

    (

    )

    088

    .

    4

    13

    093

    .

    3

    7

    6

    .

    0

    3

    76

    x

    3

    =

    -

    -

    =