Sigma notation - difference of individual vector values, for loop or symsum?

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!

 採用された回答

John D'Errico
John D'Errico 2017 年 11 月 10 日
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.

1 件のコメント

John
John 2017 年 11 月 10 日
Oh. Thanks. I was totally overthinking it. Appreciate the help even if I did waste your time...

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

質問済み:

2017 年 11 月 10 日

コメント済み:

2017 年 11 月 10 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by