Bisection Method






Theory For BISECTION METHOD:

In mathematics, the bisection method is a root-finding algorithm which repeatedly divides an 

interval in half and then selects the subinterval in which a root exists. It is a very simple and 

robust method, but it is also rather slow.Suppose we want to solve the equation
f(x)=0,where f is a continuous function.



The bisection method starts with two points xl and xu such that f(xl) and f(xu) have opposite 

signs. The intermediate value theorem says that f must have at least one root in the interval 

[xl,xu]. The method now divides the interval in two by computing


xr = (xl+xu) / 2.

 

There are now two possibilities: either f(xl) and f(xu) have opposite 

signs, or f(xr) and f(xl) have opposite signs. The bisection algorithm is then 

applied recursively to the sub-interval where the sign change occurs.


To determine in which sub-interval the root lies:

     
     
  1. If f(xl).f(xr)<0,then we set xu=xr

  2.  
  3. If f(xl).f(xr)>0, then we set xl=xr

  4.  
  5. If f(xl).f(xr)=0, then we set xt=xr



According to the condition we have to iterate again and again till then whenever |%error| or 

|ea|=es. Then we have to find out the %error. The rule for determine %error 

is

%error or ea = (xrnew-xrold)/ 

xrnew*100%





MATLAB CODE FOR BI-SECTION METHOD OF GIVEN EUATION:

FUNCYION OF RLC:


function f_value=RLC(R)

t=0.05;

q0=5e-4;

q=5e-6;

L=5;

C=1e-4;

f_value=(exp(-R*t/(2*L)))*cos(sqrt((1/(L*C))-(R/(2*L))^2)*t)-q/q0;


MAIN PROGRAM:


clc;

clear all

tic

Rl=200;

Ru=400;

es=.0001;

i=0;

imax=25;

Rr=(Rl+Ru)/2;

fl=RLC(Rl)

while(1)

  Rrold=Rr

  Rr=(Rl+Ru)/2

  fr=RLC(Rr)

  if Rr~=0

  ea=abs((Rr-Rrold)/Rr)*100

  end

  test=fl*fr

  if test<0 ru="Rr">0

  Rl=Rr;

  fl=fr

  else

  ea=0;

  end

  if(ea=imax

  break

  end

   
 fp=fopen('iea.txt','a+');

 [err,msg]=ferror(fp,'clear');

 if err~=0

  disp('An error occurred while appending data to the file')

  disp(msg)

 end

 fprintf(fp,'%0.0f\t%8.5e\n',i,ea);

 err=fclose(fp);

 if err~=0

  disp('Could not close the file')

 end

 i=i+1;

end

disp('The value of resistance is:')

disp(Rr)

disp('The value of i is:')

disp(i)

toc









OUTPUT


fl =

-0.1631

Rrold =

 300

Rr =

 300

fr =

-0.0295

ea =

  0

test =

  0.0048

fl =

  -0.0295

Rrold =

  300

Rr =

  350


fr =

  0.0209

ea =

  14.2857

test =

 -6.1704e-004

Ru =

  350

Rrold =

  350

Rr =

  325

fr =

  -0.0032

ea =

  7.6923

test =

  9.3070e-005

fl =

  -0.0032

Rrold =

  325

Rr =

  337.5000

fr =

  0.0091

ea =

  3.7037

test =

 -2.8865e-005

Rr =

  328.1513

fr =

 -1.0717e-007

ea =

  1.1625e-004

test =

  5.2177e-014

fl =

 -1.0717e-007

 Ru =

  337.5000

Rrold =

  337.5000

Rr =

  331.2500

fr =

  0.0031

ea =

  1.8868

test =

 -9.6751e-006

Ru =

  331.2500

Rrold =

  331.2500

Rr =

  328.1250

fr =

 -2.6307e-005

ea = 0.9524

test =

  8.2989e-008

fl =

 -2.6307e-005

Rrold =

  328.1250

Rr =

  329.6875

fr =

  0.0015


fl =

 -2.0056e-006

Rrold =

  328.1494

Rr =

  328.1616

fr =

  1.0144e-005

ea =

  0.0037

test =

 -2.0345e-011

Ru =

  328.1616

Rrold =

  328.1616



Rrold =

  328.1513

Rr =

  328.1515

fr =

  8.2673e-008

ea =

  5.8124e-005

test =

 -8.8602e-015

 Rr =

  328.155

fr =

  4.0694e-006

ea =

  0.0019

test =

 -8.1616e-012

Ru =

  328.1555

Rrold =

  328.1555

Rr =

  328.1525

fr =

  1.0319e-006

ea =

  9.2998e-004

test =

 -2.0696e-012

Ru =

  328.1525

Rrold =

  328.1525

Rr =

  328.1509

fr =

 -4.8686e-004

ea =

  4.6499e-004

test =

  9.7646e-013

fl =

 -4.8686e-007

Rrold =

  328.1509

Rr =

  328.1517

fr =

  2.7252e-007

ea =

  2.3250e-004

test =

 -1.3268e-013

Ru =

  328.1517

Rrold =

  328.151



Ru =

  328.1515

The value of resistance is:

  328.1515

The value of i is:

  19

elapsed_time =

  0.1410

>>









Disadvantages:


     
  • • It is relatively slow when compared with other root finding methods we will study,
      especially when the function f (x) has several continuous derivatives about the root 

    xr.

  •  
  • • The algorithm has no check to see whether the e is too small for the computer
      arithmetic being used. [This is easily fixed by reference to the machine epsilon of the
      computer arithmetic.]

  •  
  • • When we do this method by software (matlab) then need more time of execution for this method 

    because this method takes more number of iteration (i).
  • • It cannot be used to 

    find roots when the function is tangent is the axis and does not pass through the axis.
      For example: f(x) = x2









Discussion:

In this experiment we learn the MATLAB code of bi-section method for finding root by numerical 

method. We also clarify the basic theory of bi-section method. In MATLAB code we use a user define 

function named RLC so we learn the rule to define a ‘user defined function’ in MATLAB. Finally we 

can say that we properly follow our teacher instruction that’s why we do not face any problem to 

solve our problem.

No comments:

Post a Comment