Question

We are using a programming language that does not have a linear regression function in it. We have already implemented a single variable linear equation:

y = Ax + B

and have simply calculated the A and B coefficents from the data using a solution similar to this Stack Overflow answer.

I know this problem gets geometrically harder as variables are added, but for our purposes, we only need to add one more:

z = Ax + By + C

Does anyone have the closed form equations, or code in any language that can solve for A, B and C given an array of x, y, and z's?

Was it helpful?

Solution

so you have three linear equations

k = aX1 + bY1 + cZ1
k = aX2 + bY2 + cZ2
k = aX3 + bY3 + cZ3

What you can do is rewrite it as matriz

| x1 y1 z1 | | a |   | k |
| x2 y2 z2 | | b | = | k |
| x3 y3 y3 | | c |   | k |

to work out [a b c ] do the following matrix operation

| a |              | x1 y1 z1 |     | k |
| b | =  inverse(  | x2 y2 z2 | )   | k |
| c |              | x3 y3 y3 |     | k |

The formula for a 3x3 matrix inverse can be found here

OTHER TIPS

Yes, it's an easy linear algebra problem if you think of it the way Gil Strang does it. Here's a written explanation.

Can you use MatLab or does the calculation have to occur inside your software?

MatLab instructions on multiple regression analysis.

Integrating MatLab with C#.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top