Calculate the expectation (weighted average of random variables).
expectation([
2, 0.5; // first variable-probability pair
1, 0.4 // second variable-probability pair
])
var_prob | A list of variable-probability pairs. |
return value | The expectation of the given variable-probability pairs. |
The function takes a list of variable-probability pairs, and returns the expectation.
The var_prob argument of the function should have the form [variable, probability; variable, probability], where variable-probability pairs are separated by semicolons, and the variable is separated from the probability of its occurrence by a comma.