hi. i got a problem to convert this equation into Matlab code perhaps can help me. it is about summation. thanks
Show older comments

this equation about summation
Answers (1)
James Tursa
on 9 Apr 2015
Assuming the variables are each vectors of size N:
sum((theta_bo - theta_mbo).^2) + sum((theta_to - theta_mto).^2)
3 Comments
mohamad rusydi
on 9 Apr 2015
James Tursa
on 9 Apr 2015
Edited: James Tursa
on 9 Apr 2015
The "sum" function does this looping internally ... you don't have to manually code up a loop. E.g., the following two methods accomplish the same thing:
v = a vector of size 1 x N
% Method 1: Explicit loop
s = 0;
for k=1:N
s = s + v(k);
end
% Method 2: Using the sum function
s = sum(v);
Mohammad Abouali
on 9 Apr 2015
unless if N differs from numel(theta_bo), for some reasons. if you are summing all elements in theta_bo then you don't need to worry about the range of K. But if for some reason you are suming a portion of those vectors then just pass (1:N) to all of them. Most possibly though what James wrote here would work for you though.
Categories
Find more on Mathematics 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!