Insert a function from function file into FMINUNC command

1 visualizzazione (ultimi 30 giorni)
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

Risposte (1)

John D'Errico
John D'Errico il 4 Gen 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 Commenti
Karthik
Karthik il 5 Gen 2015
Modificato: Karthik il 5 Gen 2015
I want to solve for 'c' by minimizing the chi function. What I understand from your reply is that I cannot run fminunc on the chi function because it has heaviside in it right? Is there any other command that I could use to minimize the chi function. I also know the first and second derivatives of the chi function. Thank you.
John D'Errico
John D'Errico il 5 Gen 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.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by