Input error?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Here is my code, my function code, what I type into the command window and what the error says. Please help!
My code:
function Xout=SecantRoot(Fun,Xa,Xb,Err,imax)
%This function will find the root of a function (Fun(X)) using the secant method.
%Fun is a function to be determined by the user
%Xa and Xb are your two initial guesses needed for secant method
%Err is the maximum interval of error
%imax is the maximum number of iterations
for i = 1:imax
Xi=Xb-((Fun(Xb)*(Xa-Xb))/(Fun(Xa)-Fun(Xb)));
if abs((Xi-Xb)/Xb)<Err
Xout=Xi;
break
end
Xa=Xb;
Xb=Xi;
end
if i ==imax
fprintf('Solution not found.');
Xout=('No answer');
end
My Function code:
function y=Fun(x)
y=7*(x.^3) + exp^.2*x -6*x -10;
What I put into command window
>> SecantRoot (@Fun,2.5,.7,.1,7)
What matlab tells me:
>> SecantRoot (@Fun,2.5,.7,.1,7)
Error using exp
Not enough input arguments.
Error in Fun (line 2)
y=7*(x.^3) + exp^.2*x -6*x -10;
Error in SecantRoot (line 4)
Xi=Xb-((Fun(Xb)*(Xa-Xb))/(Fun(Xa)-Fun(Xb)));
How do I fix these issues?
0 Commenti
Risposte (1)
Walter Roberson
il 12 Apr 2012
Change your
exp^.2*x
to
exp(2*x)
or
exp(2)*x
depending on your intention.
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!