Bisection_Method_to_find_the_roots_of _binomial_any_polynomial_equations

Bisection Method to find the roots of  binomial any polynomial equations


clc;clear all;close all;
a=input('Enter first value:');
b=input('Enter second value:');
n=100;
if f(a)*f(b)<0
    if f(a)<0 && f(b)>0
        xl=a;
        xu=b;
    else
        xl=b;
        xu=a;
    end
for i=2:n
   xn=(xl+xu)/2;
   if f(xn)<0
       xl=xn;
   else
       xu=xn;
   end
   x(1)=0;
   x(i)=xn;
    if abs(f(x(i-1))-f(x(i)))<0.0001
        break
    end
end
fprintf('x=%f',x(i));
else
    fprintf('Wrong input')
end

function fx = f(x)
    fx = x*2.71828^x - cos(x);
    %fx =6*x^5-41*x^4+97*x^3-97*x^2+41*x-6;
    return;
end

Comments