Info

This question is closed. Reopen it to edit or answer.

inside function calling problem

2 views (last 30 days)
xueqi
xueqi on 16 Jul 2012
Closed: MATLAB Answer Bot on 20 Aug 2021
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 Comments
C.J. Harris
C.J. Harris on 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.
xueqi
xueqi on 16 Jul 2012
Hi. Thanks for your reply. In short my problem is trying to maximize a main function, in which other sub functions are called. So the variables of main function come from the variables in sub functions. But Matlab seems can't handle this and keeps say , for example, " Input argument "lb2" is undefined." Here lb2 is a variable from sub function. At the end of day I want to maximize the main function through these variables.Could you tell me what is the general stucture should be?

Answers (0)

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!