Info

此问题已关闭。 请重新打开它进行编辑或回答。

Not enough input arguments

1 次查看(过去 30 天)
Anonymous
Anonymous 2020-1-24
关闭: MATLAB Answer Bot 2021-8-20
Could somebody please explain what this error is and how to fix it.
(Error in goldenmax721 (line 5) xmax_old=max(f(xl),f(xu));
Code:
function[xmax,fval]=goldenmax(f,ea,xl,xu)
phi=0.5*(1+sqrt(5));
tol=1;
iter=0;
xmax_old=max(f(xl),f(xu));
while tol>ea
iter=iter+1;
d=(phi-1)*(xu-xl);
x1=xl+d;
x2=xu-d;
if f(x1)>f(x2)
xl=x2;
x2=x1;
d=(phi-1)*(xu-xl);
x1=xl+d;
xmax=x1;
fval=f(x1);
else
xu=x1;
x1=x2;
d=(phi-1)*(xu-xl);
x2=xu-d;
xmax=x2;
fval=f(x2);
end
tol=abs((xmax-xmax_old))*100;
xmax_old=xmax;
end
end

回答(2 个)

Walter Roberson
Walter Roberson 2020-1-24
You cannot run that code by simply pressing the green Run button to run it. You must go down to the command line and invoke the function passing in four arguments, the first of which is a function handle and the other three of which are numeric. (Or you could write a bit of code that made the call instead of doing it at the command line.)

KSSV
KSSV 2020-1-24
YOu have to define/ give values of f,ea,xl,xu to the function. I think you are running the function directly.
f = your value ; % enter your value
ea = your value ;
xl = your value ;
xu = yourvalue ;
[xmax,fval]=goldenmax(f,ea,xl,xu)

Community Treasure Hunt

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

Start Hunting!

Translated by