0% found this document useful (0 votes)
91 views4 pages

Find A Root of The Equation Using Bisection Method. Aim

1. The document describes an experiment to write a FORTRAN program that uses the bisection method to find the root of the equation x^2 + x - 2 = 0, using two starting point ranges: (0, 2) and (0.5, 2). 2. The algorithm and program coding for the bisection method is provided. 3. The program was executed successfully, finding the root of 1 for both starting point ranges, and outputting the number of iterations.

Uploaded by

Pushparaj Maria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views4 pages

Find A Root of The Equation Using Bisection Method. Aim

1. The document describes an experiment to write a FORTRAN program that uses the bisection method to find the root of the equation x^2 + x - 2 = 0, using two starting point ranges: (0, 2) and (0.5, 2). 2. The algorithm and program coding for the bisection method is provided. 3. The program was executed successfully, finding the root of 1 for both starting point ranges, and outputting the number of iterations.

Uploaded by

Pushparaj Maria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

EXPERIMENT NO 1:

FIND A ROOT OF THE EQUATION USING BISECTION METHOD.


AIM:
To generate a FORTRAN program to find a root of the equation using bisection method.
PROBLEM DESCRIPTION AND DATA
Solve the given equation
X2+X-2=0
Using two sets of starting points: (0.0, 2.0) and (0.5, 2.0)
ALGORITHM:
1. Decide initial values for x1 and x2 and stopping criterion, E.
2. Compute f1=f(x1) and f2=f(x2).
3. If f1xf2>0, x1 and x2 do not bracket any root and go to step 7;
Otherwise continue
4. Compute x0=(x1+x2)/2 and compute f0= f(x0)
5. If f1xf0 <0 then
Set x2=x0
Else
Set x1=x0
Set f1=f0
6. If absolute value of (x2-x1)/x2 is less than error E, then
Root =(x1+x2)/2
Write the value of root
Go to step 7
Else
Go to step 4
7. Stop
PROCEDURE
1. The equations and the values are specified as per the Algorithm.
2. The FORTRAN program is written in Geany and saved with the extension .95
3. The program is executed and result was saved.

PROGRAM CODING:
! program Bisection
real A,B,ROOT,EPS,F
integer S,COUNT
external BIM,F
parameter(EPS=0.000001)
write(*,*)
write(*,*)'SOLUTION BY BISECTION METHOD'
write(*,*)
write(*,*)'INPUT STARTING VALUES'
read(*,*)A,B
CALL BIM(A,B,EPS,S,ROOT,COUNT)
IF(S .EQ. 0) THEN
write(*,*)
write(*,*)'STARTING POINTS DO NOT BRACKET ANY ROOT'
write(*,*)'(CHECK WHETHER THEY BRACKET EVEN ROOTS)'
write(*,*)
ELSE
write(*,*)
write(*,*)'ROOT=',ROOT
write(*,*)'F(ROOT)=',F(ROOT)
write(*,*)
write(*,*)'ITERATIONS =',COUNT
write(*,*)
ENDIF
STOP
END
SUBROUTINE BIM(A,B,EPS,S,ROOT,COUNT)
REAL A,B,ROOT,EPS,F,X1,X2,X0,F0,F1,F2,ABS
INTEGER S,COUNT
EXTERNAL F
INTRINSIC ABS
X1=A
X2=B
F1=F(A)
F2=F(B)
IF(F1*F2 .GT. 0) THEN
S=0
RETURN
ENDIF
COUNT=1
111 X0=(X1+X2)/2.0
F0=F(X0)
IF(F0 .EQ. 0) THEN

S=1
ROOT=X0
RETURN
ENDIF
IF(F1*F0 .LT. 0)THEN
X2=X0
ELSE
X1=X0
F1=F0
ENDIF
IF(ABS((X2-X1)/X2) .LT. EPS)THEN
S=1
ROOT=(X1+X2)/2.0
RETURN
ELSE
COUNT = COUNT+1
GO TO 111
ENDIF
END
REAL FUNCTION F(X)
REAL X
F=X*X+X-2
RETURN
END
SOLUTION
First run
SOLUTION BY BISECTION METHOD
Input starting values
1.0 2.0
Root = 1.0000000
F(root) =0.0000000
ITERATIONS = 1
STOP Program terminated
Press RETURN to close window . . .
Second run
SOLUTION BY BISECTION METHOD
Input starting values
1.5 2.0
Root = 1.0000000
F(root) = -3.576279E-007
ITERATIONS = 21

STOP Program terminated


Press RETURN to close window . . .

RESULT:
Thus the FORTRAN program was generated and executed successfully to find a root of the equation using
bisection method.

You might also like