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

4 次查看(过去 30 天)
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