1 / 2

矩阵求逆代码.doc

//用来表示一个矩阵s_matrixmatrix;s_matrixmat;s_lines_matrix;
intnSize;//矩阵维数intnSign;//标记行列式正负void
voidprintstep(s_matrix&amp;_mat);intstep=0;outprint(s_matrix&amp;_mat);

++i){_mat[a][i]+=_mat[b][i]*k;}//endfor}voidwork1(s_matrix&amp;_mat)//

1]);}//endforjprintstep(_mat);}//endfori}void
_mat[j][i+1/_mat[i+1+1]);}printstep(_mat);}}void
makeunit(s_matrix&amp;_mat)//单位化{();forinti=0;inSize;
++i){();forintj=0;jnSize*2;++j){float
tmp=_mat[i][j]/_mat[i][i];if(fabs(tmp))tmp=0;
(tmp);}(line);//cout
endl;}_mat=mat;}voidprintstep(s_matrix&amp;_mat)//显示求的过程{cout&quot;第
&quot;++step&quot;步&quot;endl;forinti=0;inSize;++i){forintj=0;j2*nSize;
++j){if(fabs(_mat[i][j]))_mat[i][j]=0;cout_mat[i][j]&quot;&quot;;if(j==nSize-1)cout&quot;&quot;;}coutendl;}coutendl;}voidoutprint(s_matrix&amp;_mat)//输出函数{forinti=0;inSize;++i){forintj=nSize;j2*nSize;++j){cout_mat[i][j]&quot;&quot;;}coutendl;}}intmain(){step=0;();();cout&quot;*矩阵求逆*&quot;endl;cout&quot;*BillHsu*&quot;endl;cout&quot;&quot;endlendl;cout&quot;请输入矩阵维数(输入0退出):&quot;;cinnSize;if(nSize=0return0;forinti=0;inSize;++i){();cout&quot;输入第&quot;i+1&quot;行:&quot;endl;forintj=0;jnSize;++j){floattmp;cintmp;(tmp);//压入一个数到某行}forintj=0;jnSize;++j){if(i==j)();();}(line);//压入一行到矩阵}cout
work1(matrix);work2(matrix);makeunit(matrix);coutendl;
endl&quot;&quot;endl&quot;求逆结果:&quot;endl;outprint(matrix);cout&quot;&quot;endl;main();return0;}有图有真相: