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 Center および File ExchangeScope 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