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

1 回表示 (過去 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 Center および File ExchangeEntering Commands についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by