How to find parameters that minimize the sum of squares, using Matlab?

I have a system of linear equations in the following form. How can I solve it in Matlab?

$$\operatorname*{argmin}_{a,b} \sum_{i,j} [X(i,j)-a\times Y(i,j)-b]^2$$

Where X and Y are known. I need to estimate a and b - which do not depend on (i,j).

• The solution is $a=b=c=0$. You don't have to use anything to calculate it. I suspect you have an error in your setting. Aug 11, 2014 at 16:28
• Thanks for your comment. I have modified the function. Aug 11, 2014 at 16:33
• Your expression doesn't depend on $a$. Aug 11, 2014 at 16:36
• sorry. modified again. Aug 11, 2014 at 16:37
• Now it doesn't depend on $c$. Aug 11, 2014 at 16:37

Let $A = \begin{bmatrix}Y(1,1) & 1 \\ Y(2,1) & 1 \\ \vdots & \vdots \\ Y(m,n) & 1 \end{bmatrix}$, $y = \begin{bmatrix}X(1,1) \\ X(2,1)\\ \vdots \\ X(m,n)\end{bmatrix}$, and $x = \begin{bmatrix}a \\ b\end{bmatrix}$.
Then, the problem can be rewritten as $\text{argmin}_{x}\|y-Ax\|_2^2$.
This is now the standard linear least squares problem. The solution is $\hat{x} = (A^TA)^{-1}A^Ty$.
• in MATLAB notation, it would be A\y. Aug 11, 2014 at 17:27