how to write a nonliear constraint with a convriance matrix in FMINCON

Dear All,
I've got to calculate a optimization problem with FMINCON. And this is my question. I have to use a covariance matrix as a part of my nonlinear constraint such as
(x1,x2,....xn)*cov*(x1,x2,...xn)'< V.
xi is the n unknoz varibles to optimized and cov is the convariance matrix, V is just a known real number. Since my n is quite large, like 30..so i dont know how to write this nonlinear constraint in Matlab as a c for
FMINCON(f,A,b,Aeq,beq,c,ceq)
Because all the doucments i found told me to right a equation manually, thats means i have to write something like
C=[x(1)^2*cov(1,1)+x(2)^2*cov(2,2)+...+2*x(1)*x(2)*cov(1,2)+2*x(1)*x(3)*cov(1,3)....]
this is nearly impossible..... so is there any ways to write this constraint with the covariance matix?
Thank you for any help.

 Accepted Answer

If cov is a known matrix, and x is a column vector (set x0 as a column vector), then I think that
c = x'*cov*x - V;
should work just fine. Don't forget to set ceq = [].
If you derive cov from x somehow, just put that calculation first.
Alan Weiss
MATLAB mathematical toolbox documentation

7 Comments

Hi thanks for the help, cov is indeed a known matrix, but i have tried by using directly
c = x'*cov*x - V;
in the nonlinear constraint..but it doesent work...
hi Matt J, thx for the help. This is my code, since i got 27 control varialbes
function f=objfun(x)
f=x(1);
end
function [c,ceq]=constraint(x,COVA)
c=x(1)+x'*COVA*x-COVA(2,2);
ceq=[];
end
and this is my optimization code:
A=[R(1,1),-R'];
b=-R(1,1);
Aeq=[0,ones(1,26)];
beq=1;
x0=ones(27,1)*0.001;
x=fmincon('objfun',x0,A,b,Aeq,beq,lb,[],'constraint');
where R is a 26*1 matrix, COVA is a 27*27 matrix in which the first row and first colone are just zeros and the others are a covariance matrix.
But it doesent work; could you please give me some advices? thx alot
You should be calling something like as follows
x=fmincon(@objfun,x0,A,b,Aeq,beq,lb,[],@(x)constraint(x,COVA));
Note that objfun and constraint must be specified as function handles and not as strings. You also have to define/construct COVA somewhere in the workspace which calls FMINCON.
Thx a lot Matt. It seems it works. Thx so much
Good news. But then please Accept-click Alan's answer,
sorry forgot to accept. thx Alan and Matt.

Sign in to comment.

More Answers (0)

Asked:

on 16 Dec 2013

Commented:

on 17 Dec 2013

Community Treasure Hunt

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

Start Hunting!