LECTURE 9 Review of Matrix lgebra We shall now look at algorithms for solving systems of linear equations system of linear equations is a set of equations of the form è9è 8 é é: a x + a x + æææ+ a m x m = b a x + a x + æææ+ a m x m = b a n,;x + a n,;x + æææ+ a n,;mx m = b n, a n x + a n x + æææ+ a nm x m = b n In the example above, we have a total of n equations and m unknowns However, for the most part we shall be considering systems of equations where the total number of equations equals the total number of unknowns; for in this case, we generally have a unique solution èif we have fewer equations than unknowns we don't have enough information to get a unique solution; and if we have more èindependentè equations than unknowns that we won't have any solutionsè The ærst step in casting the problem of solving systems of linear equations into the realm on numerical analysis, is to represent such a systems as a matrix equation Thus, if we then denote by, x, and b the matrices a a æææ a ;n, a n a a æææ a ;n, a n a n,; a n,; æææ a n,;n, a n,;n a n a n; æææ a n;n, x = then è9è èwith m = nè can be written x x x n, x n ; b = x = b b b b n, b n Now what makes this formulation accessible to numerical analysis is the fact that most èif not allè numerical programming languages have anumerical array data type In Maple, for example, a matrix like can be identiæed with a array constructed as follows: := arrayè,è; ë,ë := ; @
THREE SIMPLE CSES or more succinctly ë,ë := ; ë,ë := ; ë,ë := ; ë,ë := ; ë,ë := ; ë,ë := ; ë,ë := ; ë,ë := ; := arrayè,è; := ëë,,ë,ë,,ë,ë,ëë; Three Simple Cases Diagonal Matrices matrix equation x = b is trivial to solve if the matrix is purely diagonal For if the corresponding system of equations reduces to a æææ a æææ æææ a n,;n, æææ a x = b è x = b a a x = b è x = b a x n = b n è x n = b n Lower Triangular Matrices If the matrix has the form a æææ a a æææ a n,; a n,; æææ a n,;n, a n a n; æææ a n;n, èwith zeros everywhere above the diagonal from a to è, then it is called lower triangular matrix equation x = b in which is lower triangular is also fairly easy to solve For it is equivalent ot a system of equations of the form a x = b a x + a x = b a x + a x + a x = b a n x + a n x + a n x + æææ+ x n = b n
THREE SIMPLE CSES To ænd the solution of such a system one solves the ærst equation for x and then substitutes its solution b =a for the variable x in the second equation a b a + a x = b è x = a b, a b a One can now substitute the numerical expressions for x, and x into the third equation and get a numerical expression for x Continuing in this manner we can solve the system completely t this point, it might be worthwhile to develop an explicit algorithm for carrying out the solution of a lower triangular linear system Let n denote the number of equations èand the number of unknownsè We shall assume the matrix is lower triangular so that ccording to the discusion above, we have a ij = ; if jéi x = b a and if we know x ;x ;::: ;x k, we can compute x k from the k th equation x k = èb k, a k x, a k x k,æææ,a k;k,x k è a kk = X b k, k, a ki x i a kk a kk i= Upper Triangular Matrices We can do a similar thing for systems of equations characterized by an upper triangular matrices For if then the corresponding system of equations will be a a æææ a ;n, a n a æææ a ;n, a n æææ a n,;n æææ a x + a x+æææ+ a n x n = b a x + æææ+ a n x n = b a n,;n,x n, + a n,;nx n = b n, x n = b n which can be solved by substituting the solution of the last equation into the penultimate equation and solving for x n, x n, = a n,;n, x n = b n b n,, a n,;n bn and then substituting this result into the third from last equation, etc then becomes x n,i = a n,i;n,i è b i, ix k= a n,i;n,kx n,k! The formula for a particular x i
THREE SIMPLE CSES Example 9 Write a Maple program that solves the following system of equations x = x + x = x +x + x = x + x +x + x = 8 æ First note that this system corresponds to a lower triangular matrix B @ We can thus solve the equations x = b by forward substitution: for each k from to we set è! x k = k, X b k, a ks x s a kk In Maple this can be coded as follows: s= C n := ; := arrayèn,nè; b := arrayènè; x := arrayènè; := ëë,,,ë,ë,,,ë,ë,,,ë,ë,,,ëë; b := ë,,,9ë; for k from to n do xëkë := èbëkë - sumèëk,së*xësë,s=k-èèèëk,kë; od; Example 9 Write a Maple program that solves the following system of equations x +x + x, x = x + x, x =,x + x = x = 8 æ First note that this system corresponds to a lower triangular matrix B @,,, We can thus solve the equations x = b by backward substitution: for each k from to we set x,k = a,k;,k In Maple this can be coded as follows: n := ; := arrayèn,nè; b := arrayènè; x := arrayènè; è X C k, b,k, a,k;,sx,s s=!
THREE SIMPLE CSES := ëë,,,-ë,ë,,,-ë,ë,,-,ë,ë,,,ëë; b := ë,,,8ë; for k from to èn-è do xën-kë := èbën-kë - sumèën-k,n-së*xën-së,s=k-èèèën-k,n-kë; od;