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.
kinda misleading, but i get the gist of it
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
why leading size is always 7? and how :(
On a weighted average we should divide the weighted values by the sum of the weights and not by the number of terms. https://en.wikipedia.org/wiki/Weighted_arithmetic_mean
@Mehmed Saad: some of the many cheating solutions have been deleted.
This problem definitely needs to be fixed to use the correct weighted average formula.
This is NOT the weighted average. The denominator should be the sum of the weights. PLEASE FIX THIS!!!
Daniel is correct.
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
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).
how the heck can you get smaller than?
y = x*w'/3
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 beautiful! Smart move!
This is not the weighted average
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
I submitted a correct code with correct outputs , yet it keeps returning that its wrong
i donno how to report that
input - Request user input, thus values for x and w were overwritten.
This probably shouldn't pass...
I like the commented "y =(x*w.')/length(x)" more than the "shorter" solution.
Which values occur exactly three times?
Back to basics 15 - Benchmark
Wind Chill Computation
Produce a cosine wave
Find the treasures in MATLAB Central and discover how the community can help you!
Select a Web
Choose a web site to get translated content where available and see local events and
offers. Based on
your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country
sites are not optimized for visits from your location.
Contact your local office