# from weighted average to single values

think about when you're computing a weighted average: you do something like

W = sum(amount*weight) / sum(weight)

Now I need to find every amount (amount0, amount1.....) starting from knowing the value of W and every single weight. Is this possible? I'm trying to find out an algorithm.

• i think this is impossible given just weighted average and each weight – Aang Aug 16 '12 at 10:29

It corresponds to $$w_1x+w_2y+...+w_Nz=W$$ with known coefficients $w_i$. Given W and $w_i$, clearly there is no unique solution for this system but multiple solutions..

• What I'm trying to do here is to find an average weighted margin. Each amount for me is a final sell price, so from W I can calculate sum(amounts) or I can take some hints from purchase prices..I know there's no a unique solution, but in addition I have some max min limit for each product price.. – user1400495 Aug 16 '12 at 10:49
• Yes I see. There is no unique solution but if you have a set of equations then you have a solution based on some "nice" criterion even if you have more equations than unknowns. en.wikipedia.org/wiki/Overdetermined_system Moreover I can suggest to have a look compressive sensing. en.wikipedia.org/wiki/Corollary I think they will help at any case – Seyhmus Güngören Aug 16 '12 at 11:01

As others have remarked, this is impossible. However if we are given a number of weighted averages, and the weights used to calculate each average, then we may be able to determine the original values. In general though we will need lots of weights to find the values, so it's really only an academic exercise.

So suppose there are $n$ values $a_1, ... , a_n$ that we want to find. We are given $m$ weighted averages: $$w_{11} a_1 + ... + w_{1n} a_n = W_1 \\ w_{21} a_1 + ... + w_{2n} a_n = W_2 \\ ...\\ w_{m1} a_1 + ... + w_{mn} a_n = W_m$$ First we require $m$ to be at least as large as $n$. We can write this in matrix form: $$\begin{pmatrix} w_{11} & w_{12} & ... &w_{1n} \\ w_{21} & w_{22} & ... &w_{2n} \\ .& .& ... & .\\ w_{m1} & w_{m2} & ... &w_{mn} \\ \end{pmatrix} \begin{pmatrix} a_1 \\ a_2 \\ . \\ a_n \end{pmatrix} = \begin{pmatrix} W_1 \\ W_2 \\ . \\ W_m \end{pmatrix}$$ Now we need to solve this equation to get the matrix/vector $$A = \begin{pmatrix} a_1 \\ a_2 \\ . \\ a_n \end{pmatrix}$$ on its own. There is a criteria for solving this from linear algebra: if we can find $n$ linearly independent rows in the matrix of $w$'s then we will be able to solve for the $a$'s. If we can't find $n$ linearly independent rows then we won't be able to solve for the $a$'s.

Here's an example on how to do it when you have two values. There are two naturally occurring isotopes of chlorine.
35Cl has a mass of 34.9689 amu.
37Cl has a mass of 36.9659 amu. Determine the abundance of each isotope.

From the periodic table the given mass is 35.453

The sum of the percentage of the abundances is 100% or 1.00 since we use decimals i.e. 75% = .75 Set one abundance to x and the other abundance to 1 - x.

(34.9689 * x) + (36.9659 * (1-x)) = 35.453 34.9689X + 36.9659 - 36.9659x = 35.453

solve for x.

x = .7576 so the abundance of 35Cl with mass of 34.9689 amu is 75.76% and the other isotope is 24.24%

For reference: http://www.chemteam.info/Mole/AvgAtomicWt-Reverse.html