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
0 个评论
采纳的回答
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!