nbm_sle_sm_ludecomp.nb 1 LU Decomposton Method Jame Trahan, Autar Kaw, Kevn Martn Unverst of South Florda Unted States of Amerca aw@eng.usf.edu
nbm_sle_sm_ludecomp.nb 2 Introducton When solvng multple sets of smultaneous lnear equatons wth the same coeffcent matrx but dfferent rght hand sdes, LU Decomposton s advantageous over other numercal methods n that t proves to be numercall more effcent n computatonal tme than other technques. In ths worsheet, the reader can choose a sstem of equatons and see how each step of LU decomposton method s conducted. To learn more about LU Decomposton method as well as the effcenc of ts computatonal tme clc here. LU Decomposton method s used to solve a set of smultaneous lnear equatons, [A] [X] = [C], where [A] nxn s a non-sngular square coeffcent matrx, [X] nx1 s the soluton vector, and [C] nx1 s the rght hand sde arra. When conductng LU decomposton method, one must frst decompose the coeffcent matrx [A] nxn nto a lower trangular matrx [L] nxn, and upper trangular matrx [U] nxn. These two matrces can then be used to solve for the soluton vector [X] nx1 n the followng sequence: Recall that [A] [X] = [C]. Knowng that [A] = [L] [U] then frst solvng wth forward substtuton [L] [Z] = [C] and then solvng wth bac substtuton [U] [X] = [Z] gves the soluton vector [X]. A smulaton of LU Decomposton method follows. Secton 1: Input Data Below are the nput parameters to begn the smulaton. Ths s the onl secton that requres user nput. The user can change the values that are hghlghted and Mathematca wll calculate the soluton vector [X]. è Number of equatons n = 4 4 è [A] nxn coeffcent matrx
nbm_sle_sm_ludecomp.nb 3 A = Table@88175, 25, 5, 1<, 8512, 64, 8, 1<, 81728, 144, 12, 1<, 88, 4, 2, 1<<D; A êê MatrxForm 175 25 5 1 512 64 8 1 1728 144 12 1 8 4 2 1 è [RHS] nx1 rght hand sde arra RHS = Table@8106.8, 177.2, 279.2, 79.3<D; RHS êê MatrxForm 106.8 177.2 279.2 79.3 Secton 2: LU Decomposton method Ths secton dvdes LU Decomposton nto 3 steps: 1) Decomposton of coeffcent matrx @AD nxn 2) Forward Substtuton 3) Bac Substtuton ü Step 1: Fndng [L] and [U] How does one decompose a non-sngular matrx [A], that s, how do ou fnd [L] and [U]? The followng procedure decomposes the coeffcent matrx [A] nto a lower trangular matrx [L] and upper trangular matrx [U], gven [A]=[L][U]. è For [U], the elements of the matrx are exactl the same as the coeffcent matrx one obtans at the end of forward elmnaton steps n Nave Gauss Elmnaton. è For [L], the matrx has 1 n ts dagonal entres. The non-ero elements on the non-dagonal elements are multplers that made the correspondng entres ero n the upper trangular matrx durng forward elmnaton. LU Decomposton procedure: Varable names: n = number of equatons U = nxn upper trangular matrx L = nxn lower trangular matrx
nbm_sle_sm_ludecomp.nb 4 LUdecompose@n_, A_D := ModuleA8AA, multpler<, L = Arra@0, 8n, n<d; U = Arra@0, 8n, n<d; AA = Arra@0, 8n, n<d; For@ = 1, n, ++, L@@, DD = 1; For@ = 1, <= n, ++, AA@@, DD = A@@, DD; If@!=, L@@, DD = 0DDD; ForA = 1, n 1, ++, ForA = + 1, n, ++, AA@@, DD multpler = NA AA@@, DD E; L@@, DD = multpler; For@ = 1, n, ++, AA@@, DD = AA@@, DD multpler AA@@, DDDE For@ = 1, n, ++, For@ = 1, n, ++, U@@, DD = AA@@, DD; If@ <, U@@, DD = 0DDD;E; Prnt@"L", "=", L êê MatrxFormD; Prnt@"U", "=", U êê MatrxFormDE LUdecompose@n, AD 1 0 0 0 2.92571 1 0 0 L= 9.87429 11.25 1 0 0.0457143 0.3125 0.00806452 1 U= 175 25 5 1 0 9.14286 6.62857 1.92571 0 0 37.2 12.79 0 0 0 0.455645 Notce that matrx [L] has onl one unnown to be solved for n ts frst row, and matrx [U] has onl one unnown to be solved for n ts last row. Ths wll prove useful n solvng for the soluton vector [X] n the followng steps of LU decomposton method.
nbm_sle_sm_ludecomp.nb 5 ü Step 2: Forward Substtuton Now that the [L] matrx has been formed, forward substtuton step, [L][Z]=[C], can be conducted, begnnng wth the frst equaton as t has onl one unnown, 1 = c 1 ÅÅÅÅÅÅÅ Equaton (2.1) l 1,1 Subsequent steps of forward substtuton can be represented b the followng formula: -1 Hl, * LD =2..n L Equaton (2.2) l, = Hc -@ ÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅ =1 ÅÅÅÅÅÅÅÅÅÅÅÅÅ The procedure below conducts forward substtuton steps to solve for @ZD nx1. Varable names: n = number of equatons RHS = nx1 rght hand sde arra L = nxn lower trangular matrx forwardsubsttuton@n_, L_, C_D := ModuleA8<, Z = Arra@, nd; C@@1DD Z@@1DD = L@@1, 1DD ; ForA = 2, n, ++, summ = 0; For@ = 1, 1, ++, summ = summ + L@@, DD Z@@DDD; HC@@DD summl Z@@DD = E; L@@, DD Prnt@"Z", "=", Z êê MatrxFormDE forwardsubsttuton@n, L, RHSD Z= 106.8 135.266 746.372 38.1661
nbm_sle_sm_ludecomp.nb 6 ü Step 3: Bac Substtuton Now that [Z] has been found, t can be used n the bac substtuton step, [U][X] = [Z], to solve for soluton vector @X D nx1, where @UD nxn s the upper trangular matrx calculated n Step 1, and @ZD nx1 s the rght hand sde arra. Bac substtuton begns wth solvng the n th equaton as t has onl one unnown. x n = n ÅÅÅÅÅÅÅÅ u n,n Equaton (2.3) The remanng unnowns are solved for worng bacwards from the Hn - 1L th equaton to the frst equaton usng the formula below x = H n -@ ÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅ Hu =+1, *x ÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅ LD L =n-1. ÅÅÅÅÅÅ.1 The followng procedure solves for @XD nx1. u, Equaton (2.4) Varable names: n = number of equatons Z = nx1 rght hand sde arra U = nxn upper trangular matrx bacsubsttuton@n_, U_, Z_D := ModuleA8<, X = Arra@x, nd; Z@@nDD X@@nDD = U@@n, ndd ; ForA = n 1, >= 1,, summ = 0; For@ = + 1, n, ++, summ = summ + U@@, DD X@@DDD; HZ@@DD summl X@@DD = E; U@@, DD Prnt@"X", "=", X êê MatrxFormDE The soluton vector @X D nx1 s: bacsubsttuton@n, U, ZD X= 0.116681 3.48532 8.73534 83.7628
nbm_sle_sm_ludecomp.nb 7 Concluson Mathematca helped us appl our nowledge of LU Decomposton method to solve a sstem of n smultaneous lnear equatons. The results are as follows: Prnt@"L", "=", L êê MatrxFormD Prnt@"U", "=", U êê MatrxFormD forwardsubsttuton@n, L, RHSD bacsubsttuton@n, U, ZD 1 0 0 0 2.92571 1 0 0 L= 9.87429 11.25 1 0 0.0457143 0.3125 0.00806452 1 U= Z= X= 175 25 5 1 0 9.14286 6.62857 1.92571 0 0 37.2 12.79 0 0 0 0.455645 106.8 135.266 746.372 38.1661 0.116681 3.48532 8.73534 83.7628 Queston 1: Solve the followng set of smultaneous lnear equatons usng LU decomposton method. 5 6 2.3 6 9 2 3.5 7 3.5 6 2 3 1.5 2 1.5 6 x 1 x 2 x 3 x 4 4 5 = 6.7 7.8 Queston 2: Use LU decomposton repeatedl to fnd the nverse of 5 6 2.3 6 9 2 3.5 7 3.5 6 2 3 1.5 2 1.5 6 Queston 3: Loo at the [Z] matrx n [L][Z]=[C] step n LU decomposton method of Queston 1. Is t the same as the [RHS] matrx at the end of forward elmnaton steps n Nave Gauss Elmnaton method? If es, s ths a concdence?
nbm_sle_sm_ludecomp.nb 8 References Autar Kaw, Holstc Numercal Methods Insttute, http://numercalmethods.eng.usf.edu/mws, See Introducton to Sstems of Equatons How does LU Decomposton method wor? Savng of computatonal tme for fndng nverse of a matrx usng LU decomposton