Error using inline/subsref (line 13) Not enough inputs to inline function.

조회 수: 5 (최근 30일)
Steven
Steven 2014년 2월 10일
댓글: Steven 2014년 2월 10일
hi guys
Please if anyone can help me with my code. i face an error that says
Error using inline/subsref (line 13)
Not enough inputs to inline function.
Error in Bisection (line 9)
ya = f(a); yb = f(b);
f = inline('x-e^(-x)')
a = 0; b = 1; % [a,b], f(a) = -, f(b) = +
imax = 10; % imax = maximum number of iterations
et = 0.0001; % et = error tolerance
ya = f(a); yb = f(b);
if sign(ya) == sign(yb),
error('Function has same sign at end points'),
end
disp(' n a b c b-c f(c) ')
for n = 1:imax
c = (a+b)/2;
yc = f(c);
iter = n; % iter = count for iteration
bound = (b-c);
out = [ iter, a, b, c, bound, yc ];
disp( out)
if abs(yc) < et,
disp('Bisection has converged');
break;
end
if sign(yc) ~= sign (ya),
b = c;
yb = yc;
else
a = c;
ya = yc;
end
if (iter >= imax),
disp('Zero not found to desired tolerance'),
end
end
Thank you

채택된 답변

Patrik Ek
Patrik Ek 2014년 2월 10일
편집: Patrik Ek 2014년 2월 10일
In matlab the naturlal number e is not defined. It is still a variable. You can try by just typing e. Instead of using you just uses exp.
a = exp(x);
in matlab is the same as e^x analytically. Also try,
f = inline('e.^x')
% or
f2 = inline('e^x')
and you will see f and f2 are functions of 2 variables and not one.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Scope Variables and Generate Names에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by