Program For Bisection Method In Fortran Language

Posted on by admin
  1. Bisection Method Example
  2. Bisection Method Matlab
I'm rusty with fortran and programming in general. I can't see my 'error' in a code that I wrote from scratch.
Basically I wanted to get some fun and solve for a temperature in thermodynamics where I must get 'T_f' which appear in a transcendental equation: ##Aln left ( frac{T_f^2}{T_1T_2} right )+2B[2T_f-(T_1T_2)]=0##.
Where T_1 is worth 100, T_2 is worth 200, A=2 and B=0.005.
Here is my code: that I compile along with The problem is that for the values I said above, I get the message 'There's an even number of root(s) in that interval'. Thus apparently the condition f(a)*f(b)>0 is satisfied. However when I enter the numbers in my pocket calculator I get f(a)=-2.3862... and f(b)=2.3862... where I truncated both values. Thus the condition is not satisfied.
I really don't see what's wrong. Any idea?
Edit: I tried with many different values for a and b. I even changed t_1 and t_2, same message.
Edit2: I've just tested the values of fa and fb. It thinks they are worth infinity. Going to check this out.
Edit3: No idea why it thinks they are worth infinity. o_0.
Edit4: ok it does not plug in t_1 and t_2 inside my function.

Solving the linear system of equations by CHOLESKY'S method. Finding the EIGENVALUES and EIGENVECTORS by JACOBI method. Solving the linear system of equations by GAUSS ELIMINATION method. Solving the linear system of equations by JACOBI method. Solving the linear system of equations by GAUSS-SEIDEL method. Sample page from NUMERICAL RECIPES IN FORTRAN 77: THE ART OF. 1970, Numerical Methods That Work; 1990, corrected edition.

BISECTION_RC is a FORTRAN90 library which demonstrates the simple bisection method for solving a scalar nonlinear equation in a change of sign interval, using reverse communication (RC).

The routine assumes that an interval [a,b] is known, over which the function f(x) is continuous, and for which f(a) and f(b) are of opposite sign. By repeatedly computing and testing the midpoint, the halving change of sign interval may be reduced, so that either the uncertainty interval or the magnitude of the function value becomes small enough to satisfy the user as an approximation to the location of a root of the function.

This routine is in part a demonstration of the idea of reverse communication. Many zero finders require that the user define f(x) by writing a function with a very specific set of input and output arguments, and sometimes with a specific name, so that the user can call the zero finder, which in turn can call the function. This is sometimes an awkward formulation to follow. Reverse communication instead allows the user's calling program to retain control of the function evaluation.

To use the reverse communication zero finder, the user defines the values of A and B, and sets a parameter JOB to zero to indicate that this is the first call. From then on, the zero finder repeatedly returns a value X, asking the user to evaluate the function there. Once the user has evaluated FX = f(X), the user may accept this approximation to the root, or else call the zero finder again, passing the just-computed value of FX so that it can take another bisection step.

Fortran language

Licensing:

The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.

Languages:

BISECTION_RC is available in a C version and a C++ version and a FORTRAN77 version and a FORTRAN90 version and a MATLAB version and a Python version.

Related Data and Programs:

BACKTRACK_BINARY_RC, a FORTRAN90 library which carries out a backtrack search for a set of binary decisions, using reverse communication.

Bisection Method Example

BISECTION_INTEGER, a FORTRAN90 library which seeks an integer solution to the equation F(X)=0, using bisection within a user-supplied change of sign interval [A,B].

BRENT, a FORTRAN90 library which contains Richard Brent's routines for finding the zero, local minimizer, or global minimizer of a scalar function of a scalar argument, without the use of derivative information.

CG_RC, a FORTRAN90 library which implements the conjugate gradient (CG) method for solving a positive definite sparse linear system A*x=b, using reverse communication (RC).

LOCAL_MIN_RC, a FORTRAN90 library which finds a local minimum of a scalar function of a scalar variable, without the use of derivative information, using reverse communication (RC), by Richard Brent.

NMS, a FORTRAN90 library which includes a wide variety of numerical software, including solvers for linear systems of equations, interpolation of data, numerical quadrature, linear least squares data fitting, the solution of nonlinear equations, ordinary differential equations, optimization and nonlinear least squares, simulation and random numbers, trigonometric approximation and Fast Fourier Transforms (FFT).

ROOT_RC, a FORTRAN90 library which seeks a solution of a scalar nonlinear equation f(x) = 0, or a system of nonlinear equations, using reverse communication (RC), by Gaston Gonnet.

ROOTS_RC, a FORTRAN90 library which seeks a solution of a system of nonlinear equations f(x) = 0, using reverse communication (RC), by Gaston Gonnet.

Bisection Method Matlab

SORT_RC, a FORTRAN90 library which can sort a list of any kind of objects, using reverse communication (RC).

TEST_ZERO, a FORTRAN90 library which implements test problems for the solution of a single nonlinear equation in one variable.

ZERO_RC, a FORTRAN90 library which seeks a solution of a scalar nonlinear equation f(x) = 0, using reverse communication (RC), by Richard Brent.

ZOOMIN, a FORTRAN90 library which includes various zero finder routines.

Reference:

  1. Werner Rheinboldt,
    Algorithms for finding zeros of a function,
    UMAP Journal,
    Volume 2, Number 1, 1981, pages 43-72.
  2. Werner Rheinboldt,
    Methods for Solving Systems of Nonlinear Equations,
    SIAM, 1998,
    ISBN: 089871415X,
    LC: QA214.R44.

Source Code:

  • bisection_rc.f90, the source code.

Examples and Tests:

  • bisection_rc_prb.f90, a sample calling program.
  • bisection_rc_prb_output.txt, the output file.

List of Routines:

  • BISECTION_RC seeks a zero of f(x) in a change of sign interval.
  • R8_SIGN returns the sign of an R8.
  • TIMESTAMP prints the current YMDHMS date as a time stamp.

You can go up one level to the FORTRAN90 source codes.

Last revised on 13 January 2013.