Reputation: 70327
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)
Upvotes: 0
Views: 266
Reputation: 79551
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);
Upvotes: 1