0
$\begingroup$

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?

  • 0
    @Landscape It is useful to have correct tags, but please, do not retag too many questions at once, since then the front page of the [active tab](http://math.stackexchange.com/questions?sort=active) is overfilled with old questions, bumped by your edits. See, for example, [this question](http://meta.math.stackexchange.com/questions/5068/how-much-bumping-is-too-much) meta. Several questions in the linked tab there are related to this problem, too.2013-05-17
  • 0
    ok, now I've noticed that you were only doing rollbacks @Landscape. But I think that the concern that not too many old questions should be bumped still stands.2013-05-17
  • 0
    @MartinSleziak: Thank you for your kindly reminding. Yes, I was just rollbacking the [retagging by doraemonpaul](http://math.stackexchange.com/users/30938/doraemonpaul?tab=activity) to their original status. It is my fault that I didn't realize that my behavior would lead to the bad result mentioned by you.2013-05-17
  • 0
    @Landscape I have posted a question on [meta](http://meta.math.stackexchange.com/questions/9602/should-questions-on-matrices-and-matrix-equations-be-also-tagged-as-linear). Perhaps it would be better to discuss the issue there before starting some kind of editing/retagging war between several users.2013-05-17

2 Answers 2

2

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

1

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.