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 3 numbers that physically must add up to zero. Unfortunately, each is obtained from a noisy measurement and they don't add up exactly. Assuming the noise is Gaussian and given 3 corresponding standard deviations (one for each number), what is the correct way to change the numbers so that they add up correctly? It seems like the number with the smallest stdev should be moved least, etc...

It feels like a least squares problem, and I think I can do this with an optimizer like Nelder Mead or something, but a closed form solution would be very welcome.

share|cite|improve this question
Closing three numbers? Could you edit in a more intelligible and more informative title, please? – Gerry Myerson Sep 4 '12 at 2:25
By the way, do you know that there's a stackexchange site for statistics questions? – Gerry Myerson Sep 4 '12 at 2:27
I'm happy to re-title it if you have a good suggestion. In the realm I'm working in, we refer to this as a "closure property" of those three numbers. As for which stack exchange to use, meh - it seems like a shade of grey to me. – xscott Sep 5 '12 at 3:02
I wasn't aware of that usage of the word. I withdraw my objection (although I think maybe a title like "Adjusting noisy measurements so they sum to zero" might make it easier for future generations to find this page). As for choice of site, my thought was that if you didn't get a useful answer here, you might try there - but it seems to have worked for you here, so, never mind. – Gerry Myerson Sep 5 '12 at 4:59
up vote 1 down vote accepted

The correct way to change the numbers, from the maximum likelihood perspective, is to use $$ b_1^\prime = \frac { a_1 b_1 ( a_2 + a_3 ) - a_2 a_3 ( b_2 + b_3 ) } { a_1 a_2 + a_2 a_3 + a_3 a_1 } $$ and similarly for $b_2$ and $b_3$ where $b_i$ is the $i$th data point and $a_i$ is $1 / \sigma_i^2$ where $\sigma_i$ is $i$th standard deviation. Wolfram alpha was used to get this closed form solution of the constrained least squares problem.

share|cite|improve this answer
Empirically this seems to work. Thank you very much! I would like to see what you fed into Wolfram Alpha to get the results so I can understand that it's correct. – xscott Sep 5 '12 at 3:07
The edit history has more details, but I didn't do anything more interesting than type the log likelihood and the constraint into wolfram alpha. – binn Sep 5 '12 at 5:05

X$_1$=a$_1$+e$_1$,X$_2$=a$_2$+e$_2$, and X$_3$=a$_3$+e$_3$ where a$_1$+a$_2$+a$_3$=0.

e$_1$ has mean 0 and variance σ$_1$$^2$ e$_2$ has mean 0 and variance σ$_2$$^2$ e$_3$ has mean 0 and variance σ$_3$$^2$

X$_1$+X$_2$+X$_3$=a$_1$+a$_2$+a$_3$+e$_1$+e$_2$+e$_3$=0+e$_1$+e$_2$+e$_3$ is Gaussian

E(X$_1$+X$_2$+X$_3$)=0 Var(X$_1$+X$_2$+X$_3$)=σ$_1$$^2$+σ$_2$$^2$+σ$_3$$^2$

If you are given that X$_1$+X$_2$+X$_3$ =a ≠ 0, Set Z=X$_1$+X$_2$+X$_3$-a. Then Z=0.

E(a)=0 and Var(a)=σ$_1$$^2$+σ$_2$$^2$+σ$_3$$^2$ and a is Gaussian. So the question is how to split a into three parts s$_1$, s$_2$, s$_3$ such that s$_1$+s$_2$+s$_3$=a where s$_i$ is the amount X$_i$ is adjusted. Assume you want to

minimize E[(X$_1$-s$_1$)$^2$+(X$_2$-s$_2$)$^2$+(X$_3$-s$_3$)$^2$] where s$_1$+s$_2$+s$_3$=a. The question is how to choose s$_1$, s$_2$ and s$_3$ given a.

E[(X$_1$-s$_1$)$^2$+(X$_2$-s$_2$)$^2$+(X$_3$-s$_3$)$^2$] =

EX$_1$$^2$+E[s$_1$$^2$] + EX$_2$$^2$+E[s$_2$$^2$]+EX$_3$$^2$+E[s$_3$$^2$]=

E[s$_1$$^2$] +E[s$_2$$^2$]+E[s$_3$$^2$]=s$_1$$^2$+s$_1$$^2$+s$_3$$^2$.

Since s$_1$=a-s$_2$-s$_3$, s$_1$$^2$+s$_1$$^2$+s$_3$$^2$=(a-s$_2$-s$_3$)$^2$+s$_2$$^2$+s$_3$$^2$

share|cite|improve this answer
Thank you for your reply. I like the way you're thinking about it, but I don't see how to get the answer I'm looking for from your last line. I wish I could combine your rigor with binn's solution below which seems to give the right answers. – xscott Sep 5 '12 at 3:05

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.