MATLAB: How to create a handle-function with a double summation on 201 variables (40401 terms)

fminconfunctionsMATLAB and Simulink Student Suitesumsymbolic

Hello everyone!
I have to use Lagrangian multipliers with two linear constrains to minimize the function
where W represent all 201 variables that I want to determine, C are correlation coefficients between two vectors and sigma are standard deviations of the vectors (obviously I have 201 vectors).
To use Lagrangian multipliers, I use the function fmincon.
The problem is that I don't know how create the function .
I think the input function should be a handle-function (and fmincon works with a handle-function), but I don't know how create a so complicated handle funcion.
I used
W = sym('W',[1 201]);
to create my symbolic variables.
Then, I tried to use several methods to create , like
FUN=@(W) symsum(symsum(W('i')*W('j')*S('i','j')*std(L(:,'i'))*std(L(:,'j')), j, 1, 201), i, 1, 201);
When I try to minimize this FUN with fmincon, this error appears:
"Undefined function 'symsum' for input arguments of type 'double'."
Another very complex attempt consists of creating an ausiliar array in which write every term of summations,
FUNau =cell(201*201, 1);
nit=0;
for i=1:201
for j=1:201
nit=nit+1;
FUNau(nit,1) = (W(i)*W(j)*S(i,j)*std(L(:,i))*std(L(:,j)));
end
end
% high computation time
then I tried several methods to compute the right FUN, like
FUN =@(W) sum(FUNau);
or
FUN =@(W) symsum(FUNau);
but every attemp has failed when I used fmincon.
How can I create the function so that fmincon works?
Thanks.

Best Answer

FUN = @(W) (W.*sigma).'*C*(W.*sigma)