Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
inside function calling problem
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi dear all, could you give me some advice about my program? Here is my code
mu =@(r,lb1,lb2,lb3) ambportfchc(r,lb1,lb2,lb3) %mu is a 35*2 matrix
SIGMA =@(s1,s12,s2) [s1 s12; s12 s2]
p =@(mu, SIGMA) log( mvnpdf(hatpc,mu,SIGMA)); %p is a 35*1 function vector
sumllh=0;
for i=1:size(mu,1)
sumllh=@(r,lb1,lb2,lb3,s1,s12,s2) sumllh+p(i,:)
end
A=[0 1 1 1 0 0 0;0 -1 0 0 0 0 0;0 0 -1 0 0 0 0;0 0 0 -1 0 0 0]
b=[1;0;0;0]
x= fmincon(sumllh,[0,0,0,0,0,0,0],A,b)
here ambportfchc is a function I define in a separate function file which is quite big. At the end of the day I want to maximize sumllh through the parameters r,lb1,lb2,lb3,s1,s12,s2 using fmincon. I feel that there maybe something wrong when I am defining and calling function. And Matlab gives me some error information which are
could also try the interior-point or sqp algorithms: set the Algorithm option to 'interior-point' or 'sqp' and
rerun. For more help, see Choosing the Algorithm in the documentation.
> In fmincon at 472
In try1 at 18
??? Undefined function or method 'plus' for input arguments of type 'function_handle'.
Error in ==> @(r,lb1,lb2,lb3,s1,s12,s2)sumllh+p(i,:)
Error in ==> fmincon at 574
initVals.f = feval(funfcn{3},X,varargin{:});
Error in ==> try1 at 18
x= fmincon(sumllh,[0,0,0,0,0,0,0],A,b)
Caused by:
Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.
2 Kommentare
C.J. Harris
am 16 Jul. 2012
I'm not sure what you are doing here, but I don't think it's what you are intending to do. Please read the documentation on functions and function handles. The error you are getting stems from the fact that the 'fmincon' function is trying to add two function handles.
Antworten (0)
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!