Regression/linear equation solving

1 view (last 30 days)
I have a set of over defined equations that do not fit perfectly. The problem resembles this simpler problem in nature:
x1 = 0.8 + x2,
x1 = 1.2 + x2
x2 = 1.5 + x3
x3 = -3 + x1
x4 = -1.5 + x2
x4 = -1.7 +x2
I'm trying to solve for the x's, and they have values which are relative to one another, so i can assume for example that one of the x's is 0.
Because this is over defined, I would need to do a regression of some sort.
I'm feeling a bit foggy today, but I'm sure there's got to be a way to do this in MATLAB. Can anyone provide me with some sample code?

Accepted Answer

Tom Lane
Tom Lane on 5 Mar 2012
Bring all the x's over to the left of the equal sign. Then a matrix representation of those equations is this:
1 -1 0 0
1 -1 0 0
0 1 -1 0
-1 0 1 0
0 -1 0 1
0 -1 0 1
Let this be A, and define a vector b that is is the vector of constant terms, and your least squares solution is A\b. MATLAB will automatically set one of the x values to zero for you.
  1 Comment
Matt
Matt on 5 Mar 2012
Thanks, this is exactly what I was looking for

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!