Possible Duplicate:
Solving a linear equation
I need to programmatically solve a system of linear equations in C# AND VB
Here's an example of the equations:
12.40 = a * 56.0 + b * 27.0 + tx
-53.39 = a * 12.0 + b * 59.0 + tx
14.94 = a * 53.0 + b * 41.0 + tx
I'd like to get the best approximation for a, b, and tx.
Should i use some sort of matrix class or something?
There are three ways to solve systems of linear equations in two variables: graphing. substitution method. elimination method.
Gauss-Jordan elimination is the most straightforward and easiest to understand method for solving a system of simultaneous linear equations like this. LU decomposition is a little more numerically stable, but your matrix doesn't look poorly conditioned so I don't think you need the extra complexity.
If you store the coefficients in a matrix, you can solve it by computing the LU decomposition of the matrix. I'm not terribly familiar with the exact algorithm, but wikipedia's pages on this should be a good starting point:
http://en.wikipedia.org/wiki/System_of_linear_equations#Solving_a_linear_system
http://en.wikipedia.org/wiki/LU_decomposition
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With