lec 10 gauss elimination1

Upload: arafatasghar

Post on 14-Apr-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 Lec 10 Gauss Elimination1

    1/27

    Simultaneous Linear Equations

    Topic: Gaussian Elimination

    Dr. Nasir M Mirza

    Numerical Methods

    Email: [email protected]

  • 7/30/2019 Lec 10 Gauss Elimination1

    2/27

    Gaussian Elimination

  • 7/30/2019 Lec 10 Gauss Elimination1

    3/27

    Basic Principles

    The general description of a set of linear equations in the matrixform: [A][X] = [B]

    Where, [A] is ( m x n ) matrix, the [X] is a ( n x 1 ) vector, andthe [B] is a (m x 1 ) vector.

    How we solve such a system:

    Write the equations in natural form

    Identify unknowns and order them

    Isolate unknowns

    Write equations in matrix form

  • 7/30/2019 Lec 10 Gauss Elimination1

    4/27

    Types of Matrix Formulation

    If m = n The solution of [A]{x} ={b} with n unknowns and m(n) equations

    If m > n The system is overdetermined system (Least Square Problems)

    If m < n The system is underdetermined system (Optimization Problems)

    mnmnmmm

    nn

    nn

    nn

    bxaxaxaxa

    bxaxaxaxa

    bxaxaxaxa

    bxaxaxaxa

    332211

    33333232131

    22323222121

    11313212111

    Suppose we have an ( m x n ) Array

  • 7/30/2019 Lec 10 Gauss Elimination1

    5/27

    Matrix Representation

    nnnnnnn

    n

    n

    n

    b

    b

    b

    b

    x

    x

    x

    x

    aaaa

    aaaa

    aaaa

    aaaa

    3

    2

    1

    3

    2

    1

    321

    3333231

    2232221

    1131211

    mnmnmmm

    nn

    nn

    nn

    bxaxaxaxa

    bxaxaxaxa

    bxaxaxaxa

    bxaxaxaxa

    332211

    33333232131

    22323222121

    11313212111The set of n linear equationswith n unknowns:

    The matix form:

  • 7/30/2019 Lec 10 Gauss Elimination1

    6/27

    Consistency

    nnnnnnn

    n

    n

    n

    b

    b

    b

    b

    x

    x

    x

    x

    aaaa

    aaaa

    aaaaaaaa

    bXA

    3

    2

    1

    3

    2

    1

    321

    3333231

    2232221

    1131211

    The problem is consistent, if a solution exists for the problem.

    The problem is inconsistent, if there is no solution for the problem.

  • 7/30/2019 Lec 10 Gauss Elimination1

    7/27

    Rank of Matrix

    Rank of a matrix is the number of linearlyindependent column vectors in the matrix.

    For n x n matrix, A:

    If rank(A) = n and is consistent, A has an uniquesolution exists

    If rank(A) = n and is inconsistent, A has no solution

    exists If rank(A) < n and system is consistent, A has an

    infinite number of solutions

  • 7/30/2019 Lec 10 Gauss Elimination1

    8/27

    Matrix

    For an n x n system, rank(A) = n automaticallyguarantees

    that the system is consistent.

    The columns of A are linearly independent The rows of A are linearly independent

    rank(A) = n

    det(A) ~= 0

    A-1 exists;

    The solution to [A]{x} ={b} exist and is unique.

  • 7/30/2019 Lec 10 Gauss Elimination1

    9/27

    Matrix Definition

    1

    6

    15.0

    12

    y

    x

    5

    6

    12

    12

    y

    x

    Considery = -2.0 x + 6

    y = 0.5 x + 1

    There are 2 unknowns x , y

    and rank is 2

    Considery = -2 x + 6

    y = -2 x + 5

    There are 2 unknowns x , y and

    rank is 1 and is inconsistent

  • 7/30/2019 Lec 10 Gauss Elimination1

    10/27

    Gaussian Elimination

    Gaussian Elimination is one of the most popular techniques for

    solving simultaneous linear equations of the form: [A][X] =[b]

    The method consists of 2 steps

    1. Forward Elimination of Unknowns.2. Back Substitution

    Let us learn the method first by examples:

    mnmnmmm

    nn

    nn

    nn

    bxaxaxaxa

    bxaxaxaxa

    bxaxaxaxa

    bxaxaxaxa

    332211

    33333232131

    22323222121

    11313212111

  • 7/30/2019 Lec 10 Gauss Elimination1

    11/27

    Example 1:Consider following three linear equations with three unknowns:

    )3(74.506.113.569.3

    )2(69.475.378.046.1

    )1(76.128.406.337.2

    321

    321

    321

    xxx

    xxx

    xxx

    )4(7426.08059.12911.1 321 xxx

    )5(6058.3366.66650.20

    69.475.3780.046.1

    0842.16366.2885.146.1

    32

    321

    321

    xx

    xxx

    xxx

    First step is to divide by 2.37 so that the coefficient of x1 is one. Thus

    Now multiply this by -1.46 and adding it with Eq2.

    )6(4802.86038.58942.90 32 xx

    Now multiply Eq.4 with 3.69 and adding it to Eq3.

  • 7/30/2019 Lec 10 Gauss Elimination1

    12/27

    Example 1:Re-writing Equations 4, 5 and 6:

    )6(4802.86038.58942.9)0(

    )5(6058.33866.66650.2)0(

    )4(7426.08059.12911.1

    321

    321

    321

    xxx

    xxx

    xxx

    )7(3530.13965.20 32 xx

    8671.211077.18)0(0 32 xx

    The second step is to divide by -2.6650 so that the coefficient of x2 is one. Thus

    Now multiply this by -9.8942 and adding it to Eq 6.

    dividing it by 18.1077, we get

    )8(2076.1)0(0 32 xx

  • 7/30/2019 Lec 10 Gauss Elimination1

    13/27

    Example 1:Final form of Eq. 4, 7 and 8 is

    )8(2076.100

    )7(3530.13965.20

    )4(7426.08059.12911.1

    3

    32

    321

    x

    xx

    xxx

    5410.12076.13965.23530.13965.23530.1 32

    xx

    Now x3 is known and we can back-substitute it into Eq. 7 to find x2.

    Similarly, we can find x1 using values of x2 and x3 from Eq. 4

    Therefore, the solution is given as

    x1= 0.9338 ; x

    2= 1.5410 ; x

    3= 1.2076

    9338.0

    2076.13965.25410.12911.17426.0

    3965.22911.17426.0321

    xxx

  • 7/30/2019 Lec 10 Gauss Elimination1

    14/27

    Forward Elimination

    The goal of Forward Elimination is to transform the coefficientmatrix into an Upper Triangular Matrix

    7.000

    56.18.401525

    112144

    1864

    1525

  • 7/30/2019 Lec 10 Gauss Elimination1

    15/27

    Forward Elimination

    Linear Equations:A set ofn equations and n unknowns

    11313212111 ... bxaxaxaxa nn

    22323222121 ... bxaxaxaxa nn

    nnnnnnn bxaxaxaxa ...332211

    . .

    . .

    . .

    ( Eq.1 )

    ( Eq.2 )

  • 7/30/2019 Lec 10 Gauss Elimination1

    16/27

    Forward Elimination

    Transform to an Upper Triangular Matrix

    Step 1: Eliminate x1 in 2nd equation using equation 1 as the pivot equation

    )(1

    21

    11

    aa

    Eqn

    Which will change the Eq. 1 as following:

    1

    11

    21

    1

    11

    21

    212

    11

    21

    121 ... ba

    axa

    a

    axa

    a

    axa nn

    11313212111 ... bxaxaxaxa nn (Eq.1)

  • 7/30/2019 Lec 10 Gauss Elimination1

    17/27

    Forward Elimination

    Zeroing out the coefficient of x1

    in the 2nd equation.

    Subtract Equation 1 from Eq.2

    1

    11

    2121

    11

    212212

    11

    2122 ... b

    a

    abxa

    a

    aaxa

    a

    aa nnn

    '

    2

    '

    22

    '

    22 ... bxaxa nn

    nnn aa

    aaa

    aaaaa

    1

    11

    212

    '

    2

    12

    11

    2122

    '22

    Or

    1

    11

    21

    1

    11

    21

    212

    11

    21

    121... b

    a

    axa

    a

    axa

    a

    axa

    nn

    Where

    22323222121 ... bxaxaxaxa nn ( Eq.2 )

    ( Eq.1 )

  • 7/30/2019 Lec 10 Gauss Elimination1

    18/27

    Forward Elimination

    Repeat this procedure for the remaining equations to reduce the set ofequations as

    11313212111 ... bxaxaxaxa nn '

    2

    '

    23

    '

    232

    '

    22 ... bxaxaxa nn

    '

    3

    '

    33

    '

    332

    '

    32 ... bxaxaxa nn

    ''

    3

    '

    32

    '

    2 ... nnnnnn bxaxaxa

    . . .

    . . .

    . . .

  • 7/30/2019 Lec 10 Gauss Elimination1

    19/27

    Forward Elimination

    Step 2: Eliminate x2 in the 3rd equation.Equivalent to eliminating x1 in the 2

    nd equation using equation 2 as the pivot

    equation.

    )(23 3222

    aa

    EqnEqn

  • 7/30/2019 Lec 10 Gauss Elimination1

    20/27

    Forward Elimination

    This procedure is repeated for the remaining equations to reduce theset of equations as

    11313212111 ... bxaxaxaxa nn

    '2

    '23

    '232

    '22 ... bxaxaxa nn

    "

    3

    "

    33

    "

    33 ... bxaxa nn

    ""

    3

    "

    3 ... nnnnn bxaxa

    . .

    . .

    . .

  • 7/30/2019 Lec 10 Gauss Elimination1

    21/27

    Forward Elimination

    Continue this procedure by using the third equation as the pivot equation

    and so on.

    At the end of (n-1) Forward Elimination steps, the system of equations will

    look like:

    '

    2

    '

    23

    '

    232

    '

    22 ... bxaxaxa nn

    "

    3

    "

    3

    "

    33 ... bxaxa nn

    11 n

    nn

    n

    nn bxa

    . .

    . .

    . .

    11313212111 ... bxaxaxaxa nn

  • 7/30/2019 Lec 10 Gauss Elimination1

    22/27

    Forward Elimination

    At the end of the Forward Elimination steps:

    )-(n

    nn

    3

    2

    1

    n

    nn

    n

    n

    n

    b

    bb

    b

    x

    xx

    x

    a

    aaaaa

    aaaa

    1

    "

    3

    '

    2

    1

    )1(

    "

    3

    "

    33

    '

    2

    '

    23

    '

    22

    1131211

  • 7/30/2019 Lec 10 Gauss Elimination1

    23/27

    Back Substitution

    The goal of Back Substitution is to solve each of the equations usingthe upper triangular matrix.

    3

    2

    1

    3

    2

    1

    33

    2322

    131211

    x

    x

    x

    00

    0

    b

    b

    b

    a

    aa

    aaa

    Example of a system of 3 equations

  • 7/30/2019 Lec 10 Gauss Elimination1

    24/27

    Back Substitution

    Start with the last equation because it has only

    one unknown

    )1(

    )1(

    n

    nn

    n

    n

    n

    a

    bx

    Solve the second from last equation (n-1)th using xn solved for

    previously.

    This solves for xn-1.

  • 7/30/2019 Lec 10 Gauss Elimination1

    25/27

    Back Substitution

    Representing Back Substitution for all equations by formula

    1

    1

    11

    iii

    n

    ijj

    i

    ij

    i

    i

    i

    a

    xab

    x

    Fori=n-1,

    n-2,.,1

    and)1(

    )1(

    n

    nn

    n

    n

    n

    a

    bx

  • 7/30/2019 Lec 10 Gauss Elimination1

    26/27

    Computer Programfunction x = gaussE(A,b,ptol)

    % GEdemo Show steps in Gauss elimination and back substitution% No pivoting is used.

    %

    % Synopsis: x = GEdemo(A,b)

    % x = GEdemo(A,b,ptol)

    %

    % Input: A,b = coefficient matrix and right hand side vector

    % ptol = (optional) tolerance for detection of zero pivot

    % Default: ptol = 50 * eps

    %

    % Output: x = solution vector, if solution exists

    A=[25 5 1; 64 8 1; 144 12 1]

    b=[106.8; 177.2; 279.2]

    if nargin

  • 7/30/2019 Lec 10 Gauss Elimination1

    27/27

    Computer Program (continued)% program continued

    for i =1:n-1pivot = Ab(i,i);

    if abs(pivot)