From: Markus Staudinger on
Dear all,

I have a problem with the constraint function in fmincon. The error message is:

??? Error using ==> fmincon at 612
FMINCON cannot continue because user supplied nonlinear constraint function
failed with the following error:
Error using ==> myconstr
Too many input arguments.

Error in ==> Optim at 38
[optparams(s,1:4,3),lik(s,3)] = fmincon(@lnLIL,cfg.iniparamsIL,[],[],[],[],...

Optim determines the model to fit and calls fmincon:
case 'IL'
[optparams(s,1:4,3),lik(s,3)] = fmincon(@lnLIL,cfg.iniparamsIL,[],[],[],[],...
cfg.lboundIL,cfg.uboundIL,@myconstr,options,cfg,choice(:,s),rew(:,s));

[L(s,3),model(s,3)] = lnLIL(optparams(s,:,3),cfg,choice(:,s),rew(:,s));
...
myconstr reads:
function [c,ceq,gradc,gradceq] = myconstr(x)

c(1) = x(1) - 1/x(4);
c(2) = x(2) - 1/x(4);
ceq = [];

if nargout > 2
gradc = [1, 1; 1/x(4)^2, 1/x(4)^2];
gradceq = [];
end
end

Even when I change [optparams(s,1:4,3),lik(s,3)] to [x,lik(s,3)] in Optim it doesn't work.
Has anybody got any idea?

Many thanks
Markus