fmincon runs fine without the non-linear constraint given by the function:
function [c,ceq] = DiagCAW11_constraints(theta,RC,r,bsum)
A=diag(theta(11:14),0);
B=diag(theta(15:18),0);
ceq = [];
c = diag(A.^2 + B.^2 - 1);
end
However when running with the constraint, I get the error
"Error using DiagCAW11_constraints
Too many input arguments."
Here is the entire minimization problem:
fmincon('DiagCAW11_likelihood',theta0,[],[],[],[],[],lb,ub,'DiagCAW11_constraints',options,RC,r,bsum);

2 commentaires

Thorbjørn Kristiansen
Thorbjørn Kristiansen le 13 Août 2016
As I understand it, the constraint is supposed to have the same amount of input arguments as the function being minimized. Is this a misconception?
Thorbjørn Kristiansen
Thorbjørn Kristiansen le 14 Août 2016
If I add another input variable (x) to the constraint, fmincon runs, but gives the same results as without the constraint.

Connectez-vous pour commenter.

Réponses (1)

Are Mjaavatten
Are Mjaavatten le 14 Août 2016

0 votes

To transfer the extra inputs to DiagCAW11_constraints you should use an anonymous function:
Make sure that RC, r, bsum are defined. Then define an anonymous function nonlcon as:
nonlcon = @(theta) DiagCAW11_constraints(theta,RC,r,bsum);
You may transfer parameters to DiagCAW11_likelihood in the same manner:
likelihood = @(theta) DiagCAW11_likelihood(theta,par1,par2)
Now you may call fmincon:
theta = fmincon(likelihood,theta0,[],[],[],[],lb,ub,nonlcon,options);
Good luck!

Community Treasure Hunt

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

Start Hunting!

Translated by