Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Not enough input arguments
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (2)
Walter Roberson
am 24 Jan. 2020
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.)
0 Kommentare
KSSV
am 24 Jan. 2020
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)
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!