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

303 Views Asked by At

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).

1

There are 1 best solutions below

1
On BEST ANSWER

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$.