各位老师,我用breeze的pinv求矩阵伪逆,为什么结果是错的?下面是一段测试代码:
package AE_LOC
import breeze.linalg.{DenseMatrix, eig, inv, pinv}
/**
* Created by Administrator on 2018/7/11.
*/
object Test_Matrix {
def main(args: Array[String]): Unit = {
//取MATLAB中第二次计算的结果
val A=DenseMatrix((1.0,0.000052849468204,-0.000141077142447,-0.000089904809261),
(1.0,0.000052913176697,-0.000140978731412,-0.000090021631624),
(1.0,0.000053199579186,-0.000140971328619,-0.000089864288907),
(1.0,0.000053166285325,-0.000140899813861,-0.000089996053789),
(1.0,0.000053368539372,-0.000140830212164,-0.000089985284831),
(1.0,0.000053031908518,-0.000141110407135,-0.000089745032264),
(1.0,0.000052959039354,-0.000141090707018,-0.000089819005131),
(1.0,0.000052992075982,-0.000140807429379,-0.000090243054323))
val deltaw=pinv(A.t*A)//*A.t*r
println(deltaw)
}
}
求解结果如下:
七月 14, 2018 5:12:46 下午 com.github.fommil.netlib.BLAS
警告: Failed to load implementation from: com.github.fommil.netlib.NativeSystemBLAS
七月 14, 2018 5:12:46 下午 com.github.fommil.netlib.BLAS
警告: Failed to load implementation from: com.github.fommil.netlib.NativeRefBLAS
七月 14, 2018 5:12:47 下午 com.github.fommil.netlib.LAPACK
警告: Failed to load implementation from: com.github.fommil.netlib.NativeSystemLAPACK
七月 14, 2018 5:12:47 下午 com.github.fommil.netlib.LAPACK
警告: Failed to load implementation from: com.github.fommil.netlib.NativeRefLAPACK
4.872723391844739E11 -8.402618428318382E14 2.2312732735908435E15 1.4246530975093118E15
-8.402618428281145E14 1.44896791033931622E18 -3.8476501203625242E18 -2.4566979259979945E18
2.2312732735986278E15 -3.8476501203929989E18 1.0217245392080683E19 6.5236404952027802E18
1.424653097499306E15 -2.4566979259916278E18 6.5236404951342039E18 4.1653054625770337E18
Process finished with exit code 0
而用MATLAB或Python求解结果是一致的:
1.0e+12 *
0.000000000000136 0.000000025810710 0.000000120865941 -0.000000174075492
0.000000025810710 4.142477448797149 0.652950358936210 1.420594988073896
0.000000120865942 0.652950358931182 1.316103334637498 -1.676153252853749
-0.000000174075494 1.420594988077356 -1.676153252871454 3.463037932613488