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

2 ビュー (過去 30 日間)
L_B
L_B 2014 年 11 月 23 日
コメント済み: L_B 2014 年 11 月 23 日
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 Center および File ExchangeMATLAB Mobile についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by