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

Answers (1)

Assuming the variables are each vectors of size N:
sum((theta_bo - theta_mbo).^2) + sum((theta_to - theta_mto).^2)

3 Comments

then how can i insert the range.? for example the range of K is from 1 to 700? aren't it important to include?
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);
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.

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Tags

Asked:

on 9 Apr 2015

Community Treasure Hunt

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

Start Hunting!