Вы находитесь на странице: 1из 1

%Enter the equation n = input('Enter the degree of the equation : '); % Set the tolerance value tol = input('Enter

the tolerance'); %Enter lower and upper limits x1 = input('Enter the lower limit x1'); x2 = input('Enter the upper limit x2'); %Repeat calculations until interval is less than 2*tolerance while x2-x1 > 2*tol x3 = (x1+x2)/2; % Evaluate function at lower limit and midpoint fx1 = fx(x1); fx3 = fx(x3); % Multiply values: if product > 0, signs are same. Keep upper limit % If products < 0, signs are opposite. Keep lower limit prod = fl*fm; if prod >0 low = mid; else high = mid; end end %Root = midpoint of interval. Print out root root = (high+low)/2; fprintf('\n\n Root found: %.4f\n\n',root)