Info
This question is closed. Reopen it to edit or answer.
question about too many arguments error while using fmincon
1 view (last 30 days)
Show older comments
I am using an anonymous function to pass data as additional parameteres (N is 77*2 matrix contained in number.txt, Y is a 77*4 matrix contained in initial.txt)
%% Data N=number; Y=initial; f=@(x)obj(x, N, Y);
%% Minimization arg=rand(1,56); options=optimoptions('fmincon','Display','iter-detailed' ,'MaxIter',100000,'MaxFunEvals',100000);
%%Results [x,fval, exitflag, output]= fmincon(f, arg,[], [], [], [], [0.01 0.01 0.01 0.01 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], [0.99 0.99 0.99 0.99 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0],[],'fmincon', options);
I am keep getting this error: FMINCON cannot continue because user supplied objective function failed with the following error: Error using ==> @(x)obj(x,N,Y) > Too many input arguments.
What is wrong with my code??
ps. my function file contains this following code; the objective function is a bit long, (summation form), and I have to estimate x(1)...x(56).
function f=obj(x,N,Y) I=77; f=0; for i=1:I f= f-994*(log(x(1)*(x(2)^Y(i,1))*(1-x(2))^(1-Y(i,1))*(x(3)^N(i,1))*(1-x(3))^(1-N(i,2))*(x(4)^N(i,3))*(1-x(4))^N(i,4)+x(5)*(x(6)^Y(i,1))*(1-x(6))^(1-Y(i,1))*(x(7)^N(i,1))*(1-x(7))^(1-N(i,2))*(x(8)^N(i,3))*(1-x(8))^N(i,4)+x(9)*(x(10)^Y(i,1))*(1-x(10))^(1-Y(i,1))*(x(11)^N(i,1))*(1-x(11))^(1-N(i,2))*(x(12)^N(i,3))*(1-x(12))^N(i,4)+x(13)*(x(14)^Y(i,1))*(1-x(14))^(1-Y(i,1))*(x(15)^N(i,1))*(1-x(15))^(1-N(i,2))*(x(16)^N(i,3))*(1-x(16))^N(i,4)+x(17)*(x(18)^Y(i,1))*(1-x(18))^(1-Y(i,1))*(x(19)^N(i,1))*(1-x(19))^(1-N(i,2))*(x(20)^N(i,3))*(1-x(20))^N(i,4)+x(21)*(x(22)^Y(i,1))*(1-x(22))^(1-Y(i,1))*(x(23)^N(i,1))*(1-x(23))^(1-N(i,2))*(x(24)^N(i,3))*(1-x(24))^N(i,4)+x(25)*(x(26)^Y(i,1))*(1-x(26))^(1-Y(i,1))*(x(27)^N(i,1))*(1-x(27))^(1-N(i,2))*(x(28)^N(i,3))*(1-x(28))^N(i,4)+x(29)*(x(30)^Y(i,1))*(1-x(30))^(1-Y(i,1))*(x(31)^N(i,1))*(1-x(31))^(1-N(i,2))*(x(32)^N(i,3))*(1-x(32))^N(i,4)+x(33)*(x(34)^Y(i,1))*(1-x(34))^(1-Y(i,1))*(x(35)^N(i,1))*(1-x(35))^(1-N(i,2))*(x(36)^N(i,3))*(1-x(36))^N(i,4)+x(37)*(x(38)^Y(i,1))*(1-x(38))^(1-Y(i,1))*(x(39)^N(i,1))*(1-x(39))^(1-N(i,2))*(x(40)^N(i,3))*(1-x(40))^N(i,4)+x(41)*(x(42)^Y(i,1))*(1-x(42))^(1-Y(i,1))*(x(43)^N(i,1))*(1-x(43))^(1-N(i,2))*(x(44)^N(i,3))*(1-x(44))^N(i,4)+x(45)*(x(46)^Y(i,1))*(1-x(46))^(1-Y(i,1))*(x(47)^N(i,1))*(1-x(47))^(1-N(i,2))*(x(48)^N(i,3))*(1-x(48))^N(i,4)+x(49)*(x(50)^Y(i,1))*(1-x(50))^(1-Y(i,1))*(x(51)^N(i,1))*(1-x(51))^(1-N(i,2))*(x(52)^N(i,3))*(1-x(52))^N(i,4)+x(53)*(x(54)^Y(i,1))*(1-x(54))^(1-Y(i,1))*(x(55)^N(i,1))*(1-x(55))^(1-N(i,2))*(x(56)^N(i,3))*(1-x(56))^N(i,4)))*Y(i,2);
end end
1 Comment
Alan Weiss
on 6 Jun 2014
Please format your code so we can read it. Use the {}Code button.
Alan Weiss
MATLAB mathematical toolbox documentation
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!