Ch3解线性方程组的直接方法求解bxA高斯消元法:思路首先将A化为上三角阵/*upper-triangularmatrix*/,再回代求解/*backwardsubstitution*/。=消元记,)()1()1(nnijaAA)1()1(1)1(...nbbbbStep1:设,计算因子0)1(11a)...,,2(/)1(11)1(11niaamii将增广矩阵/*augmentedmatrix*/第i行mi1第1行,得到)1(1)1(1)1(12)1(11...baaan)2(A)2(b)...,,2,()1(11)1()2()1(11)1()2(njibmbbamaaiiijiijij其中Stepk:设,计算因子且计算0)(kkka)...,,1(/)()(nkiaamkkkkikik)...,,1,()()()1()()()1(nkjibmbbamaakkikkikikkjikkijkij共进行?步n1)()2(2)1(121)()2(2)2(22)1(1)1(12)1(11..................nnnnnnnnbbbxxxaaaaaa回代)()(/nnnnnnabx0)(nnnaWhatif?Nouniquesolutionexists.)1...,,1()(1)()(niaxabxiiinijjiijiii0)(iiiaWhatif?Thenwemustfindthesmallestintegerkiwith,andinterchangethek-throwwiththei-throw.0)(ikiaWhatifwecan’tfindsuchk?Nouniquesolutionexists.定理若A的所有顺序主子式/*determinantofleadingprincipalsubmatrices*/均不为0,则高斯消元无需换行即可进行到底,得到唯一解。iiiiiaaaaA...............)det(1111注:事实上,只要A非奇异,即A1存在,则可通过逐次消元及行交换,将方程组化为三角形方程组,求出唯一解。§1GaussianElimination–TheMethod0(1,2,,1)定理(矩阵的分解)设为阶矩阵,如果的顺序主子式,则可分解为一个下三角矩阵和一个上三角矩阵的乘积,且这种分解是唯一的.iLUAnADinALU选主元消去法例:单精度解方程组211021219xxxx/*精确解为和*/...1000...00.1101191x8个...8999...99.0212xx8个用GaussianElimination计算:911212110/aam999212210101010...0.011ma8个92121012mb9991010011100,112xx小主元/*Smallpivotelement*/可能导致计算失败。全主元消去法/*CompletePivoting*/每一步选绝对值最大的元素为主元素,保证。1||ikmStepk:①选取;0||max||,ijnjikjiaakk②Ifikkthen交换第k行与第ik行;Ifjkkthen交换第k列与第jk列;③消元注:列交换改变了xi的顺序,须记录交换次序,解完后再换回来。列主元消去法/*PartialPivoting,ormaximalcolumnpivoting*/省去换列的步骤,每次仅选一列中最大的元。0||max||,iknikkiaak例:211111091,112xx11021111102119注:列主元法没有全主元法稳定。0,112xx例:211101019999991010010101注意:这两个方程组在数学上严格等价。标度化列主元消去法/*ScaledPartialPivoting*/对每一行计算。为省时间,si只在初始时计算一次。以后每一步考虑子列中最大的aik为主元。||max1ijnjiasnkkkaa...iiksa注:稳定性介于列主元法和全主元法之间。§1GaussianElimination–PivotingStrategies高斯-若当消去法/*Gauss-JordanMethod*/与GaussianElimination的主要区别:每步不计算mik,而是先将当前主元akk(k)变为1;把akk(k)所在列的上、下元素全消为0;bAxIbxA1Hey!Isn’titbetterthanGaussianElimination?Whatmakesyousayso?Obviouslywenolongerneedthebackwardsubstitution!You’dbetterwaittillwegothroughthenextsectiontodrawyourconclusion…§1GaussianElimination–Gauss-JordanMethod运算量/*AmountofComputation*/§1GaussianElimination–AmountofComputation由于计算机中乘除/*multiplications/divisions*/运算的时间远远超过加减/*additions/subtractions*/运算的时间,故估计某种算法的运算量时,往往只估计乘除的次数,而且通常以乘除次数的最高次幂为运算量的数量级。GaussianElimination:Stepk:设,计算因子且计算0)(kkka)...,,1(/)()(nkiaamkkkkikik)...,,1,()()()1()()()1(nkjibmbbamaakkikkikikkjikkijkij共进行n1步)()2(2)1(121)()2(2)2(22)1(1)1(12)1(11..................nnnnnnnnbbbxxxaaaaaa)()(/nnnnnnabx)1...,,1()(1)()(niaxabxiiinijjiijiii(nk)次(nk)2次(nk)次(nk)(nk+2)次nnnknknnk6523)2)((2311消元乘除次数:1次(ni+1)次22)1(1211nninni回代乘除次数:GaussianElimination的总乘除次数为,运算量为级。nnn3132333n§1GaussianElimination–AmountofComputationCompletePivoting:比GaussianElimination多出比较,保证稳定,但费时。33nOPartialPivoting:比GaussianElimination只多出比较,略省时,但不保证稳定。32nOScaledPartialPivoting:比GaussianElimination多出除法和比较,比列主元法稳定。但若逐次计算si(k),则比全主元法还慢。)(2nO32nOGauss-JordanMethod:运算量约为。故通常只用于求逆矩阵,而不用于解方程组。求逆矩阵即。23nO1||AIIA123*0.0012.0003.0001.0001.0003.7124.6232.0002.0001.0725.6433.000(0.4904,0.05104,0.3675)10.0012.0003.0001.000|1.0003.7TxxxxAb例1:阶方程组四位有效数字精确解为解:()高斯消去法213132100020001.997124.6232.0002.0001.0725.6433.0000.0012.0003.0001.0000.0012.0003.0001.000020043005100202004300510020400160062003005.0002.000(0.400mmmx,0.09989,0.4000)T21310.50000.000522.0001.0725.6433.000|1.0003.7124.6232.0000.0012.0003.0001.0002.0001.0725.6433.00003.1761.8010.50002.0013.0031.002mmAb()交换行,避免绝对值小的主元作除数。(列主元素法)320.63002.0001.0725.6433.00003.1761.8010.500001.8680.687(0.4900,0.05112,0.3678)mTx1123G-J245.356123100356001|245010245010356001123100nAAAI例2:用法求的逆矩阵解:15/32001/302/31012/301/31101/31101/205/22013/203/21001/211/20100132010331|.001210nIA§2三角分解法/*MatrixFactorization*/高斯消元法的矩阵形式/*MatrixFormofG.E.*/:Step1:)0(/111111aaamii记L1=1...11121nmm,则][)1()1(1bAL)1(1)1(1)1(11...baan)2(A)2(bStepn1:)()2(2)1(1)()2(2)2(22)1(1)1(12)1(11121..................nnnnnnnnnbbbaaaaaabALLL其中Lk=1...11,,1knkkmm§2MatrixFactorization–MatrixFormofG.E.1kL1...11,,1knkkmm111211...nLLL111jim,记为L单位下三角阵/*unitarylower-triangularmatrix*/记U=)()2(2)2(22)1(1)1(12)1(11............nnnnnaaaaaaLUAA的LU分解/*LUfactorization*/Heyhasn’tGEgivenmeenoughheadache?WhydoIhavetoknowitsmatrixform??!WhenyouhavetosolvethesystemfordifferentwithafixedA.bCouldyoubemorespecific,please?FactorizeAfirst,thenforeveryyouonlyhavetosolvetwosimpletriangularsystemsand.bbyLyxU§2MatrixFactorization–MatrixFormofG.E.定理若A的所有顺序主子