Engr/Math/Physics 25 Chp8 Linear Algebraic Eqns-1 Bruce Mayer, PE Registered Electrical & Mechanical Engineer BMayer@ChabotCollege.edu Engineering/Math/Physics 25: Computational Methods 1 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt Learning Goals Define Linear Algebraic Equations Solve Systems of Linear Equations by Hand using • Gaussian Elimination (Elem. Row Ops) • Cramer’s Method Distinguish between Equation System Conditions: Exactly Determined, OverDetermined, UnderDetermined Use MATLAB to Solve Systems of Eqns Engineering/Math/Physics 25: Computational Methods 2 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt Linear Equations Example In Many Engineering Analyses (e.g. ENGR36 & ENGR43) The Engineer Must Solve Several Equations in Several Unknowns; e.g.: 6x 3y 4z 41 12 x 5y 7z 26 5x 2y 6z 14 Contains 3 Unknowns (x,y,z) in the 3 Equations Engineering/Math/Physics 25: Computational Methods 3 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt 1 2 3 Linear Systems - Characteristics Examine the System of Equations 6 x 3 y 4 z 41 12 x 5 y 7 z 26 5 x 2 y 6 z 14 We notice These Characteristics that DEFINE Linear Systems Engineering/Math/Physics 25: Computational Methods 4 ALL the Variables are Raised EXACTLY to the Power of ONE (1) COEFFICIENTS of the Variables are all REAL Numbers The Eqns Contain No Transcendental Functions (e.g. ln, cos, ew) Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt Gaussian Elimination – ERO’s A “Well Conditioned” System of Eqns can be Solved by Elementary Row Operations (ERO): • Interchanges: The vertical position of two rows can be changed • Scaling: Multiplying a row by a nonzero constant • Replacement: The row can be replaced by the sum of that row and a nonzero multiple of any other row Engineering/Math/Physics 25: Computational Methods 5 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt ERO Example - 1 Let’s Solve The System of Eqns 1 2 3 6 x 3 y 4 z 41 12 x 5 y 7 z 26 5 x 2 y 6 z 14 INTERCHANGE, or Swap, positions of Eqns (1) & (2) Engineering/Math/Physics 25: Computational Methods 6 1 2 3 12 x 5 y 7 z 26 6 x 3 y 4 z 41 5 x 2 y 6 z 14 Next SCALE by using Eqn (1) as the PIVOT To Multiply • (2) by 12/6 • (3) by 12/[−5] Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt ERO Example - 2 The Scaling Operation 1 12 x 5 y 7 z 26 12 2 6 x 3 y 4 z 41 6 12 3 5 x 2 y 6 z 14 5 1 2 3 12 x 5 y 7 z 26 12 x 6 y 8 z 82 12 x 4.8 y 14.4 z 33.6 Engineering/Math/Physics 25: Computational Methods 7 Note that the 1st Coeffiecient in the Pivot Eqn is Called the Pivot Value • The Pivot is used to SCALE the Eqns Below it Next Apply REPLACEMENT by Subtracting Eqs • (2) – (1) • (3) – (1) Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt ERO Example - 3 The Replacement Operation Yields 1 2 3 12 x 5 y 7 z 26 0 x 11y 15 z 108 0 x 9.8 y 7.4 z 7.6 Or 1 2 3 12 x 5 y 7 z 26 11y 15 z 108 9.8 y 7.4 z 7.6 Engineering/Math/Physics 25: Computational Methods 8 Note that the x-variable has been ELIMINATED below the Pivot Row • Next Eliminate in the “y” Column We can use for the y-Pivot either of −11 or −9.8 • For the best numerical accuracy choose the LARGEST pivot Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt ERO Example - 4 Our Reduced Sys 1 2 3 12 x 5 y 7 z 26 11y 15 z 108 9.8 y 7.4 z 7.6 Since |−11| > |−9.8| we do NOT need to interchange (2)↔(3) Scale by Pivot against Eqn-(3) Engineering/Math/Physics 25: Computational Methods 9 1 2 12 x 5 y 7 z 26 11y 15 z 108 11 3 9.8 y 7.4 z 7.6 9.8 Or 1 2 3 12 x 5 y 7 z 26 11y 15 z 108 11y 8.306 z 8.531 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt ERO Example - 5 Perform Replacement by Subtracting (3) – (2) 1 2 3 12 x 5 y 7 z 26 11y 15 z 108 23.306 z 116.531 Now Easily Find the Value of z from Eqn (3) z 116.531 23.306 5 Engineering/Math/Physics 25: Computational Methods 10 The Hard Part is DONE Find y & x by BACK SUBSTITUTION From Eqn (2) 108 15 z 108 75 y 11 11 y 33 11 3 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt ERO Example - 6 BackSub into (1) 1 2 3 6 x 3 y 4 z 41 12 x 5 y 7 z 26 5 x 2 y 6 z 14 12 x 5 y 7 z 26 7 z 5 y 26 x 12 35 15 26 24 x 2 12 12 x=2 Thus the Solution Set for Our Linear System Engineering/Math/Physics 25: Computational Methods 11 y = −3 z=5 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt Importance of Pivoting Computers use finite-precision arithmetic A small error is introduced in each arithmetic operation, AND… error propagates When the pivot element is very small, then the multipliers will be even smaller Adding numbers of widely differing magnitude can lead to a loss of significance. To reduce error, row interchanges are made to maximize the magnitude of the pivot element Engineering/Math/Physics 25: Computational Methods 12 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt Gaussian Elimination Summary INTERCHANGE Eqns Such that the PIVOT Value has the Greatest Magnitude SCALE the Eqns below the Pivot Eqn using the Pivot Value ratio’ed against the Corresponding Value below REPLACE Eqns Below the Pivot by Subtraction to leave ZERO Coefficients Below the Pivot Value Engineering/Math/Physics 25: Computational Methods 13 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt Poorly Conditioned Systems For Certain Systems Guassian Elimination Can Fail by • NO Solution → Singular System • Numerically Inaccurate Results → ILL-Conditioned System In a SINGULAR SYSTEM Two or More Eqns are Scalar Multiples of each other In ILL-Conditioned Systems 2+ Eqns are NEARLY Scalar Multiples of each other Engineering/Math/Physics 25: Computational Methods 14 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt A Singular (Inconsistent) Sys Consider 2-Eqns in 2-Unknowns 1 2 x 2y 4 2x 4 y 5 Perform Elimination by • Swapping Eqns • Mult (2) by 2/1 • Subtract (2) – (1) Engineering/Math/Physics 25: Computational Methods 15 1 2 1 2 1 2 2x 4 y 5 0x 0 y 3 2 0 3 ???? 2x 4 y 5 x 2y 4 2x 4 y 5 2x 4 y 8 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt Singular System - Geometry Plot This System on the XY Plane x 2y 4 2x 4 y 5 The Lines do NOT CROSS to Define a A Solution Point y 1 2 Singular Systems Have at least Two “PARALLEL” Eqns Engineering/Math/Physics 25: Computational Methods 16 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt ILL-Conditioned Systems A small deviation in one or more of the CoEfficients causes a LARGE DEVİATİON in the SOLUTİON. 1x 2y 3 x 1 0.48 x 0.99 y 1.47 y 1 1x 2y 3 x3 0.49 x 0.99 y 1.47 y0 Engineering/Math/Physics 25: Computational Methods 17 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt ILL-Conditioned Systems - 2 Systems in Which a Small Change in a CoEfficient Produces Large Changes in the Solution are said to be STIFF Tilt Region • Essentially the Lines Have very nearly Equal SLOPES • “Tilting” The Equations just a bit Dramatically Shifts the Solution (Crossing Point) Engineering/Math/Physics 25: Computational Methods 18 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt Matrix Methods for LinSys - 1 Consider the Electrical Ckt Shown at Right The Operation of this Ckt May be Described in Terms of the • Mesh Currents, I1-I4 • Sources: 4 mA, 12 V • Resistors: 1 & 2 kΩ Engineering/Math/Physics 25: Computational Methods 19 Notice Mesh Currents I1 & I2 are Defined by SOURCES Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt Matrix Methods for LinSys - 3 Using Techniques from ENGR43 find 0 I2 I2 I2 I1 I1 0 0 0 I3 3I 3 I3 0 0 2I 4 2I 4 Recall Matrix Multiplication to Write the Equation system in Matrix Form Engineering/Math/Physics 25: Computational Methods 20 4mA 0 8mA 12mA 0 I1 4 1 0 0 1 1 1 0 I 0 2 0 1 3 2 I 3 8 0 1 1 2 I 4 12 A x b Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt Matrix Methods for LinSys - 3 Thus The (linear) Ckt Can be Described by Ax b Where • A Coefficient Matrix – m-Rows x n-Colunms • b Constraint Vector • x Solution Vector Engineering/Math/Physics 25: Computational Methods 21 This Can Be Written in Std Math Notation a11 A ai1 am1 x1 x xi xm a1i aii ani a1n ain amn b1 b bi bm Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt Determinants - 1 If we Solve a LinSys by Elimination we may do a Lot of work Before Discovering that the system is Singular or Very-Stiff Determinants Can Alert us ahead of time to these Difficulties Engineering/Math/Physics 25: Computational Methods 22 Determinants are Defined only for SQUARE Arrays The 2x2 Definition a11 a12 D2 a11a 22 a 21a12 a 21 a 22 D2 is Sometimes called the “Basic Minor” Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt Determinants - 2 Calculating Larger-Dimension DETs becomes very-Tedious very-Quickly • Consider a 3x3 Det a11 a12 D3 a21 a22 a31 a32 a13 a23 a11 detMinor 1 a12 detMinor 2 a13 detMinor 3 a33 D3 a11 a22a33 a32a23 a12 a21a33 a31a23 a13 a21a32 a31a22 • Example 4 9 6 465 22 935 6 677 39 D3ex 7 13 2 348 261 696 87 3 11 5 Engineering/Math/Physics 25: Computational Methods 23 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt Determinants - 3 A Determinant, no matter what its size, Returns a SINGLE Value Matrix vs. Determinant • For Square Matrix A the Notation A det A A MATLAB vs det • The det Calc is quite Painful, but MATLAB’s “det” Fcn Makes it Easy Engineering/Math/Physics 25: Computational Methods 24 For the D3ex >> A = [-4,9,6; 7,13,-2; -3,11,5]; >> D3ex = det(A) D3ex = 87 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt Determinant Indicator - 1 The LARGER the Magnitude of the Determinant relative to the Coefficients, The LESS-Stiff the System If det=0, then the System is SINGULAR 1 2 x 2y 4 det 0 SINGULAR 2x 4 y 5 det 0.03 1x 2y 3 STIFF 0.48 x 0.99 y 1.47 1x 0.49 x 2y 0.99 y Engineering/Math/Physics 25: Computational Methods 25 3 1.47 det 0.01 STIFF Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt Determinant Indicator - 2 Consider this 5 x System 7x 2y 2y 5 Check the “Stiffness” D 7 13 23 2 24 2 Thus The system appears NON-Stiff Find Solution by Elimination as x3 Engineering/Math/Physics 25: Computational Methods 26 y 1 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt MATLAB Left Division MATLAB has a very The Syntax is Quite nice Utility for Simple Solving Well• the hassle is Conditioned Linear entering the Matrix-A and Vector-b Systems of the Form Ax b Well Conditioned → x = A\b • Square System → No. of Eqns & Unknwns are Equal • det 0 Engineering/Math/Physics 25: Computational Methods 27 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt Left-Div Example - 1 Consider a 750 kg Crate suspended by 3 Ropes or Cables In MATRIX form Using Force AT w Mechanics from ENGR36 Find 3 Eqns in 3 Unknowns 0.48TAB 0TAC 0.5195TAD 0 0.8TAB 0.8824TAC 0.7792TAD 750 * 9.81 0.36TAB 0.4706TAC 0.3506TAD 0 Engineering/Math/Physics 25: Computational Methods 28 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt Left-Div Example - 2 The MATLAB Command Window Session >> A = [-0.48, 0, 0.5195;... 0.8, 0.8824, 0.7792;... -0.36, 0.4706, -.3506]; >> w = [0; 9.81*750; 0] >> T = A\w T = 1.0e+003 * 2.6254 3.8157 2.4258 Engineering/Math/Physics 25: Computational Methods 29 Or • TAB = 2.625 kN • TAC = 3.816 kN • TAD = 2.426 kN Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt Matrix Inverse - 1 Recall The Matrix Formulation for nEqns in n-Unknowns Ax b In Matrix Land xb A To Isolate x, employ the Matrix Inverse A-1 as Defined by Engineering/Math/Physics 25: Computational Methods 30 1 A AI Note that the IDENTITY Matrix , I, Has Property Ix x Use A-1 in Matrix Eqn 1 1 A Αx A b 1 or Ix A b 1 or x A b Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt Matrix Inverse - 2 Thus the Matrix Shorthand for the Solution Ax b 1 xA b Determining the Inverse is NOT Trivial (Ask your MTH6 Instructor) Engineering/Math/Physics 25: Computational Methods 31 In addition A-1 is, in general, Less Numerically Accurate Than Pivoted Elimination However 1 xA b is Symbolically Elegant and Will be Useful in that regard Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt Compare MatInv & LeftDiv % Bruce Mayer, PE % ENGR25 * 21Oct09 % file = Compare_MatInv_LeftDiv_0910 % A = [3 -7 8; 7 6 -5; -9 0 2] b = [13; -29; 37] Ainv = inv(A) xinv = Ainv*b xleft = A\b % % CHECK Both by b = A*x CHKinv = A*xinv CHKleft = A*xleft Engineering/Math/Physics 25: Computational Methods 32 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt All Done for Today Matrix Inversion by Adjoint Engineering/Math/Physics 25: Computational Methods 33 Given A, Find A-1 Adj ( A) A |A| 1 The “Adjoint” of a matrix is the transpose of the matrix made up of the “CoFactors” of the original matrix. Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt Engr/Math/Physics 25 Appendix f x 2 x 7 x 9 x 6 3 2 Bruce Mayer, PE Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege.edu Engineering/Math/Physics 25: Computational Methods 34 Bruce Mayer, PE BMayer@ChabotCollege.edu • ENGR-25_Linear_Equations-1.ppt