0

Given these values:

x1 = {1, 3, 6, 8} 
x2 = {2 ,8, 5, 10} 
y = {8.6, 30.8, 34.1, 53.8} 

And this formula

y = m1 * x1 + m2 * x2  

Is there a way to determine m1 and m2 using Math.NET or an equivalent C# library?

(The expected result for these values is m1=3.6 and m2=2.5)

Piotr Leniartek
  • 1,177
  • 2
  • 14
  • 33
Jonathan Allen
  • 68,373
  • 70
  • 259
  • 447

1 Answers1

1

This is just a system of linear equations: solve Xm = y for m given X and y.

var X = Matrix<double>.Build.DenseOfArray(new double[,] {
    { 1, 2 },
    { 3, 8 },
    { 6, 5 },
    { 8, 10 }
});
var y = Vector<double>.Build.Dense(new double[] {
    8.6,
    30.8,
    34.1,
    53.8
});
var m = X.Solve(y);
Timothy Shields
  • 75,459
  • 18
  • 120
  • 173