randRangeWeighted(1, 4, 1, 0.4) randRangeWeighted(1, 4, 1, 0.4) randRangeWeighted(1, 4, 1, 0.4)
WEIGHT_A + WEIGHT_B + WEIGHT_C randRangeNonZero(-9, 9) randRangeExclude(-9, 9, [0, XA]) randRangeNonZero(-9, 9, [0, XA, XB]) randRangeExclude(-9, 8, [-2, -1, 0, 1]) randRangeExclude(-9, 8, [-2, -1, 0, 1, YA]) randRangeExclude(-9, 8, [-2, -1, 0, 1, YA, YB]) XA * WEIGHT_A + XB * WEIGHT_B + XC * WEIGHT_C YA * WEIGHT_A + YB * WEIGHT_B + YC * WEIGHT_C SUM_X / TOTAL_WEIGHT SUM_Y / TOTAL_WEIGHT fractionReduce(SUM_X, TOTAL_WEIGHT) fractionReduce(SUM_Y, TOTAL_WEIGHT)

What is the average of the points `\blue{A}`, `\pink{B}` and `\green{C}` with weights `\blue{WEIGHT_A}`, `\pink{WEIGHT_B}` and `\green{WEIGHT_C}` respectively?

graphInit({ range: 10, scale: 20, tickStep: 1, labelStep: 1, unityLabels: false, labelFormat: function( s ) { return "\\small{" + s + "}"; }, axisArrows: "<->", }); label([XA, YA], "A", "above", { color: BLUE }); label([XB, YB], "B", "above", { color: PINK }); label([XC, YC], "C", "above", { color: GREEN }); circle([XA, YA], 0.15, { stroke: BLUE, fill: BLUE, strokeWidth: 1.5 }); circle([XB, YB], 0.15, {stroke: PINK, fill: PINK, strokeWidth: 1.5 }); circle([XC, YC], 0.15, { stroke: GREEN, fill: GREEN, strokeWidth: 1.5 });

`(`XM, YM`)`

For a weighted average, each value is multiplied by a weight, then the results are summed and divided by the sum of the weights.

First find the sum of the weights.

`\blue{WEIGHT_A} + \pink{WEIGHT_B} + \green{WEIGHT_C} = TOTAL_WEIGHT`

So the weighted average of the three points, call it `\purple{M}`, is:

`\purple{M} = \dfrac{\blue{WEIGHT_AA} + \pink{WEIGHT_BB} + \green{WEIGHT_CC}} {TOTAL_WEIGHT}`

The `x` coordinate of `\purple{M}` is the weighted average of the `x` coordinates.

`\purple{M_x} = \dfrac{1}{TOTAL_WEIGHT}\bigl( \blue{WEIGHT_A \cdot A_x} + \pink{WEIGHT_B \cdot B_x} + \green{WEIGHT_C \cdot C_x}\bigr)`

`\purple{M_x} = \dfrac{1}{TOTAL_WEIGHT}\bigl( \blue{WEIGHT_A \cdot negParens(XA)} + \pink{WEIGHT_B \cdot negParens(XB)} + \green{WEIGHT_C \cdot negParens(XC)}\bigr)`

`\purple{M_x} = \dfrac{1}{TOTAL_WEIGHT}(SUM_X)`

`\purple{M_x = XM_FRACTION}`

The `y` coordinate of `\purple{M}` is the weighted average of the `y` coordinates.

`\purple{M_y} = \dfrac{1}{TOTAL_WEIGHT}\bigl( \blue{WEIGHT_A \cdot A_y} + \pink{WEIGHT_B \cdot B_y} + \green{WEIGHT_C \cdot C_y}\bigr)`

`\purple{M_y} = \dfrac{1}{TOTAL_WEIGHT}\bigl( \blue{WEIGHT_A \cdot negParens(YA)} + \pink{WEIGHT_B \cdot negParens(YB)} + \green{WEIGHT_C \cdot negParens(YC)}\bigr)`

`\purple{M_y} = \dfrac{1}{TOTAL_WEIGHT}(SUM_Y)`

`\purple{M_y = YM_FRACTION}`

`\purple{M} = (\purple{M_x}, \purple{M_y}) = \left(\purple{XM_FRACTION}, \purple{YM_FRACTION}\right)`

circle([XM, YM], 0.15, { stroke: PURPLE, fill: PURPLE, strokeWidth: 1.5 }); label([XM, YM], "M", "above", { color: PURPLE });