求解中值为0的线性方程组Math.Net系统 [英] Math.Net system of linear equations with a 0 value in solution

查看:114
本文介绍了求解中值为0的线性方程组Math.Net系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当矩阵的实际解决方案之一为0时,我正在尝试在Math.Net中求解矩阵,但是得到-NaN-作为结果.

I am trying to solve a Matrix in Math.Net when one of the actual solutions to the matrix is 0, but I am getting -NaN- as results.

这里是一个示例矩阵,为简单起见已被简化.

Here is an example matrix which has already been reduced for simplicity.

1 0  1 | 10000 
0 1 -1 | 1000
0 0  0 | 0

代码示例:

public void DoExample()
{
    Matrix<double> A = Matrix<double>.Build.DenseOfArray(new double[,] {
        { 1, 0, 1 }, 
        { 0, 1, -1 }, 
        { 0, 0, 0 }, 
    });

    Vector<double> B = Vector<double>.Build.Dense(new double[] { 10000, 1000, 0 });

    var result = A.Solve(B);
}

我希望获得的解决方案是 [10000,1000,0] .

The solution I am hoping to get to is [ 10000, 1000, 0 ].

如您所见,我想要的结果已经是增强向量.这是因为在此示例中,我使用Gauss-Jordan手工将矩阵简化为简化的行梯形形式(RREF).如果我可以在Math.Net中使用Gauss-Jordan运算来执行此操作,则可以检查RREF矩阵中是否存在全0行的情况.能做到吗?

As you can see, the result I want is already the augment vector. This is because I simplified the matrix to reduced row echelon form (RREF) by hand using Gauss-Jordan for this example. If I could somehow use a Gauss-Jordan operations within Math.Net to do this, I could check for the scenario where an all 0 row exists in the RREF matrix. Can this be done?

否则,使用现有的Math.Net线性代数求解器操作,对于变量之一来说,当0是唯一可能的解决方案时,我有什么办法可以识别?

Otherwise, is there any way I can recognize when 0 is the only possible solution for one of the variables using the existing Math.Net linear algebra solver operations?

谢谢!

推荐答案

例如,迭代求解器可以实际处理此问题

The iterative solver can actually handle this, for example

using MathNet.Numerics.LinearAlgebra.Double.Solvers;
A.SolveIterative(B, new MlkBiCgStab());

返回

[10000, 1000, 0]

有趣的是,对于MKL本机提供程序,它也适用于常规的Solve例程,但不适用于托管提供程序(如您所知)或例如. OpenBLAS本机提供程序.

Interestingly, with the MKL Native Provider this also works with the normal Solve routine, but not with the managed provider (as you have found out) nor with e.g. the OpenBLAS native provider.

这篇关于求解中值为0的线性方程组Math.Net系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆