How to correct error in Nonlinear constraint in fmincon
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I used fmincon too calculate six(6) vartialbes in a function (mandmf, to long to be posted here). The code is below
for q= -1:1:1, for k.....
x0=[k;l;m;n;p;q];
% calling the function
[x,fvals]=fmincon(@(x) mandmf(x,mu,gamma)...
,x0, [], [], [], [], -1*ones(6,1), ones(6,1),@(x)constred(x));
end....
where constred(x) is a nonlinear constraint given as
function [c,ceq] = constred(x)
c = [];
ceq = x(1)*x(1)' + x(2)*x(2)' + x(3)*x(3)'+ x(4)*x(4)' + x(5)*x(5)' +x(6)*x(6)' - 1;
end
The code works and gives the desired results.
Now I increased the coefficients to twelve(12) by changing x(1)'=x(7), ...,x(6)'=x(12) and then wrote the new constraint as
function [d,g] = constman39(x)
d = [];
g = x(1)*x(7) + x(2)*x(8) + x(3)*x(9)+ x(4)*x(10) + x(5)*x(11) +x(6)*x(12) - 1;
end
I have included the changes in the variables in a new function mandmfmod. The new code is
for k =....
x0=[k;l;m;n;p;q;k1;k2;k3;k4;k5;k6];
% calling the function
[x,fvals]=fmincon(@(x) mandmfmod(x,mu,gamma)...
,x0, [], [], [], [], -1*ones(12,1), ones(12,1), ...
@(x)constman39(x));
When I tried to run it MATLAB give the following error
Error using svd
Input to SVD must not contain NaN or Inf.
Error in pinv (line 29)
[U,S,V] = svd(A,0);
Error in qpsub (line 463)
projSD = pinv(projH)*(-Zgf);
Error in nlconst (line 619)
[SD,lambda,exitflagqp,outputqp,howqp,ACTIND] ...
Error in fmincon (line 794)
[X,FVAL,LAMBDA,EXITFLAG,OUTPUT,GRAD,HESSIAN]=...
Error in mand5 (line 59)
[x,fvals]=fmincon(@(x) mandmfmod(x,mu,gamma)...
I didn't get any error when working with six variables.
What should I do? I have not been able to figure out what the problem is. Help please.
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Nonlinear Optimization dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!