Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|cite|improve this question
@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 is overfilled with old questions, bumped by your edits. See, for example, this question meta. Several questions in the linked tab there are related to this problem, too. – Martin Sleziak May 17 '13 at 8:11
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. – Martin Sleziak May 17 '13 at 8:13
@MartinSleziak: Thank you for your kindly reminding. Yes, I was just rollbacking the retagging by doraemonpaul 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. – 23rd May 17 '13 at 8:20
@Landscape I have posted a question on meta. Perhaps it would be better to discuss the issue there before starting some kind of editing/retagging war between several users. – Martin Sleziak May 17 '13 at 8:25
up vote 1 down vote accepted

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

share|cite|improve this answer

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.

share|cite|improve this answer

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.