Insert a function from function file into FMINUNC command
1 view (last 30 days)
Show older comments
Hello, I have the following function file to generate the required function in unknown variable 'c'.
Then i have the following command which takes this function (last line in above command).
c = fminunc(@(c) chi(c, K0_com, M_com_vec, lambda, Steps, Steps, ns1, ns2), cint, options);
When I run the command I am getting the following message.
Error using chi
Too many output arguments.
Error in @(c)chi(c,K0_com,M_com_vec,lambda,Steps,Steps,ns1,ns2)
Error in fminunc (line 254)
f = feval(funfcn{3},x,varargin{:});
Error in In (line 83)
c = fminunc(@(c) chi(c, K0_com, M_com_vec, lambda, Steps, Steps, ns1, ns2),
cint);
Caused by:
Failure in initial user-supplied objective function evaluation. FMINUNC
cannot continue.
Can you please let me know how to fix this? Thanks
0 Comments
Answers (1)
John D'Errico
on 4 Jan 2015
chi has no return argument. How do you expect fminunc to operate? Should it be able to guess which variable to optimize over?
doc function
I think that perhaps you have some romantic idea that MATLAB will see this line of chi
((0.5*c'*(G + lambda*eye(ns1*ns2))*c) - (c'*M_com_vec));
and somehow magically understand that this is the return argument. You assign the result to nothing, then terminate the line with a semi-colon. It just gets dumped into the bit bucket. MATLAB cannot read your mind. It does exactly what you tell it to do.
Of course, from your comments, it is also not obvious if you have put the call to fminunc INSIDE the function chi itself. This is another problem that people often seem to make.
4 Comments
John D'Errico
on 5 Jan 2015
The tools in the optimization toolbox, thus functions of the class of fminunc, fmincon, etc., require a continuous objective. That does not appear to be true for your function.
You might try a tool like a genetic optimizer, or a particle search of some sort, any of which will be less sensitive to such singularities.
See Also
Categories
Find more on Direct Search in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!