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

Let's say I have




where $a,b,c \geqslant 0$

What's the best way to find solutions for a, b and c so that the results of the sums are as close as possible to the terms on the right-hand side? My method has been a brute-force search but maybe there's a better way. I tagged this with 'matrices' because I didn't know what else to tag it with.

I've also thought about trying to find the variance of the variances to determine a best fit.

share|cite|improve this question
So the $n_i$, $p_i$ and $k_i$ are given? What do you mean by "the results of the sums are as close as possible to the terms on the right-hand sides"? – Johannes Kloos Mar 9 '12 at 16:07

First, rewrite the system as $Ax = d$: $$ \begin{pmatrix} n_1 & n_2 & n_3 \\ p_1 & p_2 & p_3 \\ k_1 & k_2 & k_3 \end{pmatrix} \begin{pmatrix} a \\ b \\ c \end{pmatrix} = \begin{pmatrix} n_T \\ p_T \\ k_T \end{pmatrix} $$ If $A$ is non-singular, i.e. $\operatorname{det}(A) \neq 0$, and $d \neq 0$, then the system has one solution, namely $$ x = A^{-1} d,$$ which might violate the condition $a,b,c \geqslant 0.$

However, if $\operatorname{det}(A) = 0$, then you are looking for a vector $x$ in the nullspace of $A$. You will have to find the nullspace basis of $A$: $\{ B_1, \ldots, B_{3-r} \}$, where $r = {\rm rank}(A)$. and form a vector $x = \sum B_i$ s.t. $x$ satisfies the conditions.

share|cite|improve this answer
This was a hint longer than a comment. – user2468 Mar 9 '12 at 15:56
I know how to solve when a,b,c can be less than zero. But that's not the case. I don't know where to start with your last paragraph. I'm not familiar enough with matrices to understand it. – Korgan Rivera Mar 9 '12 at 16:47
I'm assuming you're given $n_i$'s, $p_i$'s, $k_i$'s and $n_T, p_T, k_T$. Then you will form to linear system above and solve by $x = A{-1} d$ which will give you a vector of three values $x=(a,b,c)$. Now, in some cases, it happens that ${\rm det}(A) = 0$ and more than one solution exists. What you do in this case, is to find what is called the homogeneous solution. – user2468 Mar 12 '12 at 5:04
... A simple way to do so, is to move the RHS vector to LHS and have: $$ \begin{pmatrix} n_1 & n_2 & n_3 & n_T \\ p_1 & p_2 & p_3 & p_T\\ k_1 & k_2 & k_3 & k_T \end{pmatrix} \begin{pmatrix} a \\ b \\ c \end{pmatrix} =\begin{pmatrix} 0 \\ 0 \\ 0 \end{pmatrix} $$ The vector $x = (a,b,c)$ you're looking for is a nullspace vector of the matrix above. Think of the matrix as function that maps vectors to vectors. It really scrambles the entries of the vectors. In this case, it scrambles $x$ and produces the zero vector $(0,0,0)$. Finding a nullspace.. – user2468 Mar 12 '12 at 5:05
...basis is a standard operation in linear algebra. The basis is a general parametric formula for all such $x$'s. What you need to do in this case, is to search for parameters such that $x$ satisfies the conditions $a,b,c \ge 0$. – user2468 Mar 12 '12 at 5:06

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.