Solving $X^{T}Xw = X^{T}y$ for $w$ in Octave / MATLAB

219 Views Asked by At

I have a matrix $X$ and a vector $y$, how do I solve the following equation for $w$:

$$ X^{T}Xw = X^{T}y $$

in Octave and/or MATLAB?

2

There are 2 best solutions below

0
On BEST ANSWER

You don't have to worry about multiplying by $X^T$ to get a square matrix. Just type "X\y"

0
On

The literal translation of $$w = (X^{T}X)^{-1}X^{T}y$$ is

w = inv(X * X') * X' * y or better w = linsol(X*X', X'*y)

but you should better use lsqlin see Emre's answer.