"Not enough input arguments" Help Don't understand why?

11 views (last 30 days)
When I try and use the fzero function but keep getting this error:
Error using fzero (line 289) FZERO cannot continue because user supplied
function_handle ==> SCC failed with the error below.
Not enough input arguments.
Error in a6q7 (line 10)
q=fzero('SCC',1);
The script is as follows:
clear all
clc
z=sqrt(2)*sin(pi/4);
A =z*z;
B =z^0.5;
C =3+2*z;
x=0:10;
y=SCC(x,A,B,C);
plot(x,y)
q=fzero('SCC',1);
And the function SCC is:
function y = SCC(x,A,B,C)
y=A.*sin(x).*cos(x)+B.*cos(C.*x);
end
Thanks for any help!

Accepted Answer

Geoff Hayes
Geoff Hayes on 23 Nov 2014
Liam - according to the documentation for fzero, the input function handle is to a function that a accepts a scalar x and returns a scalar fun(x). Note that your function accepts four inputs, and so the error message, Not enough input arguments, makes sense since there fsolve will only try to provide one.
If x is your only variable into SCC, and the remaining three parameters, A, B, and C, are constant, then I would replace your line of code
q=fzero('SCC',1);
with an anonymous function that makes use of SCC as
q=fzero(@(x)SCC(x,A,B,C),1);
In the above, we are now supplying a function to fzero that will accept a single input argument only, and use the A, B, and C that have been defined previously. See anonymous functions for more details.
Try the above and see what happens!
  1 Comment
L_B
L_B on 23 Nov 2014
Thanks for the explanation really helped! I used the global function to get it to work after but thanks very much!

Sign in to comment.

More Answers (0)

Categories

Find more on Function Handles in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!