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

firstly I need to apologize for my non mathematical language. Secondly I'll try to explain what I would like to calculate:

I have 3 series/rows of numbers and every series has 5 numbers(for example):

1.series: 2,4,9,1,7

2.series: 3,1,8,6,2

3.series: 8,0,6,0,9

sum of their columns should be as close as possible to this result:

result: 90,60,70,21,45

any series may/may not be multiplied by any multiplier

Could someone advice me what method shall be used for the calculation please? Any help is greatly appreciated

Thank you


share|cite|improve this question
up vote 0 down vote accepted

Put the system in the form $$ Xw = y $$ i.e. (note each series is in a column of $X$) $$ \begin{pmatrix} 2 & 3 & 8 \\ 4 & 1 & 0 \\ 9 & 8 & 6 \\ 1 & 6 & 0 \\ 7 & 2 & 9 \end{pmatrix} \begin{pmatrix} w_1 \\ w_2 \\ w_3 \end{pmatrix} = \begin{pmatrix} 90 \\ 60 \\ 70 \\ 21 \\ 45 \end{pmatrix} $$ Now to solve for $w,$ you can approximate it using least-squares as follows: $$ Aw = y \\ A^{T} A w = A^{T} y \\ w = (A^{T} A)^{-1} A^{T} y \\ $$ This will work as long as $A^{T} A$ is invertible.

share|cite|improve this answer
Hello, thank you very much for your answer. And how to resolve it in the case when A^{T}A is not invertible? Thank you – hugo Apr 1 '12 at 15:10
When $A^{T}A$ is not invertible this means that one series is an exact multiple of some other series. Remove the redundant one are proceed. – user2468 Apr 1 '12 at 16:55
Now I see. Could I have an additional question please? As least-squares gives me an approximation, it can happen that result of multiplication of resulting w value with X will be smaller than intended value y. Is there a way how to make every w big enough so that Xw >= y? And is it possible, at the same time, to make sure every Xw <= some other number? Many Thanks again! I am marking your reply as answer. – hugo Apr 1 '12 at 17:34
@hugo I am not quite sure. AFAIK, least squares minimizes the square of the error. In other words it minimizes $(Aw - y)^2.$ So it can give you $Aw$ bigger or smaller than $y.$ Think $(2.1-2)^2$ is small. Also $(1.9-2)^2$ is small. What you need is minimize the error (not squared). I have to go through my course notes to recall which method. But please go ahead and post a new question; maybe someone else know readily. – user2468 Apr 1 '12 at 17:49
Thank you very much for your help. I have posted new question link. We can meet there again :) Have a nice day.hugo – hugo Apr 1 '12 at 19:34

Let say you multiply the rows by $a,b$ and $c$, respectively. Then if you add them up you get the following system of equations $2a+3b+8c=90$, $4a+1b+0=60$, $9a+8b+6c=70$, $1a+6b+0c=21$ and $7a+2b+9c=45$. You can solve the system of equations as usual.

share|cite|improve this answer
Hello, thank you very much for your answer. Is it possible to alter these equations> 2a+3b+8c=90 ...etc. in such a way they would implement not only a,b,c but also d,e, the case there was more series than just 3? Again many thanks. – hugo Apr 1 '12 at 15:11

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.