Not enough input arguments.
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Anonymous Chupacabra
am 26 Apr. 2015
Kommentiert: Anonymous Chupacabra
am 27 Apr. 2015
I have a file called F.m which contains the following code:
1 % INPUT:
2 % 3D vector x
3 %
4 % OUTPUT:
5 % function value at x
6
7 function val = f(x)
8 val= x(1)^2 + x(1)*x(2)^3 - 12*x(3) + 4;
9 end
I am trying to call F.m in an algorithm in another file, but when I run the code, I get the following error:
"Error using F (line 8) Not enough input arguments."
I'm new to MATLAB, so I'm not sure what I'm doing wrong here. Any help would be greatly appreciated!
2 Kommentare
Aaron Powers
am 26 Apr. 2015
Could you include the code that calls your function f, with an example of what x is?
Akzeptierte Antwort
the cyclist
am 26 Apr. 2015
With the syntax
Algorithm1(F, gradf, [0,1,2], 0.1, 0.1, 10)
MATLAB is looking for a variable named F (and similarly with gradf). You need to tell it that F is a function, by passing the function handle:
Algorithm1(@F, @gradf, [0,1,2], 0.1, 0.1, 10)
It looks like you have similar problems deeper in your code, but I could not resolve them completely because I don't have all the functions you are using.
Weitere Antworten (1)
Jan
am 26 Apr. 2015
Bearbeitet: Jan
am 26 Apr. 2015
Inside this line:
[a, b] = Algorithm2(f, xk, dk, T);
you call the function "f" without arguments. But You want top provide the function handle of this file instead:
[a, b] = Algorithm2(@f, xk, dk, T);
Note: In modern Matlab versions you can omit the feval and call the function handle directly, which looks nicer:
while norm(gradf(xk)) >= tol1
Siehe auch
Kategorien
Mehr zu Specifying Target for Graphics Output finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!