From: Joseph M. Newcomer on
I guess I don't understand the question.
On Fri, 11 Jun 2010 09:41:17 +0200, Andreas Bauer <com(a)news.de> wrote:

>Hello Joseph
>>
>> http://en.wikipedia.org/wiki/Regression_analysis
>> ****
>>>
>>>
>>> Thanks. Regards Andreas
>> Joseph M. Newcomer [MVP]
>it is not clear.
>On my Excel sheet, you see may problem
>
>Two axis
>
>x
>y
>
>Customer insert the values in mm, axis controller needs steps.
>First I should calibrate the system.
*****
You are discussing a problem for which you have provided no useful information. So it
is impossible to figure out what the intent is, or what the numbers mean, or why I would
want to interpret them in any particular way.

This isn't a really good problem description.
*****
>http://www.fileuploadx.de/49586
*****
This produces nothing useful. It tellsb me the page is invalid, and redirects me to

http://www.fileuploadx.de/index.php

which is perplexing, and since I've lost most of my German vocabulary, unintelligible.
joe
*****
>
>How?
>How I get a,b and the offset c?
>
>Do you have a step by step instruction. Tutorial?
>
>Thanks.
>Regards Andreas
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Andreas Bauer on
Hello Joseph M. Newcomer,
> I guess I don't understand the question.
sorry.

Maybe now a little bit better
http://www.fileuploadx.de/492401

First I have a axis x
The user want to insert the values in mm.
But I should send in C++ or in C# the steps,units to the x controller
(Step motor)

In C# I found a code, but I'm not sure is working or not.
[Linear regression of polynomial coefficients]
http://www.trentfguidry.net/post/2009/08/01/Linear-regression-polynomial-coefficients.aspx

[Linear and multiple linear regression]
http://www.trentfguidry.net/post/2009/07/19/Linear-multiple-regression.aspx

I should also to understand the algorithm by hand. That is my problem.
Where is a good instruction.
Maybe you can help me.

Thanks a lot.

Regards Andreas

For a first order polynomial (a line), the equation is:
Y = A + BX
For this equation, z0 is 1 and z1 is X, and y is Y.
This is done in the code shown below.
double[] x = new double[] { 2.3601, 2.3942, 2.4098, 2.4268,
2.4443, 2.4552, 2.4689, 2.4885, 2.5093, 2.5287 };
double[] y = new double[] { 133.322, 666.612, 1333.22,
2666.45, 5332.9, 7999.35, 13332.2, 26664.5, 53329, 101325 };
int nPolyOrder = 1;
double[,] z = new double[y.Length, nPolyOrder + 1];
for (int i = 0; i < y.Length; i++)
{
z[i, 0] = 1.0;
z[i, 1] = x[i];
}
double[] coefs = Polynomial.Regress(z, y);


public static double[] Regress(double[,] z, double[] y)
{
//y=a0 z1 + a1 z1 +a2 z2 + a3 z3 +...
//Z is the functional values.
//Z index 0 is a row, the variables go across index 1.
//Y is the summed value.
//returns the coefficients.
Debug.Assert(z != null && y != null);
Debug.Assert(z.GetLength(0) == y.GetLength(0));

Matrix zMatrix = z;
Matrix zTransposeMatrix = zMatrix.Transpose(); KENNZEICHENooooo
Matrix leftHandSide = zTransposeMatrix * zMatrix;
Matrix rightHandSide = zTransposeMatrix * y;
Matrix coefsMatrix = leftHandSide.SolveFor(rightHandSide);
KENNZEICHENooooo

return coefsMatrix;
}
From: Andreas Bauer on
http://www1.minpic.de/bild_anzeigen.php?id=114609&key=55273016&ende

Hello,
the next problem is, I dimension x and y.
The new x, ist depend from y.

Measure
mm x mm y Units X Units Y
173,000 12,500 130,816 266,000
275,500 28,500 196,860 256,000
139,500 153,000 113,987 175,000


Greeting Andreas

From: Joseph M. Newcomer on
see below...
On Sat, 12 Jun 2010 20:59:35 +0200, Andreas Bauer <com(a)news.de> wrote:

>Hello Joseph M. Newcomer,
> > I guess I don't understand the question.
>sorry.
>
>Maybe now a little bit better
>http://www.fileuploadx.de/492401
>
>First I have a axis x
>The user want to insert the values in mm.
>But I should send in C++ or in C# the steps,units to the x controller
>(Step motor)
****
So, what is the protocol for sending a message to the controller? You have indicating
there is a stepper motor controller but not how it is connected, which is the most
essential part. Then, you have not indicated how the information that is sent along this
channel is encoded, so there's no way to tell what is going on. Typically, stepper motors
increment one step at a time, and any relationship between mm and steps is because of the
mechanical couplings between the motor and the object being moved. So you need to know
how many steps are required per mm of motion. You hve not revealed this.

Most systems are isotropic, that is, one step in x and one step in y are the same linear
distance on the final motion, just at 90-dgree angles to each other. An anisotropic
system has different mappings of steps-to-x-distance and steps-to-y-distance. Is your
system isotropic or anisotropic?

None of this has much to do with C++, C#, MFC, or anything else. I can't write code to
send an undefined sequence of bytes across an undefined interface to effect an undefined
result, in any language.
*****
>
>In C# I found a code, but I'm not sure is working or not.
>[Linear regression of polynomial coefficients]
>http://www.trentfguidry.net/post/2009/08/01/Linear-regression-polynomial-coefficients.aspx
****
But what's this got to do with stepping distances in mm?

Regression is involved in discovering the coefficients of a polynomial function that is
based on the analysis of statistically-acquired data. If I measure the parameters of two
variables, one of which is dependent on the other, the regression analysis allows me to
discover in the equation t = f(w) what the expected value of t will be, given a value w,
by having a function of some polynomial in terms of w, e.g.,
t = k0 * w + k1 * w**2 + k2 * w**3 +...
(or some other polynomial, I'm trying to discover the ki values)

BUt this has little, if anything, to do with moving a stepping motor.

Regression analysis is one problem. Moving a stepping motor is an unrelated problem, and
that's where I'm not seeing how one relates in any way to the other.
*****
>
>[Linear and multiple linear regression]
>http://www.trentfguidry.net/post/2009/07/19/Linear-multiple-regression.aspx
****
Yes, but what does this have to do with moving the stepping motor?
joe
****
>
>I should also to understand the algorithm by hand. That is my problem.
>Where is a good instruction.
>Maybe you can help me.
>
>Thanks a lot.
>
>Regards Andreas
>
>For a first order polynomial (a line), the equation is:
>Y = A + BX
>For this equation, z0 is 1 and z1 is X, and y is Y.
>This is done in the code shown below.
> double[] x = new double[] { 2.3601, 2.3942, 2.4098, 2.4268,
>2.4443, 2.4552, 2.4689, 2.4885, 2.5093, 2.5287 };
> double[] y = new double[] { 133.322, 666.612, 1333.22,
>2666.45, 5332.9, 7999.35, 13332.2, 26664.5, 53329, 101325 };
> int nPolyOrder = 1;
> double[,] z = new double[y.Length, nPolyOrder + 1];
> for (int i = 0; i < y.Length; i++)
> {
> z[i, 0] = 1.0;
> z[i, 1] = x[i];
> }
> double[] coefs = Polynomial.Regress(z, y);
>
>
> public static double[] Regress(double[,] z, double[] y)
> {
> //y=a0 z1 + a1 z1 +a2 z2 + a3 z3 +...
> //Z is the functional values.
> //Z index 0 is a row, the variables go across index 1.
> //Y is the summed value.
> //returns the coefficients.
> Debug.Assert(z != null && y != null);
> Debug.Assert(z.GetLength(0) == y.GetLength(0));
>
> Matrix zMatrix = z;
> Matrix zTransposeMatrix = zMatrix.Transpose(); KENNZEICHENooooo
> Matrix leftHandSide = zTransposeMatrix * zMatrix;
> Matrix rightHandSide = zTransposeMatrix * y;
> Matrix coefsMatrix = leftHandSide.SolveFor(rightHandSide);
>KENNZEICHENooooo
>
> return coefsMatrix;
> }
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Andreas Bauer on
Hello Arne,
works well with C#. Maybe you have some hints with C++?


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();
}