The bisection method is useful when you want to find a root of a continuous function in a specified range. It works on the
Apply the bisection method to f(x) = sin(x) starting with 1, 99, ε step = ε abs = 0.00001, and comment. After 24 iterations, we have the interval 8, 2 and sin(8) ≈ 0. Write a Fortran program to find first derivation of the.: Orthogonal polynomials generator. The most basic problem in Numerical Analysis (methods) is the root-finding problem. The Bisection Method is a simple root finding method, easy to implement and very robust. The disadvantages of this method.
which says that if a continuous function changes sign over an interval, there is at least one root of the function in that interval. Here is how to find a root using this method.- Assign end points for the 'root hunt'. Let's call them 'a' ad 'b'. The end points should be such that the value of the function, f at both points should be opposite in sign.i.e. f(a), f(b)<0. This is because we will search for a point within this limit that has zero value for the function or a point where the function crosses the x-axis of the Cartesian Plane. If the end points have the same sign, we can use the GO TO statement to read new values for a and b.
- We choose the mid-point of this interval. Now this mid-point, let's call it 'c', will have some value for the function, namely f(c). Evidently, f(c) will have a positive or negative sign unless it has the value zero in which case it is the root.
- If f(c) has a sign opposite to f(a) or f(b), we will continue searching the root between f(c) and that particular endpoint. Obviously, it cannot have a sign opposite to both as per our choice of a and b. Depending on which end has the opposite sign, either a will take the value of c or c will take the value of b.
- We continue this till we get the desired degree of accuracy in the value of the root (upto a certain number of decimal points).
!To find the root of a function using bisection method
program rootf
implicit none
real a,b,c,f,root
10 write (*,*) 'Give the range within which you wish to find a single root?'
read (*,*) a,b
write(*,*) 'The end points are'
write (*,*) 'a= ',a,'b= ',b
if (f(a)*f(b)>0) then !To make sure the end points have opposite signs
write (*,*) 'The function has same sign at both end points. Please, try again.'
go to 10
else
write (*,*) 'Finding roots in the range ',a,' to ',b
!To start computation
do
if (abs(f(a))<0.00001) then
root=a
exit
end if
if (abs(f(b))<0.00001) then
root=b
exit
end if
c=(a+b)/2.0 !To check the value of the function at the mid-point. This will anyway be checked again when the value of c is replaced the next time the loop runs
if (abs(f(c))<0.00001) then
root=c
exit
end if
if (f(a)*f(c)<0) then !To move end points closer to the root
b=c
else
a=c
end if
if (abs(b-a)<0.00001) then ! To exit the loop on getting the answer upto a certain number of decimal places
root=a
exit
end if
end do
end if
write (*,*) 'The root of x**2-x-5 in the range ',a,' to ',b,' is ',root !To display the result
end program rootf
!Subprogram to define the function, f
function f(x)
implicit none
real f,x
f=x**2-x-5 !You can change the function as per choice. Just make sure it is continuous
end function f
Sample Output for the Bisection Method
|
Fortran Program For Bisection Method Examples
- Related Questions & Answers
- Selected Reading
Given with the function f(x) with the numbers a and b where, f(a) * f(b) > 0 and the function f(x) should lie between a and b i.e. f(x) = [a, b]. The task is to find the value of root that lies between interval a and b in function f(x) using bisection method.
What is bisection method?
Bisection method is used to find the value of a root in the function f(x) within the given limits defined by ‘a’ and ‘b’. The root of the function can be defined as the value a such that f(a) = 0.
Example
Now, If a function f(x) is continuous in the given interval [a..b] and also, sign of f(a) ≠ sign of f(b) then there will be a value m which belongs to the interval a and b such that f(m) = 0
Value m [a..b] Such that f(m) = 0
I.e. m is the value of root which can be multiple
Given below is the figure which is showing the intervals f(a) and f(b). To find the root between these intervals the limit is divided into parts and stored in the variable m i.e.
m = (a + b) / 2
After the division of limits new interval will be generated as shown in the figure given below
Example
Approach that we are using in the below program is as follow −
- Input the equation and the value of intervals a and b
- Divide the intervals as : m = (a + b) / 2
- Print m is the root
- If f(m) ≠ 0
- Check if f(a) * f(m) < 0
- Then root will lie between a and m
- Check if f(b) * f(m) < 0
- Then root will lie between b and m