《Gauss全主元消去法》由会员分享,可在线阅读,更多相关《Gauss全主元消去法(4页珍藏版)》请在金锄头文库上搜索。
1、Gaussian elimination with complete pivotingTo keep the Gaussian elimination method smooth operation,We must ensure that the pivot elementandcan not too small in each 0)1(akkkakkk)1( operation.So the selection of appropriate pivot elements in every step of elimination.,the maximum absolute value or t
2、he major elements as the pivot element,this improved Gaussian elimination method named Gauss pivot element elimination. There have 3 methods to select pivot element,Gaussian elimination with partial pivoting、scaled partial pivoting、complete pivoting.Through access to some data,I introduce the Gaussi
3、an elimination with complete pivoting briefly.Complete pivoting at the th step searches all the kentries,to find the entry to the largest magnitude.Both row ),()1(kjkiakijand column interchanges are performed to bring this entry to the pivot position.The specific steps:axaxaxaaxaxaxaaxaxaxannnnnnnnn
4、nnnn)0(1,)0(2)0(21)0(1)0(1, 2)0(22)0(221)0(21)0(1, 1)0(12)0(121)0(11,LMLLThe th elimination,find all(i=k,k+1,n; j=k,k+1n),the is kakij)1( Lak)1( the pivot element.aakijk)1()1(maxBoth row and column interchanges are performed to bring this entry to the pivot position.Move to (k,k).Until the n-1 step,
5、 the ak)1( original equation into the same equations on triangular solution:,)1(1,)1()2(1, 3)2(33)2(33)1(1, 2)1(23)1(232)1(22)0(1, 1)0(13)0(132)0(121)0(11axaaxaxaaxaxaxaaxaxaxaxannnnnnnnnnnnnnnnMLLLBackward substitution:Backward substitution is the solution of triangular systems .If,then0)1(annn . 1
6、 , 2,1,11)1()1(1,)1()1(1,)1(,LnininijjiijiniiiiinnnnnnnxaaaxaaxAlgorithm:function x=Gauss(A,b) B=A,b; n=length(A); x=zeros(n,2); for i=1:n x(i,1)=i; %x 第一列数字 i 代表 x(i) end for i=1:n-1 m,p=max(abs(B(i:n,i:n);%求绝对值最大系数所在行号和列号l,q=max(m); if m=0; disp(A 奇异) returnend if p(q)+i-1i %行变换 pm=p(q)+i-1; C(i:n
7、+1)=B(i,i:n+1); B(i,i:n+1)=B(pm,i:n+1); B(pm,i:n+1)=C(i:n+1); end if q+i-1i %列变换 q=q+i-1; D(1:n)=B(1:n,q); B(1:n,q)=B(1:n,i); B(1:n,i)=D(1:n); E(1:2)=x(q,:);%调换解的顺序 x(q,:)=x(i,:); x(i,:)=E(1:2); end for k=i+1:n %消元 am=B(k,i)/B(i,i); B(k,i:n+1)=B(k,i:n+1)-am*B(i,i:n+1); end end x(n,2)=B(n,n+1)/B(n,n)
8、; for i=n-1:-1:1 %回代 xx(i+1:n)=x(i+1:n,2); x(i,2)=(B(i,n+1)-B(i,i+1:n)*xx(i+1:n)/B(i,i); end for i=1:n-1 % 调换解的顺序 u,r=min(x(i:n,1); if r+i-1i r=r+i-1; xf(1:2)=x(i,1:2); x(i,1:2)=x(r,1:2); x(r,1:2)=xf(1:2); end end end For example P89,Exercises2 A=1.19 2.11 -100 1;14.2 -0.122 12.2 -1;0 100 -99.9 1;15.3 0.110 -13.1 - 1;b=1.12;3.44;2.15;4.16; x=Gauss(A,b)x =1.0000 0.17682.0000 0.01273.0000 -0.02074.0000 -1.1826