Return to site

Fortran Program For Bisection Method

broken image


I'm trying to implement Bisection Method with Fortran 90 to get solution, accurate to within 10^-5 for 3x - e^x = 0 for 1. Edius pro 9 download free. The bisection method is simple, robust, and straight-forward: take an interval a, b such that f(a) and f(b) have opposite signs, find the midpoint of a, b, and then decide whether the root lies on a, (a+ b)/2 or (a+ b)/2, b. Repeat until the interval is. 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. Program For Bisection Method In Fortran Download January 21 2019 The bisection method in mathematics is a root-finding method that repeatedly bisects an interval and then selects a subinterval in which a root must lie for further.

In the following table, each line/entry contains the program file name, the page number where it can be found in the textbook, and a brief description. Click on the program name to display the source code, which can be downloaded.
Chapter 1: Introduction
first.f906-7First programming experiment
pi.f90 8Simple code to illustrate double precision
Chapter 2: Number Representation and Errors
oct.f90 49Print in octal format
hex.f90 50Print in hexadecimal format
numbers.f90 60-61Print internal machine representation of various numbers
xsinx.f90 77-79Example of carefully programming f(x) = x - sinx
Chapter 3: Locating Roots of Equations
bisection.f9094-95Bisection method
rec_bisection.f9095-96Recursive version of bisection method
newton.f90106-107Sample Newton method
secant.f90127-128Secant method
Chapter 4: Interpolation and Numerical Differentiation
coef.f90152-155Newton interpolation polynomial at equidistant pts
deriv.f90185-186Derivative by center differences/Richardson extrapolation
Chapter 5: Numerical Integration
sums.f90200Upper/lower sums experiment for an integral
trapezoid.f90207Trapezoid rule experiment for an integral
romberg.f90223-224 Romberg arrays for three separate functions
Chapter 6: More on Numerical Integration
rec_simpson.f90241Adaptive scheme for Simpson's rule
Chapter 7: Systems of Linear Equations
ngauss.f90270-271Naive Gaussian elimination to solve linear systems
gauss.f90285-287Gaussian elimination with scaled partial pivoting
tri.f90301-302Solves tridiagonal systems
penta.f90304Solves pentadiagonal linear systems
Chapter 8: More on Systems of Linear Equations
Chapter 9: Approximation by Spline Functions
spline1.f90385Interpolates table using a first-degree spline function
spline3.f90404-406Natural cubic spline function at equidistant points
bspline2.f90427-428Interpolates table using a quadratic B-spline function
schoenberg.f90430-431Interpolates table using Schoenberg's process
Chapter 10: Ordinary Differential Equations
euler.f90448-449Euler's method for solving an ODE
taylor.f90451Taylor series method (order 4) for solving an ODE
rk4.f90462-463Runge-Kutta method (order 4) for solving an IVP
rk45.f90472-473Runge-Kutta-Fehlberg method for solving an IVP
rk45ad.f90474Adaptive Runge-Kutta-Fehlberg method
Chapter 11: Systems of Ordinary Differential Equations
taylorsys1.f90489-490Taylor series method (order 4) for systems of ODEs
taylorsys2.f90491Taylor series method (order 4) for systems of ODEs
rk4sys.f90491-493,496Runge-Kutta method (order 4) for systems of ODEs
amrk.f90510-513 Adams-Moulton method for systems of ODEs
amrkad.f90513Adaptive Adams-Moulton method for systems of ODEs
Chapter 12: Smoothing of Data and the Method of Least Squares
Chapter 13: Monte Carlo Methods and Simulation
test_random.f90562-563Example to compute, store, and print random numbers
coarse_check.f90564Coarse check on the random-number generator
double_integral.f90574-575Volume of a complicated 3D region by Monte Carlo
volume_region.f90575-576Numerical value of integral over a 2D disk by Monte Carlo
cone.f90576-577 Ice cream cone example
loaded_die.f90581Loaded die problem simulation
birthday.f90583Birthday problem simulation
needle.f90584Buffon's needle problem simulation
two_die.f90585Two dice problem simulation
shielding.f90586-587Neutron shielding problem simulation
Chapter 14: Boundary Value Problems for Ordinary Differential Equations
bvp1.f90602-603Boundary value problem solved by discretization technique
bvp2.f90605-606Boundary value problem solved by shooting method
Chapter 15: Partial Differential Equations
parabolic1.f90618-619 Parabolic partial differential equation problem
parabolic2.f90620-621Parabolic PDE problem solved by Crank-Nicolson method
hyperbolic.f90633-634Hyperbolic PDE problem solved by discretization
seidel.f90642-645 Elliptic PDE solved by discretization/ Gauss-Seidel method
Chapter 16: Minimization of Functions
Chapter 17: Linear Programming

Addditional programs can be found at the textbook's anonymous ftp site: V torrent.

Lagu

[Home] [Features] [TOC] [Purchase] [Sample Code] [Web] [Manuals] [Errata] [Links]
Last updated: 5/20/2003
The bisection method is useful when you want to find a root of a continuous function in a specified range. It works on the Intermediate Value Theorem

Fortran Program For Bisection Method

Fortran Program For Bisection 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).
Pros and Cons: This method is useful to find a value of a root where other methods fail. It is a slow method but has a

Fortran Program Example

convergence factor of 1 and is thus considered very reliable.
For

[Home] [Features] [TOC] [Purchase] [Sample Code] [Web] [Manuals] [Errata] [Links]
Last updated: 5/20/2003
The bisection method is useful when you want to find a root of a continuous function in a specified range. It works on the Intermediate Value Theorem

Fortran Program For Bisection 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).
Pros and Cons: This method is useful to find a value of a root where other methods fail. It is a slow method but has a

Fortran Program Example

convergence factor of 1 and is thus considered very reliable.

Fortran Program For Bisection Method Example

Now for the FORTRAN program,
!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

Fortran Program For Bisection Method Overriding


Sample Output for the Bisection Method
Confirming the answer with Gnuplot. Notice how the intervals get smaller while 'hunting' for the root. Clearly, one point (x,f(x)) remains above the x-axis and the other below it, till we find a root (x,0). Also note that the other root which is outside the range [0,9] remains untouched.




broken image