ME 3 Nmercl Methods Solng Sstems of Lner Algebrc Eqtons These presenttons re prepred b Dr. Cnet Sert Mechncl Engneerng Deprtment Mddle Est Techncl Unerst Ankr, Trke csert@met.ed.tr The cn not be sed wthot the permsson of the thor
Mth Introdcton f (,,..., n ) = f (,,..., n ) =... A generl set of eqtons. n eqtons, n nknowns. f n (,,..., n ) = Lner Algebrc Eqton: An eqton of the form f()= where f s polnoml wth lner terms. + +... + n n = b + +... + n n = b............ n + n +... + nn n = b n A generl set of lner lgebrc eqtons. n eqtons, n nknowns. Mtr Form: [A] {} = {b} [A] nn Coeffcent mtr {} n Unknown ector {b} n Rght-Hnd-Sde (RHS) ector
Reew of Mtrces [A] n n m m nm n m nd row Elements re ndcted b j row colmn Row ector: m th colmn r r rn n [ R] Colmn ector: [C] c c c m m Sqre mtr: [A] nm s sqre mtr f n=m. A sstem of n eqtons wth n nknonws hs sqre coeffcent mtr. Mn (prncple) dgonl: of [A] nn conssts of elements ; =,...,n Smmetrc mtr: If j = j [A] nn s smmetrc mtr Dgonl mtr: [A] nn s dgonl f j = for ll =,...,n ; j=,...,n nd j Identt mtr: [A] nn s n dentt mtr f t s dgonl wth = =,...,n. Shown s [I] 3
Reew of Mtrces (cont d) Upper trnglr mtr: [A] nn s pper trnglr f j = =,...,n ; j=,...,n nd >j Lower trnglr mtr: [A] nn s lower trnglr f j = =,...,n ; j=,...,n nd <j Bnded mtr: [A] nn s bnded mtr f j = for ll j > HBW or j > HBW, where HBW s the hlf bndwdth. Trdgonl mtr: s bnded mtr wth HBW=. Inerse of mtr: [A] - s the nerse of [A] nn f [A] - [A]=[I] Trnspose of mtr: [B] s the trnspose of [A] nn f b j = j Shown s [A] or [A] T Mtr mltplcton: [C] ps = [A] pr [B] rs c b =,...,p ; j=,...,s Note: [A][B] [B][A] j r k k kj Agmented mtr: s specl w of showng two mtrces together. b For emple A gmented wth the colmn ector B s b b b Determnnt of mtr: s sngle nmber. Determnnt of [A] s shown s A. 4
Grphcl Method for Solng Smll (n3) Set of Eqtons Consder set of eqtons + = b + = b Plot these on the Crtesn coordnte sstem wth es nd. b b For n=3, ech eqton wll be plne on 3D coordnte sstem. Solton s the pont where these plnes ntersect. For n>3, grphcl solton s not prctcl. 5
Grphcl Method (cont d) Grphcl Method s sefl to llstrte: () no solton () nfntel mn soltons (3) ll-condtoned sstem In sstem () nd (), eqtons re lnerl dependent. In sstem (3), the slopes of the lnes re er close to ech other. Mthemtcll Coeffcent mtrces of () & () re snglr. Ther determnnts re zero nd ther nerse do not est. Coeffcent mtr of (3) s lmost snglr. Its nerse s dffclt to tke. Ths sstem hs nqe solton, whch s not es to determne nmercll becse of ts etreme senstt to rond-off errors. 6
Crmer s Rle for Solng Set of Eqtons Determnnt of sstem Determnnt of mtr s D Determnnt of 33 mtr s D 3 3 33 3 3 33 3 3 3 Determnnt of generl nn mtr cn be clclted recrsel sng the boe pttern. Determnnt of snglr sstem s zero. - 3 = 5-6 = 7 Determnnt of n lll-condtoned sstem s close to zero. - 3 = 5 3.98-6 = 7 Wrnng: Mltpl both eqtons of the boe sstem wth 3 = 5 398-6 = 7 Ths sstem s s ll-condtoned s the preos one bt t hs determnnt tmes lrger. Therefore we need to scle sstem when we tlk bot the mgntde of ts determnnt. Detls wll come lter. 7
Crmer s Rle for Solng Set of Eqtons (Cont d) Crmer s Rle: Ech nknown s clclted s frcton of two determnnts. The denomntor s the determnnt of the sstem, D. The nmertor s the determnnt of modfed sstem obtned b replcng the colmn of coeffcents of the nknown beng clclted b the RHS ector. For 33 sstem b b 3 3 b3 3 33 3 b3 33 3 D D b b 3 3 3 D 3 b b b 3 For snglr sstem D= Solton cn not be obtned. For lrge sstems Crmer s rle s not prctcl becse clcltng determnnts s costl. To sole n nn sstem of eqtons, Crmer s rle needs n+ determnnt eltons. Usng recrse lgorthm, determnnt of n nn mtr reqres n!+n- rthmetc opertons (+,-,, ). Therefore solng n nn sstem wth the Crmer s Rle needs more thn (n+)(n!+n-). For sstem ths mens bot opertons (Check these nmbers). 8
C nd Mtrces: A mtr s nothng bt n rr of rrs. In C rr ndces strt from. C does not do check rr bonds. Complers mght he swtches for ths. A D rr ( mtr) s declred s doble A[4][5] nd ts elements re reched s A[][j] If o do not know the sze of the mtrces before strtng the progrm, o need to se dnmc memor llocton wth ponters. Ths cn be qte confsng. Eercse : () Wrte two fnctons to dd nd mltpl two mtrces. These fnctons shold tke two mtrces nd ther szes s npt rgments nd clclte thrd mtr. The shold check f the npt mtrces re stble for ddton or mlplcton. () Wrte mn progrm. Generte two smll mtrces. Add nd mltpl them b cllng proper fnctons. Eercse : () Wrte fncton tht clcltes the determnnt of mtr. Cll ths fncton recrsel to sole sstems of eqtons sng the Crmer s Rle. () Use ths progrm to sole set of eqtons. Generte the coeffcent mtr of the sstem nsde loop. Mke sre tht or sstem s not snglr. How long t tkes to sole ths sstem? Tr solng lrger sstems. 9
Elmnton of Unknowns Method Emple : Gen set of eqtons:.5 + 6. = 3. 4.8-8.6 = 5.5 Mltpl the st eqn b 8.6 nd the nd eqn b 6.:.5 + 53.3 = 5.8 9.76 53.3 = 34. Add these eqtons: 5.6 + = 59.9 Sole for : = 59.9/5.6 =.6855478 Usng the st eqn sole for : = (3..5*.6855478)/6. =.68454 Check f these stsf the nd eqn: 4.8*.6855478 8.6*.68454 = 5.54 (Dfference s de to the rond-off errors).
Ne Gss Elmnton Method It s formlzed w of the preos elmnton technqe. Consder the followng sstem of n eqtons. + +... + n n = b () + +... + n n = b ()... n + n +... + nn n = b n (n) Step (optonl): Form the gmented mtr of [A B]. Step Forwrd Elmnton: Redce the sstem to n pper trnglr sstem. (.) Frst elmnte from nd to n th eqtons. - Mltpl the st eqn. b / & sbtrct t from the nd eqton. Ths s the new nd eqn. - Mltpl the st eqn. b 3 / & sbtrct t from the 3 rd eqton. Ths s the new 3 rd eqn.... - Mltpl the st eqn. b n / & sbtrct t from the n th eqton. Ths s the new n th eqn. Importnt: In these steps the st eqn s the pot eqton nd s the pot element. Note tht dson b zero m occr f the pot element s zero. Ne-Gss Elmnton does not check for ths.
Ne Gss Elmnton Method (cont d) (.) Now elmnte from 3 rd to n th eqtons. ndctes tht the sstem s modfed once. The modfed sstem s n 3 n 3 nn n3 n 3n 33 3 n 3 n 3 b b b b ndctes tht the sstem s modfed once. The modfed sstem s n 3 n 3 nn n3 3n 33 n 3 n 3 b b b b Repet (.) nd (.) pto (.n-). b nn 3n 33 n 3 n 3 Prmes re remoed for clrt. At the end of Step, we wll get ths pper trnglr sstem
Ne Gss Elmnton Method (cont d) Step Bck sbsttton: Fnd the nknowns strtng from the lst eqton. (.) Lst eqton noles onl n. Sole for t. (.) Use ths n n the (n-) th eqton nd sole for n-.... (.n) Use ll preosl clclted les n the st eqn nd sole for. Emple : Sole the followng sstem sng Ne Gss Elmnton. 6 + 3 + 4 4 = 6 8 + 6 3 + 4 = 6 3 3 + 9 3 + 3 4 = -9-6 + 4 + 3-8 4 = -34 Step : Form the gmented mtr 6 4 6 8 6 6 3 3 9 3-9 -6 4-8 -34 3
Ne Gss Elmnton Method (cont d) Step : Forwrd elmnton (.) Elmnte 6 4 6 (Does not chnge. Pot s 6) 4-6 8-7 3-4 -8 (.) Elmnte 6 4 6 (Does not chnge.) 4-6 (Does not chnge. Pot s -4) -5-9 4-3 - (.3) Elmnte 3 6 4 6 (Does not chnge.) 4-6 (Does not chnge.) -5-9 (Does not chnge. Pot s ) -3-3 Step : Bck sbsttton (.) Fnd 4 4 = (-3)/(-3) = (.) Fnd 3 3 = (-9+5*)/ = - (.3) Fnd = (-6-*(-)-*)/(-4) = (.4) Fnd = (6+*-*(-)-4*)/6 = 3 4
Psedocode for the Ne Gss Elmnton Method For generl nn sstem [A] {} = {B} Forwrd Elmnton LOOP k from to n- LOOP from k+ to n FACTOR = A k / A kk LOOP j from k+ to n A j = A j FACTOR * A kj END LOOP B = B FACTOR * B k ENDLOOP ENDLOOP Bck Sbsttton X n = B n / A nn LOOP from n- to SUM =. LOOP j from + to n SUM = SUM + A j * X j END LOOP X = (B SUM) / A ENDLOOP Eercse 3: Implement ths n C. Wrte mn progrm nd two fnctons. Yo need to know how to pss mtrces to the fnctons. 5
Operton Cont for the Ne Gss Elmnton Method Let s cont the FLOPS (flotng pont opertons). Consder onl mltplctons nd dsons, snce the re more epense to perform. Forwrd Elmnton FACTOR = A k / A kk s elted (n k) tmes. A j = A j FACTOR * A kj s elted tmes. B = B FACTOR * B k s elted tmes. Totl * nd / Bck Sbsttton SUM = SUM + A j * X j s elted (n ) tmes. X = (B SUM) / A s elted tmes. Totl * nd / Totl n 3 /3 + n / + O(n ) + O(n) s n ncreses n 3 /3 n k n (n k)(n k ) (n ) n 3 n 3 O(n) O(n n k n k n k ) n n (n k)(n k) (n k) Emple 3: n * & / n FE * & / n BS Totl * & / n 3 /3 % de to FE 375 55 43 333 87. % 3385 55 3433 333333 98.5 % 3.34 E8 55 3.34 E8 3.33 E8 99.8 % 6
Potng In Ne Gss Elmnton, dson b zero occrs f the pot element s zero. Note tht zero pot elements m be creted drng the elmnton step een f the re not present n the orgnl mtr. Potng s sed to od ths problem. We nterchnge rows nd colmns t ech step to pt the coeffcent wth the lrgest mgntde on the dgonl. In ddton to odng the dson b zero problem, potng redces the rond-off errors. It mkes the solton of ll-condtoned sstems eser. Complete potng ses both row nd colmn nterchnges. It s not sed freqentl. Prtl potng ses onl row nterchnges. We wll se ths. When there re lrge dfferences n mgntde of coeffcents n one eqton compred to the other eqtons we m lso need sclng. Detls wll come lter. 7
Potng Emple Emple 4: Sole the followng sstem sng Gss Elmnton wth potng. + + 4 = + + 3 3 + 4 = - 4 3 + 4 = -7 6 + - 6 3-5 4 = 6 Step : Form the gmented mtr 3-4 3-7 6-6 -5 6 Step : Forwrd Elmnton (.) Elmnte. Bt the pot element s. We he to nterchnge the st row wth one of the rows below t. Interchnge t wth the 4 th row becse 6 s the lrgest possble pot. 6-6 -5 6 6-6 -5 6 3 - Now elmnte.6667 5 3.6667-4 4 3-7 -3.6667 4 4.3333-8
Potng Emple (cont d) (.) Elmnte.from the 3 rd nd 4 th eqns. Pot element s.6667. There s no dson b zero problem. Stll we wll perform potng to redce rond-off errors. Interchnge the nd nd 3 rd rows. Note tht complete potng wold nterchnge nd nd 3 rd colmns. 6-6 -5 6 6-6 -5 6-3.6667 4 4.3333 - Elmnte -3.6667 4 4.3333 -.6667 5 3.6667-4 6.88 5.6364-9..88 3.3636-5.9999 (.3) Elmnte 3. 6.88 >.88, therefore no potng s necessr. 6-6 -5 6-3.6667 4 4.3333-6.88 5.6364-9..56-3.99 Step : Bck sbsttton 4 = -3.99 /.56 = -.9999 3 = [-9. 5.6364*(-.9999)] / 6.88 =.3335 = [- 4.3333*(-.9999) 4*.3335] / -3.6667 =. = [6 (-5)*(-.9999) (-6)*.3335 *.] / 6 = -.5 Ect solton s = [- /3 -.5] T. Use more thn 5 sg. fgs. to redce rond-off errors. 9
Sclng Normlze the eqtons so tht the mmm coeffcent n eer row s eql to.. Tht s, dde ech row b the coeffcent n tht row wth the mmm mgntde. It s dsed to scle sstem before clcltng ts determnnt. Ths s especll mportnt f we re clcltng the determnnt to see f the sstem s ll-condtoned or not. Consder the followng sstems 3 = 5-3 = 5 3.98 6 = 7 39.8-6 = 7 The re ctll the sme sstem. In the second one the eqtons re mltpled b. Determnnt of the st sstem s (-6) (-3)(3.98) = -.6, whch s close to zero. Determnnt of the nd sstem s (-6) (-3)(39.8) = -6, whch s not tht close to zero. So s ths sstem ll-condtoned or not? Scle ths sstem. The re the sme, se the st one..6667 + = -.6667 -.6633 + = -.667 Now clclte the determnnt s.6667* *(-.6633) =.33. Use ths le n jdgng the sstems condton. Note tht How close to zero? s stll n open qeston. There re other ws to determne sstems condton (See pge 77).
Scled Prtl Potng Sclng s lso sefl when some rows he coeffcents tht re lrge compred to those n other rows. Consder the followng sstem + = + = Ect solton s (.,.99998) () If we sole ths sstem wth Gss Elmnton, no potng s necessr ( s lrger thn ). Use onl 3 sg. fgs to emphsze the rond-off errors..* +.* 5 =.* 5 =.* WRONG - 5.* 4 = -5.* 4 =.* OK (b) Frst scle the sstem nd thn sole wth Gss Elmnton..* -5 + = + = Ths sstem now needs potng. Interchnge the rows nd sole..* -5 + =.* + = =. OK + =.* = =. OK Conclson: Sclng showed tht potng s necessr. Bt sclng tself s not necessr (pot the orgnl sstem nd sole). Sclng lso ntrodces ddtonl rond-off errors. Therefore se sclng to decde whether potng s necessr or not bt thn se the orgnl coeffcents.
Emple for Gss Elmnton wth Scled Prtl Potng Emple 5: Sole the followng sstem sng Gss Elmnton wth scled prtl potng. Keep nmbers s frctons of ntegers to elmnte rond-off errors. 3-3 9 3-9 -6 4-8 -34 6-4 6-8 6 6 Strt b formng the scle ector. It hs the lrgest coeffcent (n mgntde) of ech row. SV = {3 8 6 } Ths scle ector wll be pdted f we nterchnge rows drng potng. Step : Forwrd Elmnton
Emple for Gss Elmnton wth Scled Potng (cont d) (.) Compre scled coeffcents 3/3, 6/8, 6/6, /. Thrd one s the lrgest (ctll forth one s the sme bt we se the frst occrnce). Interchnge rows nd 3. 6-4 6-6 4-8 -34 3-3 9 3-9 -8 6 6 Updte the scle ector SV = {6 8 3 } Elmnte. Sbtrct (-6/6) tmes row from row. Sbtrct (3/6) tmes row from row 3. Sbtrct (/6) tmes row from row 4. Resltng sstem s 6-4 6 3-4 -8-8 -7-4 -6 3
Emple for Gss Elmnton wth Scled Potng (cont d) (.) Compre scled coeffcents /8, /3, 4/. Second one s the lrgest. Interchnge rows nd 3. 6-4 6-8 -7 3-4 -8-4 -6 Updte the scle ector SV = {6 3 8 } Elmnte. Sbtrct (/(-)) tmes row from row 3. Sbtrct ((-4)/(-)) tmes row from row 4. Resltng sstem s 6-4 6-8 -7 3/3-83/6-45/ -/3 5/3 3 4
Emple for Gss Elmnton wth Scled Potng (cont d) (.3) Compre scled coeffcents (3/3)/8, (/3)/. Frst one s lrger. No need for potng. Scle ector remns the sme SV = {6 3 8 } Elmnte 3. Sbtrct ((-/3)/(3/3)) tmes row 3 from row 4. Resltng sstem s 6-4 6-8 -7 3/3-83/6-45/ -6/3-6/3 Step : Bck sbsttton Eqton 4 4 = Eqton 3 3 = - Eqton = Eqton = 3 These re ect reslts becse rond-off errors re elmnted b not sng flotng pont nmbers. 5
Ill-condtoned Sstems The he lmost snglr coeffcent mtrces. The he nqe solton. Consder the followng 33 sstem 3. -.5.53 -.6 4.33.56 -.87 7.3 -.83 -.54.47-3.38 The solton of ths sstem s [ ] T Chnge b from.6 to.6. The soltons chnges to [.566 4.5.35] T Or chnge from 3. to 3.. The soltons chnges to [.77 6.5.7333] T Ths s tpcl ll-condtoned sstem. Its solton s er senste to the chnges n the coeffcent mtr or the rght-hnd-sde ector. Ths mens t s er senste to rond-off errors. Doble precson mst be sed to redce rond-off errors s mch s possble. Scled potng shold lso be sed to decrese rond-off errors. Fortntel not mn engneerng problems wll reslt n n ll-condtoned sstem. 6
Other Uses of Gss Elmnton Ges the LU decomposton of A sch tht [L][U]=[A]. LU decomposton s sefl f we re solng mn sstems wth the sme coeffcent mtr A bt dfferent rght-hnd-sde ectors (See pge 66). It cn be sed to clclte the determnnt of mtr. At the end of the Forwrd Elmnton step we get n pper trnglr mtr. For ths mtr the determnnt s jst the mltplcton of dgonl elements. If we nterchnged rows m tmes, thn the detemnnt cn be clclted s A = (-) m * * * nn Emple 6: Remember the emple we sed to descrbe potng. The A mtr ws 3 4 3 6-6 -5 After the Forwrd Elmnton step we fond the followng pper trnglr mtr. 6-6 -5-3.6667 4 4.3333 6.88 5.6364.56 To get ths, we sed potng nd nterchnged rows twce. Therefore the determnnt of A s A = (-) * 6 * (-3.6667) * 6.88 *.56 = -34.8 7
Gss-Jordn Method Ths s nother elmnton technqe. It s rton of Gss Elmnton. The dfference s, when n nknown s elmnted, t s elmnted from ll other eqtons, not jst the sbseqent ones. At the sme tme ll rows re normlzed b ddng them to ther pot element. At the end of the forwrd elmnton step Gss-Jordn method elds n dentt mtr, not n pper trnglr one. There s no need for bck sbsttton. Rght-hnd-sde ector hs the reslts. Emple 7: Sole the followng 44 sstem sng G-J method wth potng. Note tht ths s the sme sstem tht we sed to demonstrte Gss Elmnton wth potng. 3-4 3-7 6-6 -5 6 Interchnge rows nd 4, dde the new frst row b 6 nd elmnte from the nd, 3 rd nd 4 th eqtons..667 - -.8333.6667 5 3.6667-4 -3.6667 4 4.3333-8
Gss-Jordn Method (cont d) Interchnge rows nd 3, dde the new second row b -3.6667 nd elmnte from the st, 3 rd nd 4 th eqtons. -.88 -.6364.5 -.99 -.88 3 6.88 5.6364-9.88 3.3636-6 No potng s reqred. Dde the thrd row b 6.88 nd elmnte 3 from the st, nd nd 4 th eqtons..4.58 -.8.56 -.3.5599-3. Dde the lst row b.5599 nd elmnte 4 from the st, nd nd 3 rd eqtons. -.5..3333 - Rght-hnd-sde ector s the solton. No bck sbsttton s reqred. Gss-Jordn reqres lmost 5% more opertons thn Gss Elmnton (n 3 / nsted of n 3 /3). 9
Clcltng the Inerse of Mtr wth Gss-Jordn Clcltng the nerse of mtr s mportnt f we wnt to sole mn sstems wth the sme coeffcent mtr, bt dfferent rght-hnd-sde ectors. To tke the nerse of A, gment t wth n dentt mtr nd ppl the Gss-Jordn method. Emple 8: Fnd the nerse of the followng mtr. - A = 3 Agment A wth 33 dentt mtr. - 3 Appl the Gss-Jordn method to ths sstem to get.4. -..6 33 mtr t the rght s the nerse of A. Ths nerse cn now be sed to sole sstem wth the coeffcent mtr A nd dfferent rght-hnd-sde ectors s {} = [A] - {B} LU decomposton cn be sed for the sme prpose nd t s more effcent (See pge 73). 3
Iterte Methods - Gss-Sedel Method Gss Elmnton nd ts rnts re clled drect methods. The re not preferred for lrge sstems. Iterte methods strt wth n ntl solton ector nd tertel conerge to the tre solton. The stop when the pre-specfed tolernce s reched nd rond-off errors re not n sse. Gen the sstem [A]{}={B} nd strtng les {}, Gss-Sedel ses the frst eqton to sole for, second for, etc. = (b 3 3..... n n ) / = (b 3 3..... n n ) /...... n = (b n n n..... (n-)(n-) n- ) / nn After the frst terton o get {}. Use these les to strt new terton. Repet ntl the tolernce s stsfed s k k, % k s for ll the nknowns (=,,n), where k nd k- represent the present nd preos tertons. 3
Gss-Sedel Emple Sole the followng sstem sng the Gss-Sedel Method 6 + 3 = - + 7 + 3 = 5 strtng wth = = 3 =. + 5 3 = - Rerrnge the eqtons = ( + - 3 ) / 6 = (5 + - 3 ) / 7 3 = ( + + ) / 5 Frst terton = ( + - 3 ) / 6 = ( + - )/6 =.833 = (5 + - 3 ) / 7 = (5 + *.8333 - )/7 =.38 3 = ( + + ) / 5 = ( +.8333 + *.38)/5 =.6 Second terton = ( + - 3 ) / 6 = ( + *.38.6)/6 =.69 = (5 + - 3 ) / 7 = (5 + *.69 *.6)/7 =. 3 = ( + + ) / 5 = ( +.69 + *.)/5 =.5 Contne lke ths to get (Do not forget to check conergence sng the specfed tolernce) Zeroth Frst Second Thrd Forth Ffth..833.69.998.999...38..995.. 3..6.5.998.. 3
Jcob Method Gss- Sedel lws ses the newest lble les. Jcob Method ses les from the preos terton. Emple 9: Repet the preos emple sng the Jcob method. Rerrnge the eqtons = ( + - 3 ) / 6 = (5 + - 3 ) / 7 3 = ( + + ) / 5 Frst terton (se les) = ( + - 3 ) / 6 = ( + - )/6 =.833 = (5 + - 3 ) / 7 = ( 5 + - )/7 =.74 3 = ( + + ) / 5 = ( + + )/5 =. Second terton (se les) = ( + - 3 ) / 6 = ( + *.74.)/6 =.38 = (5 + - 3 ) / 7 = (5 + *.833 *.)/7 =.8 3 = ( + + ) / 5 = ( +.833 + *.74)/5 =.85 Contne to get Zeroth Frst Second Thrd Forth Ffth... Eghth..833.38.85.4.994......74.8.53..99.... 3...85.8.38..... 33
Conergence of the Iterte Methods Note tht these methods cn be seen s the mltple pplcton of Smple One-Pont Iterton. The m conerge or derge. A conergence crter cn be dered strtng from the conergence crter of the Smple One-Pont Iterton method. When the sstem of eqtons cn be ordered so tht ech dgonl entr of the coeffcent mtr s lrger n mgntde thn the sm of the mgntdes of the other coeffcents n tht row (dgonll domnnt sstem) the tertons conerge for n strtng les. Ths s sffcent bt not necessr crter. For ll,...,n Mn engneerng problems stsf ths reqrement. n j j j The emple we sed hs dgonll domnnt coeffcent mtr. Gss-Sedel conerges sll fster thn the Jcob method. Eercse 4: Interchnge the nd nd 3 rd eqtons of the preos emple. Is the sstem dgonll domnnt now? Sole ths sstem sng both terte methods. Compre ther conergence rtes wth tht of the soled emple. Do o obsere n dergence? 34
Improng Gss-Sedel wth Relton After ech new le of s compted, tht le s modfed b weghted erge of the reslts of the preos nd present tertons, new = l new + ( - l) old < l < : weghtng fctor If l = no relton (Orgnl Gss-Sedel) If <l< If <l< nder relton (Used to mke dergng sstem conerge) oer relton (Used to speed p the conergence of n lred conergng sstem. Clled SOR, Sccesse (or Smltneos) Oer Relton) Choce of l s problem specfc. Eercse 5: Sole the sstem we sed n the Gss-Sedel emple wth dfferent weghtng fctors. Do o notce n dfference n the conergence rte? 35
Psedocode for the Gss-Sedel Method LOOP k from to miter LOOP from to n = B LOOP j from to n IF ( j) = - A j j ENDLOOP = / A ENDLOOP CONVERGED = TRUE LOOP from to n Eercse 6: Improe ths psedocode wth relton. Eercse 7: Modf ths psedocode for the Jcob method. OUTPUT = ( old ) / * IF ( > tolernce) CONVERGED = FALSE ENDLOOP IF (CONVERGED = TRUE) STOP ENDLOOP 36
Solng Sstem of Nonlner Eqtons Emple : Solng Sstem Usng Smple One-Pont Iterton Sole the followng sstem of eqtons e 4 Pt the fnctons nto the form =g (,), =g (,) g g () ln( ) () 4 Select strtng les for nd, sch s =. nd =.. The don t need to stsf the eqtons. Use these les n g fnctons to clclte new les. = g ( ) = = g ( ) = - = g ( ) =.98689 = g ( ) = -.67436 3 = g ( ) =.98543669 3 = g ( 3 ) = -.746 4 = g ( 3 ) =.8698 4 = g ( 4 ) = -.773 The solton s conergng to the ect solton of =.469, =-.79637 Eercse 8: Sole the sme sstem bt rerrnge the eqtons s =ln(-) nd strt from = =-.7. Remember tht ths method m derge. = (4- )/ 37
38 Solng Sstem of Nonlner Eqtons (cont d) Solng Sstem Usng Newton-Rphson Method Consder the followng generl form of two eqton sstem Wrte st order TSE for these eqtons ) (, ) (, ) ( ) ( ) ( ) ( To fnd the solton set + = nd + =. Rerrnge The frst mtr s clled the Jcobn mtr. Sole for +, + nd terte. Cn be generlzed for n smltneos eqtons
39 Solng Sstem of Eqns Usng NR Method (cont d) Sole for + nd + sng Crmer s rle (ME ), The denomntor s the determnnt of the Jcobn mtr J. Emple : Sole the sme sstem of eqtons sttng wth =, = e 4 =, = = =- =.788 J =-3.436564 =, =-.63953 =3.335387 =8.479595 =.647636 J =-4.485 =, =-3.4568 =.337769 =8.3469 =.3767 J =-6.59555 =3, 3 =-.3643 3 =.959 3 =.48497 3 =.7787 J 3 =-4.499343 Looks lke t s conergng to the root n the nd qdrnt -.8,.8. Eercse 9: Cn o strt wth = nd =? Eercse : Tr to fnd strtng ponts tht wll conerge to the solton n the 4 th qdrnt. J e, J e - J, e,,
4 Solng Sstem of Nonlner Eqtons (cont d) Preos N-R solton of sstem of nonlner eqtons cn be generlzed to the solton of sstem of n nonlner eqtons (See pge 57 for detls). Gen the followng n nonlner eqtons wth n nknowns f (,,..., n ) = f (,,..., n ) =..... f n (,,..., n ) = Form the Jcobn mtr. k s the terton conter. Clclte new [Z] t ech terton. Sole the followng sstem sng n of the technqes tht we lerned n ths chpter. [Z] k {} k+ = -{F} k + [Z] k {} k where F k = f ( k, k,..., n k ) k n n n n n n k f f f f f f f f f [Z]
Emple (Fll Em Qeston): 3 q 3 Lnk lengths: 4 = 4, =, 3 = 4, 4 = 5 q q 4 Crnk ngle: q = 45 = p/4 Use the Newton-Rphson method to sole the followng set of eqtons for q 3 nd q 4. Strt wth the followng ntl gesses: q 3 = 55, q 4 = 8 Perform two tertons. f (q 3, q 4 ) = cos(q ) + 3 cos(q 3 ) 4 cos(q 4 ) = f (q 3, q 4 ) = sn(q ) + 3 sn(q 3 ) 4 sn(q 4 ) = 4
4 N-R cn be ppled to nonlner eqtons s follows [Z] k {X} k+ = -{F} k + [Z] k {X} k where [Z] k s the Jcobn mtr of the k th terton Iterton : q 3 = 55, q 4 = 8 k k f f f f [Z] ) cos( f f ) cos( f f ) sn( f f ) sn( f f 4 4 4 3 3 3 4 4 4 3 3 3 q q q q q q q q Emple (cont d)
Emple (cont d) Iterton : f f f f 3.766 4.94.943.868 q q q q 3 4 3 4 [Z] 3.766.943 4.94.868 {F}.597.33 Therefore the lner sstem s 3.766.943 4.94 q.868q 3 4.597.33 3.766.943 4.94 55.8688 4.8667 56.9637 Sole ths sstem sng Gss Elmnton (or n other technqe tht we lerned) to get q 3 = 55.55 q 4 = 8.45 43
Emple (cont d) Iterton : f f f f 3.868 4.93.797.8334 q q q q 3 4 3 4 [Z] 3.868.797 4.93.8334 {F}.395.9 Therefore the lner sstem s 3.868.797 4.93 q.8334q 3 4.395.9 3.868.797 4.93 55.55.83348.45 5.933 59.84 Sole ths sstem sng Gss Elmnton (or n other technqe tht we lerned) to get q 3 = 55.4996 q 4 = 8.7994 44