Not enough input arguments. and too many input arguments. I'm confused about why this happened? thank you so much

1 view (last 30 days)
function y=CosxMinusx(x)
y=cos(x)-x;
end
function [ root ] = FindRoot ( a, b, N, tol, fcnHandle )
for n=1:N
root=a+(b-a)/2;
if fcnHandle(a)*fcnHandle(root)>0
a=root;
else
b=root;
end
[n a b root fcnHandle(root)]
if (b-a)/2<tol
break
end
end
>> CosxMinusx
Error using CosxMinusx (line 2)
Not enough input arguments.
>> FindRoot
Error using FindRoot (line 10)
Not enough input arguments.
>> FindRoot ( -10, 10, 100, 0.01, @CosxMinusx )
Error using FindRoot
Too many input arguments.
  3 Comments
kitty jiang
kitty jiang on 2 Oct 2014
Thank you, even though it says not enough input argument, but I could get a number for CosxMinusx(1) in the command window, however, new problem poped up. Why does it say too many input argument. Thank you=)
Image Analyst
Image Analyst on 2 Oct 2014
Hopefully those are in two different m-files because you are not allowed to mix the way you "finish" functions. You either have to omit "end"s for all functions or have "end"s for all functions but you can't mix them.

Sign in to comment.

Answers (1)

Matt J
Matt J on 2 Oct 2014
Edited: Matt J on 2 Oct 2014
Because you didn't pass any input arguments to CosxMinusx when you invoked it.
How is it supposed to evaluate
y=cos(x)-x;
when you didn't supply any input x value to the function?
  2 Comments
kitty jiang
kitty jiang on 2 Oct 2014
Thank you, even though it says not enough input argument, but I could get a number for CosxMinusx(1) in the command window, however, new problem poped up. Why does it say too many input argument. Thank you=)

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!