文件名称:高斯迭代法解矩阵方程
文件大小:1KB
文件格式:NONE
更新时间:2013-12-05 05:31:37
高斯,迭代法,解矩阵方程
高斯迭代法解矩阵方程 function [a,b] = gaussj(a,n,np,b,m,mp) for j=1:n ipiv(j)=0; end for i=1:n big=0; for j=1:n if(ipiv(j)~=1) for k=1:n if (ipiv(k)==0) if (abs(a(j,k))>=big) big=abs(a(j,k)); irow=j; icol=k; end elseif (ipiv(k)>1) pause, dips('gaussj') end end end end ipiv(icol)=ipiv(icol)+1; if (irow~=icol) for l=1:n dum=a(irow,l); a(irow,l)=a(icol,l); a(icol,l)=dum; end for l=1:m dum=b(irow,l); b(irow,l)=b(icol,l); b(icol,l)=dum; end end indxr(i)=irow; indxc(i)=icol; if (a(icol,icol)==0), pause, disp('in gaussj'), end pivinv=1/a(icol,icol); a(icol,icol)=1; for l=1:n a(icol,l)=a(icol,l)*pivinv; end for l=1:m b(icol,l)=b(icol,l)*pivinv; end for ll=1:n if(ll~=icol) dum=a(ll,icol); a(ll,icol)=0; for l=1:n a(ll,l)=a(ll,l)-a(icol,l)*dum; end for l=1:m b(ll,l)=b(ll,l)-b(icol,l)*dum; end end end end for l=n:-1:1 if(indxr(l)~=indxc(l)) for k=1:n dum=a(k,indxr(l)); a(k,indxr(l))=a(k,indxc(l)); a(k,indxc(l))=dum; end end end return