Problem with fmincon: nonlcon

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 Comments

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?
If I add another input variable (x) to the constraint, fmincon runs, but gives the same results as without the constraint.

Sign in to comment.

Answers (1)

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!

Edited:

on 15 Aug 2016

Community Treasure Hunt

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

Start Hunting!