MATLAB: How can calculate this formula with matlab

I have the vectors w(1,n) and σ(n,1). How can calculate this formula?

Best Answer

You can pull the w_i and sigma_i outside of the sum_j, because the don't depend on j. And you can compute the sum_j nicely as a matrix multiplication of row vector w and column vector sigma.
w = rand(1,10); % sample values for w and s
s = rand(10, 1);
N = numel(w);
y = 0;
for i=1:N-1
y = y + s(i)*w(i)* w(i+1:end)*s(i+1:end);
end
y = 2*y;
Related Question