how to resolve a "input argument is undefined error"?

1 view (last 30 days)
Hi, i'm going crazy with this...I post here the function and the line that gives me this error:
function f = objfun(x)
f = 13.9 + (25.055 * x(1)^-0.3017) + (11.266 * x(1)^0.4925 * x(2)^-1) + (0.45 * x(1)^0.7952 * x(2)^-1) + (0.067 * x(2)^-1* (2*x(1) + 1.2*x(2))^0.861)+ (0.045 * x(2)^-1*(2*x(1) + 1.2*x(2)))+(14.005*x(2)^-0.1899)+(2.914e-4*x(2)^0.671);
options = optimoptions(@fminunc,'Algorithm','quasi-newton');
x0 = [1e4,6e4]; % Starting guess
x = fminunc(@(x)objfun,x0,options)
??? Input argument "x" is undefined.
Error in ==> objfun at 6
I write any code of function with different f, I get an error message please help me, I need it so much... Thanks alot

Answers (1)

Orion
Orion on 18 Nov 2014
Hi,
just replace
x = fminunc(@(x)objfun,x0,options)
with
x = fminunc(@objfun,x0,options)
  2 Comments
nasrin
nasrin on 18 Nov 2014
Thank you very much for your kind attention.
I did it but still give that error.
Orion
Orion on 18 Nov 2014
silly question :
do you have well separated your code ?
meaning, the function to solve in a mfile objfun.m
function f = objfun(x)
f = 13.9 + (25.055 * x(1)^-0.3017) + (11.266 * x(1)^0.4925 * x(2)^-1) + ...
(0.45 * x(1)^0.7952 * x(2)^-1) + (0.067 * x(2)^-1* (2*x(1) + 1.2*x(2))^0.861)+...
(0.045 * x(2)^-1*(2*x(1) + 1.2*x(2)))+(14.005*x(2)^-0.1899)+(2.914e-4*x(2)^0.671);
and, in a script, or in the command window, the calling lines :
clear all
options = optimoptions(@fminunc,'Algorithm','quasi-newton');
x0 = [1e4,6e4]; % Starting guess
x = fminunc(@objfun,x0,options)

Sign in to comment.

Categories

Find more on Entering Commands 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!