chsalvia
asked on
Solving systems of equations
This question is not C-specific, and could very well relate to any language really.
What is the best method for solving a system of equations with a computer algorithm? Doing it by hand is merely a matter of using the substitution method, but I can't see how that would translate into code.
For example, suppose you have an equation:
y = a + bx
...where y and x are known values, but a and b are not. How can you implement a function that solves for a and b? Again, doing this by hand is very simple - simply solve for a or b, and then use substitution to find the other variable. But I can't imagine how that could be done using C code, where a variable cannot meaningfully represent an unknown. So how can this be achieved?
What is the best method for solving a system of equations with a computer algorithm? Doing it by hand is merely a matter of using the substitution method, but I can't see how that would translate into code.
For example, suppose you have an equation:
y = a + bx
...where y and x are known values, but a and b are not. How can you implement a function that solves for a and b? Again, doing this by hand is very simple - simply solve for a or b, and then use substitution to find the other variable. But I can't imagine how that could be done using C code, where a variable cannot meaningfully represent an unknown. So how can this be achieved?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Arthur_Wood : ultimately, there's no difference, except in which variables are the unknowns - it's still a system of linear equations.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
"y = a + bx
...where y and x are known values, but a and b are not"
To solve for a and b, you will need Two instances of the relation ( that is two separate pairs of x and y:
y1 = a + b*x1
y2 = a + b*x2
Then you can solve this pair of equations for a and b. (2 equations in 2 unknowns) - In general, you need as many equations and you have unknowns.
AW
...where y and x are known values, but a and b are not"
To solve for a and b, you will need Two instances of the relation ( that is two separate pairs of x and y:
y1 = a + b*x1
y2 = a + b*x2
Then you can solve this pair of equations for a and b. (2 equations in 2 unknowns) - In general, you need as many equations and you have unknowns.
AW
>> These are tto completely different problems, with two completely different solution methodologies.
I misunderstood you then ... I thought "a bunch of X,Y pairs" meant as much X,Y pairs as are needed to find a unique solution.
I misunderstood you then ... I thought "a bunch of X,Y pairs" meant as much X,Y pairs as are needed to find a unique solution.
LU would probably be easiest to implement, unless you're up to the task of a Cholesky decomposition.
So what you are saying is that you have a bunch of X,Y pairs, and you want to find the values of a and b that best represent that data. Is that correct.
or do you have a set of equations
A1 + B1 * X1 = Y1
A1 + B1 * X2 = Y2
and you want to solve this pair of equations for A1 abd B1, given values for X1, Y1, X2 and Y2.
AW