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

3 vues (au cours des 30 derniers jours)
Steven
Steven le 10 Fév 2014
Commenté : Steven le 10 Fév 2014
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

Réponse acceptée

Patrik Ek
Patrik Ek le 10 Fév 2014
Modifié(e) : Patrik Ek le 10 Fév 2014
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.

Plus de réponses (0)

Catégories

En savoir plus sur Scope Variables and Generate Names dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by