Given two lists of numbers, determine the weighted average.
Example
[1 2 3] and [10 15 20]
should result in
33.3333 (1*10 + 2*15 + 3*20)/3
weighted mean should really be sum(x.*w)/sum(w), and not as defined in the problem.
I agree with the definition above. You need to define the sum of all the weights and not the number of weights.
As the others have said, the problem title is flat out wrong. What is required is simply not a weighted average in any standard form.
Come on Mathworks, delete this problem!
The test suits for this problem should have tests with different vector length.
There are "solutions" that just divide by 3.
I think the program title is wrong as in weighted average the denominator should contain sum of all weights
Hahaha, who wrote this problem? This is not a weighted average! Just look at the example provided: the weighted average of 1, 2 and 3 is 33.3333, hahahahaha!
this is not really the weighted average, because of 10 15 and 20 the average can't never be 33.333 here is a bug
Yes. The description is completely wrong. To start with, a weighted average should have the property that
weighted_average(x,w) == weighted_average(x,k*w)
So a simple re-scaling of the weights should not impact the result.
Good problem
kinda misleading, but i get the gist of it
good question
yay
tricky
easy
Is it possible to remove this problem or at least change the problem name so it does not say "weighted average". As others have pointed out, the definition, via example, is inaccurate.
An average, weighted or otherwise, will not be greater than the largest number in the set (which is the case here).
In case you actually want to try a weighted average problem, you can check out the one here
https://www.mathworks.com/matlabcentral/cody/problems/44156-weighted-average
very good
nice
This is NOT the weighted average. The denominator should be the sum of the weights. PLEASE FIX THIS!!!
Nice function!
This WAS the leading solution (not mine), but I removed the regexp function so you can see that it is a terrible solution.
Your weight vector should be a unit vector. W=w/norm(w) to get a true weighted average. Dividing by the max is dumb.
.
keep it up
Nice problem
easy
(^o^)v
This user (mohamed elbesealy) appears to have gamed the system, with fraudulent "likes" of this unremarkable solution submitted by 'sock-puppet' accounts. —DIV
This is a seriously flawed problem. I'm sorry, but it is. It uses an incorrect definition of a weighted average. As such, students might solve this problem, then try to use that same expression in code for some future job. A correct solution might better be:
y = x*w'/sum(w);
Agree the definition of "weighted average" is flawed. There's still a mistake in your line; it should be y = sum(x.*w)/sum(w), or y = dot(x,w)/sum(w).
That's good.
how the heck can you get smaller than?
y = x*w'/3
Sweet.
obviously misuse of poor testing...
Easy, but not the weighted average. Even assuming that the first vector contains the weighting factors (for example the sizes of different sample groups) and the second vector contains the means of the sample groups, than the divisor has to be the sum of the weighting factors instead of the number.
This is not the weighted average
Good one
odd name
I think the problem is not well formulated: in a weighted average, your weights should add up to one
FP operations and isequal(), sometimes yield some bitter results
l doubt on this definition of the problem
This is not the Weighted average. One should divide by the sum of the weighs, not by the number of them.
This is not the weighted average.
The weighted average has the sum of w in the denominator
This probably shouldn't pass...
I like the commented "y =(x*w.')/length(x)" more than the "shorter" solution.
900 Solvers
Remove the small words from a list of words.
428 Solvers
Return elements unique to either input
440 Solvers
248 Solvers
296 Solvers