Sigma notation - difference of individual vector values, for loop or symsum?
2 views (last 30 days)
Show older comments
Hey everyone,
I am trying to solve a sum in sigma notation with the difference in individual vector values, squared. I'm even having difficult explaining it, so here is the sum:

Where x(i) and y(i) are the two column vectors being used, and M is the size of each vector.
Thanks!
0 Comments
Accepted Answer
John D'Errico
on 10 Nov 2017
I think you really need to read the basic tutorials for MATLAB, because this is about as basic as you can get.
If you subtract two vectors, x and y, the result will be the difference you are trying to create, right? Thus ...
x - y
Now, can you square those elements? Of course. So you might do this ...
(x-y).^2
That squares each element of the difference. Note that I carefully used a .^ operator there. That is very important. If you don't understand why, then see my first comment. READ THE MANUAL!
How do you sum a vector? Hint:
help sum
So try this ...
sum((x-y).^2)
Finally, you need to divide by the number of elements. So to wrap it all up, you might do this...
M = numel(x);
MSE = sum((x-y).^2)/M;
If you already know the length of those vectors as M, you need not do the first line there.
But really, you need to do some basic reading. You will gain in the end, by not having to ask basic questions for everything you do. There are also some great books out there to teach you MATLAB. And when you see a problem that is too complex for you to handle, break it into small pieces. Solve each part, looking towards the solution that you need, as I did above.
More Answers (0)
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!