I want to know methods to get approximate solution for a system of n linear equations in n variables with one extra constraint. Let's consider a simpler case, say n=3. Consider the equations :
- 2x + y + z =1
- x + 2y + 3z = 1.5
- 2x + 2y + 7z = 2
I somehow obtain these 3 equations. Now I have one more constraint, that x+y+z should be as close as possible to 1. My task is to find such x,y,z. I think there doesn't exist any exact solution but is there any method/library in Python/Matlab to solve such a problem and get some approximate solution. I searched and found numpy.linalg,lstsq() but results are poor as per my requirements. Can somehow name some methods/libraries for this problem. It would be great if you tell me as many methods as possible.
Note that there can be any number of variables in my actual case, but I considered the case n=3 for simplicity.
What's so weird about this? It looks like ordinary least squares regression. If you include $x+y+z=1$ as a fourth equation, the least-squares solution turns out to be $(x,y,z)=(0.20455, 0.59091, 0.056818)$, with minimum sum of squared errors equal to $0.0284090909$.