来源:http://zhidao.baidu.com/link?url=DiqAbq9YUYn3z7QjxGGoF0PLZwN-Y9ecqKB7Gy38JWRD1riMIYukVKXKq88pxtWLwIl6-iOUf2p3liE51phEe_

private double[,] ReverseMatrix( double[,] dMatrix, int Level )
{
double dMatrixValue = MatrixValue( dMatrix, Level );
if( dMatrixValue == ) return null; double[,] dReverseMatrix = new double[Level,*Level];
double x, c;
// Init Reverse matrix
for( int i = ; i < Level; i++ )
{
for( int j = ; j < * Level; j++ )
{
if( j < Level )
dReverseMatrix[i,j] = dMatrix[i,j];
else
dReverseMatrix[i,j] = ;
} dReverseMatrix[i,Level + i ] = ;
} for( int i = , j = ; i < Level && j < Level; i++, j++ )
{
if( dReverseMatrix[i,j] == )
{
int m = i;
for( ; dMatrix[m,j] == ; m++ );
if( m == Level )
return null;
else
{
// Add i-row with m-row
for( int n = j; n < * Level; n++ )
dReverseMatrix[i,n] += dReverseMatrix[m,n];
}
} // Format the i-row with "1" start
x = dReverseMatrix[i,j];
if( x != )
{
for( int n = j; n < * Level; n++ )
if( dReverseMatrix[i,n] != )
dReverseMatrix[i,n] /= x;
} // Set 0 to the current column in the rows after current row
for( int s = Level - ; s > i;s-- )
{
x = dReverseMatrix[s,j];
for( int t = j; t < * Level; t++ )
dReverseMatrix[s,t] -= ( dReverseMatrix[i,t]* x );
}
} // Format the first matrix into unit-matrix
for( int i = Level - ; i >= ; i-- )
{
for( int j = i + ; j < Level; j++ )
if( dReverseMatrix[i,j] != )
{
c = dReverseMatrix[i,j];
for( int n = j; n < *Level; n++ )
dReverseMatrix[i,n] -= ( c * dReverseMatrix[j,n] );
}
} double[,] dReturn = new double[Level, Level];
for( int i = ; i < Level; i++ )
for( int j = ; j < Level; j++ )
dReturn[i,j] = dReverseMatrix[i,j+Level];
return dReturn;
} private double MatrixValue( double[,] MatrixList, int Level )
{
double[,] dMatrix = new double[Level, Level];
for( int i = ; i < Level; i++ )
for( int j = ; j < Level; j++ )
dMatrix[i,j] = MatrixList[i,j];
double c, x;
int k = ;
for( int i = , j = ; i < Level && j < Level; i++, j++ )
{
if( dMatrix[i,j] == )
{
int m = i;
for( ; dMatrix[m,j] == ; m++ );
if( m == Level )
return ;
else
{
// Row change between i-row and m-row
for( int n = j; n < Level; n++ )
{
c = dMatrix[i,n];
dMatrix[i,n] = dMatrix[m,n];
dMatrix[m,n] = c;
} // Change value pre-value
k *= (-);
}
} // Set 0 to the current column in the rows after current row
for( int s = Level - ; s > i;s-- )
{
x = dMatrix[s,j];
for( int t = j; t < Level; t++ )
dMatrix[s,t] -= dMatrix[i,t]* ( x/dMatrix[i,j] );
}
} double sn = ;
for( int i = ; i < Level; i++ )
{
if( dMatrix[i,i] != )
sn *= dMatrix[i,i];
else
return ;
}
return k*sn;
}
调用如下:
double[,] dMatrix = new double[,]{{,,},{,,},{,,}};
double[,] dReturn = ReverseMatrix( dMatrix, );
if( dReturn != null )
{
for( int i=; i < ; i++ )
Debug.WriteLine( string.Format( "{0} {1} {2}",
dReturn[i,], dReturn[i,],dReturn[i,] ) );
}

最新文章

  1. 今天工作中遇到的问题!echart.js
  2. (七)理解angular中的module和injector,即依赖注入
  3. PL/0语言编译器的设计与实现
  4. VirtualBox是什么
  5. SQL游标
  6. sql server代理中作业执行SSIS包失败
  7. 郑州尚学堂:链表的C语言如何实现动态内存分配
  8. 201521123098 《Java程序设计》第7周学习总结
  9. vs2017 winform打包
  10. dp 洛谷P1977 出租车拼车 线性dp
  11. web 和 java 资源
  12. c# 获取百度最后的url
  13. 算法训练 Tricky and Clever Password
  14. python 简单搭建阻塞式单进程,多进程,多线程服务
  15. 关于VS2010 C#使用DirectX的问题[英]
  16. spring boot tomcat 线程数 修改初始线程数 统计性能 每百次请求耗时
  17. 文件批量加密重命名--python脚本AND mysql命令行导入数据库
  18. Drag &amp; drop a button widget
  19. CoreAnimation confusion: CATransaction vs CATransition vs CAAnimationGroup?
  20. MyBatis 基本构成与框架搭建

热门文章

  1. filter、map、sorted和reduce函数
  2. 记录一下putty的pscp的用法【转】
  3. Flash硬件原理
  4. 题解-BOI 2004 Sequence
  5. java interview
  6. 004_LVS及haproxy
  7. java使用RunTime调用windows命令行
  8. Kubernetes重要概念理解
  9. Linux系统的命令别名功能(转)
  10. 前端 -----jQuery的事件绑定和解绑