Input error?

조회 수: 1 (최근 30일)
rachel
rachel 2012년 4월 12일
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?

답변 (1개)

Walter Roberson
Walter Roberson 2012년 4월 12일
Change your
exp^.2*x
to
exp(2*x)
or
exp(2)*x
depending on your intention.

카테고리

Help CenterFile Exchange에서 Just for fun에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by