% The program uses the bisection method to estimate a root of the equation % f(x)=0. The input parameters are x_1 and x_2 (which give an interval % that contains a root) and the tolerance = epsilon with which the root will be % estimated. function [x] = Bisection(x_1,x_2,epsilon) % With the next command ask for high accuracy (more decimals) format long % We give an initial value so that the while loop will get started x = x_1 ; % n will count the number of repetitions needed to achieve the desired % accuracy. n=0; % The method while (abs(fcn(x)) > epsilon) x = (x_1 + x_2)/2 % Next estimate of the root. n=n+1 % Number of repetitions. test = fcn(x_1) * fcn(x); % Perform product test. if test < 0 x_2 = x; % root is between x_1 and x. else % i.e. test > 0 x_1 = x; % root is between x and x_2. end end