automatic_differentiation - Implement the "automatic differentation" technique
TABLE OF CONTENTS
SYNOPSIS
DESCRIPTION
EXAMPLE
DATA TYPES AND ROUTINES
COPYRIGHT
|
The automatic_differentiation module defines a derived type that enables you (via overloading common mathematical functions and operators) to:
The module uses real numbers of the kind "wp" as defined in the auxiliary module select_precision.
(I was pointed to this technique by Simon Geard, a couple of years ago, in the context of one of the many language shootouts on the Internet.)
In numerical methods like Newton-Raphson for finding a root of the equation "f(x) = 0", you need the first derivative:
x(k+1) = x(k) - f(x(k)) / f'(x(k))
|
program root
use automatic_differentation
type(AUTODERIV) :: x
type(AUTODERIV) :: res
integer :: i
!
! First estimate
!
x = derivvar( 1.0_wp )
do i = 1,10
res = f(x)
x = x - res.v / res.dv
enddo
write(*,*) 'Root: ', x.v
contains
type(AUTODERIV) function f(x)
type(AUTODERIV) :: x
f = x + cos(x)
end function f
end program
|
The module defines a single data type, AUTODERIV, and one specific function, derivvar().
Copyright © 2006 Arjen Markus <arjenmarkus@sourceforge.net>