"Not enough input arguments" Help Don't understand why?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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!
0 commentaires
Réponse acceptée
Geoff Hayes
le 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!
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur MATLAB Mobile dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!