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

2 次查看(过去 30 天)
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!

采纳的回答

Geoff Hayes
Geoff Hayes 2014-11-23
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 个评论
L_B
L_B 2014-11-23
Thanks for the explanation really helped! I used the global function to get it to work after but thanks very much!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Mobile 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by