Этот код дает мне; Ошибка при использовании inline / subsref (строка 12) Недостаточно входных данных для встроенной функции.
% Метод деления пополам в MATLAB
% у нас есть коробка 5 кг m = 5, коэффициент трения k = 0,4 и неизвестная сила F = x,
% коробка неподвижен (g = 9,81)
m=5;
k=0.4;
g=9.81;
G=m*g;
N=G;
a='x-(k.*N)';
f=inline(a);
xl=input('Enter the left hand side of interval:') ;
xu=input('Enter the right hand side of interval:');
tol=input('Enter the tolerance:');
if f(xu)*f(xl)<0
else
fprintf('The guess is incorrect! Enter new guesses\n');
xl=input('Enter the left hand side of interval:\n') ;
xu=input('Enter the right hand side of interval:\n');
end
for i=2:12
xr=(xu+xl)/2;
if f(xu)*f(xr)<0
xl=xr;
else
xu=xr;
end
if f(xl)*f(xr)<0
xu=xr;
else
xl=xr;
end
xnew(1)=0;
xnew(i)=xr;
if abs((xnew(i)-xnew(i-1))/xnew(i))<tol,break,end
end
str = ['The required root of the equation is: ', num2str(xr), ''],