These routines execute a classical zero finding numerical algorithm of Richard Brent. The algorithm is executed in four ways, all using the same example of finding a zero of the function f(x) = x*(x*x-2.0d0)-5.0 on the interval [2,3]. Some concepts of Object-Oriented computing are illustrated in the source codes.
Four executables may be generated from the makefile
A Fortran 90 main program and function subprogram call the original code.
This module contains a derived type for the required interval and error tolerance, and the zero finding algorithm as a module subprogram. The user function is an external subprogram that is located at the end of the main program.
These modules, brentClass and brentExtraArgs, extend a derived type to a user class. The zero solving algorithm is packaged in brentClass and uses the contents of the user class to call the user function, packaged in brentExtraArgs.
The program testClassFinalize uses modules brentExtraArgsFinalize and brentClass. The derived type brentArgs is extended to a user class argument that has a finalization routine which is called as the class argument dies or is deallocated. In this example the evaluation abscissa and associated function values are written to an external file, EvaluationList. This file is summarized and closed in the finalization routine, close_evaluation_file.
Root = 2.0945514809
Root of f(x) = x*(x*x-2.0d0)-param = 0, is: 2.0945514809 The number of function evaluations required: 8 Output from the finalization routine: Number of function evaluations: 8 The file EvaluationList is closed.
2.0000000000 -1.0000000000 3.0000000000 16.0000000000 2.5000000000 5.6250000000 2.0754716981 -0.2106772705 2.0948885338 0.0037627021 2.0945478335 -0.0000407172 2.0945514809 -0.0000000077 2.0945514883 0.0000000754