Failure in initial objective function evaluation. FMINUNC cannot continue.
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
I tried to evaluate this function but I am getting this error Failure in initial objective function evaluation.
FMINUNC cannot continue.
Please what is the best way to evaluate this function
f = x(2)^2*x(9)^2 + x(2)^2*x(9) + x(2)^3*x(9) - x(3)*x(5)*x(9)^2 + x(6)*x(8)*x(9)^2 + x(6)*x(8)*x(9)^3 + x(2)*x(6)*x(8)*x(9)^2;
Accepted Answer
Star Strider
on 19 Nov 2019
Unless it is already in a function file, it needs to be an anonymous function:
f = @(x) x(2)^2*x(9)^2 + x(2)^2*x(9) + x(2)^3*x(9) - x(3)*x(5)*x(9)^2 + x(6)*x(8)*x(9)^2 + x(6)*x(8)*x(9)^3 + x(2)*x(6)*x(8)*x(9)^2;
If it is in a function file (and you have passed the function handle to fminunc correctly), the initial parameter estimates could be the problem. Please post those.
9 Comments
Kelechi Emerole
on 19 Nov 2019
These are the code, am I doing anyhthing wrong? Sorry I am new to matlab
fun =@(x)x(2)^2*x(9)^2 + x(2)^2*x(9) + x(2)^3*x(9) - x(3)*x(5)*x(9)^2 + x(6)*x(8)*x(9)^2 + x(6)*x(8)*x(9)^3 + x(2)*x(6)*x(8)*x(9)^2;
x0 = [-.5, 0];
options = optimoptions('fminunc','Algorithm','quasi-newton');
options.Display = 'iter';
[x, fval, exitflag, output] = fminunc(fun,x0,options);
Star Strider
on 19 Nov 2019
You have 9 parameters, so ‘x0’ must have 9 elements.
For example —
fun =@(x)x(2)^2*x(9)^2 + x(2)^2*x(9) + x(2)^3*x(9) - x(3)*x(5)*x(9)^2 + x(6)*x(8)*x(9)^2 + x(6)*x(8)*x(9)^3 + x(2)*x(6)*x(8)*x(9)^2;
x0 = rand(9,1);
options = optimoptions('fminunc','Algorithm','quasi-newton');
options.Display = 'iter';
[x, fval, exitflag, output] = fminunc(fun,x0,options);
This runs without error, however I doubt the result is what you want.
Kelechi Emerole
on 20 Nov 2019
Thanks very much Sir, it runs but ends up with this problem. How do I solve it? Thanks once agian.
fminunc stopped because the objective function value is less than
or equal to the default value of the objective function limit.
Star Strider
on 20 Nov 2019
That is not an error or a problem. It is simply a message from fminunc that it stopped, and the reason.
Meanwhile, consider changing your fminunc call to:
[x, fval, exitflag, output] = fminunc(@(x)norm(fun(x)), x0, options);
That may be the result you want.
Kelechi Emerole
on 20 Nov 2019
Wow thank you Sir for your quick reply, it produced this line, is that a problem?
fminunc stopped because it cannot decrease the objective function
along the current search direction.
Kelechi Emerole
on 20 Nov 2019
Mr Star strider, thank you very much. I have gotten the result I want.
Star Strider
on 20 Nov 2019
As always, my pleasure!
It is not a probllem. Again, fminunc is simply telling you that it stopped, and the reason.
Mohammed Ouallal
on 15 Aug 2020
Edited: Bruno Luong
on 15 Aug 2020
It seems that you resolve the problem but did not show how! please be kind and share the complete solution.
Thank you for the understanding!
Star Strider
on 15 Aug 2020
Yes, I did!
‘Unless it is already in a function file, it needs to be an anonymous function’
More Answers (0)
Categories
Find more on Solver Outputs and Iterative Display in Help Center and File Exchange
Tags
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)