Numerical differentiation of user defined function using diff.
interface to function
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(diff_func), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in) | :: | x |
class to define the function:
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| procedure(func), | public, | pointer | :: | f | => | null() |
| procedure, public :: faccur | |
| procedure, public :: set_function | |
| procedure, public :: compute_derivative => diff |
the procedure diff calculates the first, second or third order derivative of a function by using neville's process to extrapolate from a sequence of simple polynomial approximations based on interpolating points distributed symmetrically about x0 (or lying only on one side of x0 should this be necessary). if the specified tolerance is non-zero then the procedure attempts to satisfy this absolute or relative accuracy requirement, while if it is unsuccessful or if the tolerance is set to zero then the result having the minimum achievable estimated error is returned instead.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(diff_func), | intent(inout) | :: | me | |||
| integer, | intent(in) | :: | iord | 1, 2 or 3 specifies that the first, second or third order derivative,respectively, is required. |
||
| real(kind=wp), | intent(in) | :: | x0 | the point at which the derivative of the function is to be calculated. |
||
| real(kind=wp), | intent(in) | :: | xmin | xmin, xmax restrict the interpolating points to lie in [xmin, xmax], which should be the largest interval including x0 in which the function is calculable and continuous. |
||
| real(kind=wp), | intent(in) | :: | xmax | xmin, xmax restrict the interpolating points to lie in [xmin, xmax], which should be the largest interval including x0 in which the function is calculable and continuous. |
||
| real(kind=wp), | intent(in) | :: | eps | denotes the tolerance, either absolute or relative. eps=0 specifies that the error is to be minimised, while eps>0 or eps<0 specifies that the absolute or relative error, respectively, must not exceed abs(eps) if possible. the accuracy requirement should not be made stricter than necessary, since the amount of computation tends to increase as the magnitude of eps decreases, and is particularly high when eps=0. |
||
| real(kind=wp), | intent(in) | :: | accr | denotes that the absolute (accr>0) or relative (accr<0) errors in the computed values of the function are most unlikely to exceed abs(accr), which should be as small as possible. if the user cannot estimate accr with complete confidence, then it should be set to zero. |
||
| real(kind=wp), | intent(out) | :: | deriv | the calculated value of the derivative |
||
| real(kind=wp), | intent(out) | :: | error | an estimated upper bound on the magnitude of the absolute error in the calculated result. it should always be examined, since in extreme case may indicate that there are no correct significant digits in the value returned for derivative. |
||
| integer, | intent(out) | :: | ifail | will have one of the following values on exit: 0 the procedure was successful. 1 the estimated error in the result exceeds the (non-zero) requested error, but the most accurate result possible has been returned. 2 input data incorrect (derivative and error will be undefined). 3 the interval [xmin, xmax] is too small (derivative and error will be undefined). |
Support routine for diff.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(diff_func), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(inout) | :: | h0 | |||
| real(kind=wp), | intent(inout) | :: | h1 | |||
| real(kind=wp), | intent(out) | :: | facc | |||
| real(kind=wp), | intent(in) | :: | x0 | |||
| real(kind=wp), | intent(in) | :: | twoinf | |||
| real(kind=wp), | intent(in) | :: | f0 | |||
| real(kind=wp), | intent(in) | :: | f1 |