LECTURE_14_CS113_2010 - CS 113 Linear Systems of Equations...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 113 Linear Systems of Equations Linear Algebraic Equations Nonlinear Equations: Example Representing Linear Algebraic Equations in Matrix Form Ax = b Representing Linear Algebraic Equations in Matrix Form Ax = b Ⱥ a11 Ⱥ Ⱥa21 A= Ⱥ M Ⱥ Ⱥan1 a12 a22 M an 2 L a1n Ⱥ Ⱥ L a2 n Ⱥ O M Ⱥ Ⱥ L ann Ⱥ “coefficient matrix” € € Ⱥ x1 Ⱥ Ⱥ Ⱥ x 2 Ⱥ Ⱥ x = Ⱥ M Ⱥ Ⱥ Ⱥ x n −1 Ⱥ Ⱥ Ⱥ x n Ⱥ € “vector of unknowns” € Ⱥ b1 Ⱥ Ⱥ Ⱥ Ⱥ b2 Ⱥ b = Ⱥ M Ⱥ Ⱥ Ⱥ Ⱥbn −1 Ⱥ Ⱥ bn Ⱥ “vector of known constants” Representing Linear Algebraic Equations in Matrix Form: EXAMPLE #1 Ax = b Ⱥ 5 −3 7 Ⱥ Ⱥ Ⱥ A = Ⱥ2.1 0.7 0 Ⱥ Ⱥ 0 3.1 −7.2 Ⱥ Ⱥ Ⱥ “coefficient matrix” € € Ⱥ x1 Ⱥ Ⱥ Ⱥ x = Ⱥ x 2 Ⱥ Ⱥ x 3 Ⱥ Ⱥ Ⱥ Ⱥ −1 Ⱥ Ⱥ Ⱥ b = Ⱥ1.5 Ⱥ Ⱥ8.1Ⱥ Ⱥ Ⱥ € “vector of unknowns” € “vector of known constants” Example #2: Linear Algebraic Equation Ⱥ 3 2 Ⱥ A = Ⱥ Ⱥ Ⱥ−1 2 Ⱥ Ⱥ18 Ⱥ b = Ⱥ Ⱥ Ⱥ 2 Ⱥ € € Ⱥ x1 Ⱥ x = Ⱥ Ⱥ Ⱥ x 2 Ⱥ Ax = b The Graphic Method Review of Matrix Notation 1. Matrix 2. Row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 Ⱥ1 5 Ⱥ Ⱥ Ⱥ3 1 Ⱥ Ⱥ1 0 Ⱥ Ⱥ3 1 Ⱥ Ⱥ Ⱥ Ⱥ Ⱥ = Ⱥ Ⱥ 1 5 Ⱥ Ⱥ0 1 Ⱥ Ⱥ1 5 Ⱥ Ⱥ Multiplication by an identity matrix is commutative We write I for an identity matrix IDENTITY MATRICES Identity matrices times a matrix or vector produces the same matrix or vector Ix = x € THE INVERSE OF A MATRIX In ordinary arithmetic multiplication the inverse of 3 is and the inverse of is 3 since For square matrices the inverse of a matrix A is written A–1 , when it exists. A A–1 = I and A–1 A = I where I is the identity matrix. Multiplication with an inverse matrix is commutative. FINDING THE INVERSE OF A MATRIX IN MATLAB define a random matrix 5x5 use the command “inv” to find the inverse of A and and assign it to the variable B (notice how B is also a 5x5 matrix) see how B*A = I (identity matrix) also A*B = I (identity matrix) USING THE INVERSE TO SOLVE LINEAR SYSTEM OF EQUATIONS set up a matrix equation Ax = b Find the inverse of A and multiply both sides of the equation by A–1 −1 −1 A Ax = A b € € −1 Ix = A b −1 x=A b EXAMPLE #1 Ⱥ5 x1 − 3 x 2 + 7 x 3 = −1 Ⱥ Ⱥ 2.1x1 + 0.7 x 2 = 1.5 Ⱥ Ⱥ 3.1x 2 − 7.2 x 3 = 8.1 € € Ⱥ 5 −3 7 Ⱥ Ⱥ Ⱥ A = Ⱥ2.1 0.7 0 Ⱥ Ⱥ 0 3.1 −7.2 Ⱥ Ⱥ Ⱥ Ax = b Ⱥ x1 Ⱥ Ⱥ Ⱥ x = Ⱥ x 2 Ⱥ Ⱥ x 3 Ⱥ Ⱥ Ⱥ € Ⱥ 0.2017 −0.004 0.1961 Ⱥ Ⱥ Ⱥ € A −1 = Ⱥ −0.6050 1.4406 −0.5882 Ⱥ Ⱥ −0.2605 0.6202 −3.922 Ⱥ Ⱥ Ⱥ € Ⱥ −1 Ⱥ Ⱥ Ⱥ b = Ⱥ1.5 Ⱥ Ⱥ8.1Ⱥ Ⱥ Ⱥ Ⱥ x1 Ⱥ Ⱥ 1.3806 Ⱥ Ⱥ Ⱥ Ⱥ Ⱥ € x = Ⱥ x 2 Ⱥ = A −1b = Ⱥ −1.9988 Ⱥ Ⱥ x 3 Ⱥ Ⱥ −1.9856 Ⱥ Ⱥ Ⱥ Ⱥ Ⱥ EXAMPLE #1: FROM MATLAB Ax = b € NOT USING THE INVERSE TO SOLVE LINEAR SYSTEM OF EQUATIONS set up a matrix equation Ax = b THERE ARE OTHER WAYS TO SOLVE THIS MATRIX EQUATION THAT DO NOT RELY ON FINDING AN INVERSE. THESE METHODS TEND TO BE MORE COMPUTATIONALLY EFFICIENT. € ONE POPULAR METHOD IS CALLED GAUSS ELIMINATION BUT THERE ARE MANY OTHERS. MATLAB HAS THESE METHODS BUILT IN. NOT USING THE INVERSE TO SOLVE LINEAR SYSTEM OF EQUATIONS Ax = b TO IMPLEMENT A NONINVERSE METHOD FOR SOLVING A SYSTEM OF EQUATIONS IN MATLAB USE THE BACKSLASH “\” OR FORWARD SLASH “/” € Non-inverse method of solving system of equations ...
View Full Document

Ask a homework question - tutors are online