Hello Arne,
works well. Thanks a lot. The math. assembly looks well.
The link it is not easy to understand all.
b = inv(x'x)x'y
I hope the last questions.
Why this way? This way is correct, I'm sure.
StepsToAxis<=> UserCoordinatesInMM
fx = a*x + b*y + c
and not the simplest way
fx = a*x + b
How is call in mathematics?
Both 'Linear Regression' ?
How looks the calculation, if y not depend from x.
Can you make an example? Maybe, I hope then is clear for me, to see the
differents.
How is the best way to Round? Which function?
int stepsToAxisXInteger = Convert.ToInt32(stepsToAxisX);
int stepsToAxisXInteger = Convert.ToInt32(stepsToAxisX + 0.5);
I can calculate this way, it is easy
stepsToAxisX = b[0] * userX + b[1] * userY + b[2];
If I want to use the matrix
How is here the best way? Can you make a simple example?
For example, I have 10 new values, I know the factors b[0] b[1] b[2];
10
20
30
40
50
....
100
User in MM ---- Black Box ----- Steps to axis, axis move
Picture, calculate by hand.
http://www1.minpic.de/bild_anzeigen.php?id=114769&key=72372343&ende
Excel sheet
See sheet - Three Variables are not know
http://www.fileuploadx.de/665288
Greeting Andreas
http://www.mathdotnet.com/downloads/Iridium-2008-8-16-470.ashx
fx = 0,639237208990945*x + 0,0326366299017556*y + 19,8200049707945
fy = 0,00341428308423573*x + -0,646872751008385*y + 273,495238414032
fx = a*x + b*y + c
using MathNet.Numerics.LinearAlgebra; // Assembly notwendig.
private void btnCalc_Click(object sender, EventArgs e)
{
double[] fx = { 130.816, 196.860, 113.987 };
double[] fy = { 266.000, 256.000, 175.000 };
double[] x = { 173.0, 275.5, 139.5 };
double[] y = { 12.5, 28.5, 153};
double[] b;
Solve(fx, out b, x, y);
Console.WriteLine("fx = " + b[0] + "*x + " + b[1] + "*y + "
+ b[2]);
// Steps to axis x
double userX = 40.4;
double userY = 90.5;
double stepsToAxisX = b[0] * userX + b[1] * userY + b[2];
userX = 173.0;
userY = 12.5;
stepsToAxisX = b[0] * userX + b[1] * userY + b[2];
int stepsToAxisXInteger = Convert.ToInt32(stepsToAxisX);
Solve(fy, out b, x, y);
Console.WriteLine("fy = " + b[0] + "*x + " + b[1] + "*y + "
+ b[2]);
//Console.ReadKey();
}
private static void Solve(double[] f, out double[] b, double[]
x, double[] y)
{
Vector one = Vector.Ones(x.Length);
Vector x2 = Vector.Create(x);
Vector y2 = Vector.Create(y);
Matrix xy3 = Matrix.CreateFromColumns(new List<Vector> {
x2, y2, one });
Vector f2 = Vector.Create(f);
Matrix f3 = Matrix.CreateFromColumns(new List<Vector> { f2 });
Matrix b3 = xy3.Solve(f3);
Vector b2 = b3.GetColumnVector(0);
b = b2.CopyToArray();
}