Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

How do I solve such an eqation? (I know how to solve Mx=n using gaussian elimination but I don't know how to handle 2 variables.


share|improve this question
If $x$ and $y$ are "unknown" vectors, there will almost always be infinitely many solutions. Is it that you want to find one non-trivial solution? –  André Nicolas Feb 27 '12 at 14:15
yes, I want to find a non-trivial solution that minimizes the distance between Mx and Ny –  user25843 Feb 27 '12 at 14:18
This link provides some ideas: cs.mtu.edu/~shene/COURSES/cs3621/NOTES/INT-APP/… –  Emmad Kareem Feb 27 '12 at 15:22
add comment

2 Answers

up vote 0 down vote accepted

It seems to me like you're trying to solve the least squares problem Mx-Ny=0, in other words find the vectors x,y that minimize the euclidean norm of the vector (Mx-Ny). Let's assume that your matrices are of dimensions M[rowsM][columnsM] and N[rowsN][columnsN],then your vectors would be of dimension x[columnsM] and y[columnsN]. Because the obvious solution to your problem is the trivial solution where y=x=0 you have to give either to x or y vector some constant value in order to compute the best approximation of the other one. This paper contains the basic about least squares approximation: Least squares approximation

Basically all you need is (assuming you initialize vector y): $\vec{x}=(M^{T}M)^{-1}M^{T}(N\vec{y})$ So by finding the inverse of $M^{T}M$ and performing some matrix computations you're done.

share|improve this answer
Thanks for your answer :) but still - I'm not sure that I understand: if you take x and assign it some constant vector, you'll then find the y which minimizes the distance to this specific x. But isn't is possible that there exist some other x and y that result in a smaller distance? –  user25843 Feb 27 '12 at 15:29
Think of the simple 3 equations following: a1*x+b1*y=0 a2*x+b2*y=0 a3*x+b3*y=0 where a,b random constants.The only exact solution of this system is the trivial one x=y=0. When you assign y a constant value then, you can "compute" 3 different "solutions" for x by solving one of the 3 equations.Instead of that you compute one x value tha minimizes the sum of the quadratic errors in each equation so you find the best solution for the WHOLE system and not only one of the equations. It's the same principle with multiple variables->vectors.. –  chemeng Feb 27 '12 at 15:30
add comment

I presume you know either $x$ or $y$. If $M$ and $N$ are large, then you should use the conjugate gradient method. Otherwise you can directly invert (or pseudo-invert) $M$ or $N$ as appropriate.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.