Dividing a Number with a Vector Results in a new Vector with wrong mean
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ferhat Buke
el 30 de Mayo de 2019
Comentada: Luna
el 30 de Mayo de 2019
Hey All,
I have an interesting problem;
I have a vector (VectorInitial). I want to calculate another vector (VectorTarget) with the same size such that the elements in VectorTarget(i)=60/VectorInitial(i).
I have tried several ways;
VectorTarget = rdivide(60,VecInitial)
VectorTarget = 60./VectorInitial
Writing a for loop to go through all the elements and divide 60 by each element 1 by 1 and write it into a new vector.
All of these methods create the same VectorTarget as expectedly. However there is a huge problem.
In my case the mean(VectorInitial) = 25.0192
60/25.0192 = 2.3982
One would expect mean(VectorTarget) to be 2.3982
However mean(VectorTarget) = 2.4863
I am really baffled as to why this is happening. Any suggestions would be highly appreciated.
0 comentarios
Respuesta aceptada
Luna
el 30 de Mayo de 2019
Editada: Luna
el 30 de Mayo de 2019
Because they are not equal mathematically.
Suppose that:
VectorInit = [a,b,c]
meanVectorInit = (a+b+c)/3
VectorTarget = [60/a,60/b,60/c]
meanVectorTarget = (60/a+60/b+60/c)/3 = 20/a + 20/b + 20/c
Then check;
60/meanVectorInit = 60/( (a+b+c)/3 ) = 180/(a+b+c)
So;
20/a + 20/b + 20/c ~= 180/(a+b+c) -> they are not always equal. Depends on what a,b,c is.
meanVectorTarget ~= 60/meanVectorInit
I recommend you to do the symbolic math operations on a paper with your hand, you will see they are not equal.
2 comentarios
Más respuestas (0)
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!