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

조회 수: 2 (최근 30일)
nasrin
nasrin 2014년 11월 18일
댓글: Orion 2014년 11월 18일
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

답변 (1개)

Orion
Orion 2014년 11월 18일
Hi,
just replace
x = fminunc(@(x)objfun,x0,options)
with
x = fminunc(@objfun,x0,options)
  댓글 수: 2
nasrin
nasrin 2014년 11월 18일
Thank you very much for your kind attention.
I did it but still give that error.
Orion
Orion 2014년 11월 18일
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)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by