I need to solve an underdetermined linear equations system in c#. For example
Underdetermined linear equations system:
x + 3 = y + z
x + w = 2
Result:
x = r1
y = -r2 + r1 + 3
z = r2
w = 2 - r1
and now I initialize r1 and r2 with 3 and 4 to get one of my retults.
I try to use Math.Net in c# like this
using MathNet.Numerics.LinearAlgebra;
namespace SolveLinearEquations
{
class Program
{
static void Main(string[] args)
{
var A = Matrix<double>.Build.DenseOfArray(new double[,] {
{ 1, -1, -1, 0 },
{ 1, 0, 0, 1 }
});
var B = Vector<double>.Build.Dense(new double[] { -3, 2 });
var X = A.Solve(B);
}
}
}
but I take an exception like this
System.ArgumentException: 'Matrix dimensions must agree: 2x4.'
Can't Math.Net solve an underdetermined linear equations system or ...? What's the best solution for this?