Bisection Method

by

 

Numerical Method to find the roots of linear equations.

Bisection.m
clear
clc
disp('Bisection Method Program')
disp('By: Tariq M. Yousef')
disp('Faculty of Engineering Technology')
disp('Date: 3/5/2013')
disp(' ')
disp('Press any key to continue please...')
pause
clc


syms x

fun=input('Enter the function f(x)=');
x1=input('Enter the initial value of the period a=');
y=input('Enter the final value of the period b=');
d=input('Enter decimal places =');


i=0;
while(1)
        
    error=(y-x1)/2;   
      if(error<0.5*10^-d)
        break
      end
    
    c=(x1+y)/2;
    value_at_c=subs(fun,x,c);
    value_at_x1=subs(fun,x,x1);
    check=value_at_c*value_at_x1;
    if(check<0)
        y=c;
    end
    
    if(check>0)
        x1=c;
    end
    
   sprintf('i= %f',i)
   sprintf('[a,b]= [%f,%f]',x1,y)
   sprintf('c= [%f]',c)
   
   i=i+1;

    
end

    error=(y-x1)/2;
    disp('-------------Solution---------------');
    sprintf('The final values of period limits [a,b]= [%f,%f]',x1,y)
    sprintf('Error=%f',error)
    sprintf('Answer=%f',c)
    

Contact us