Exemple de comment programmer une dérivée en un point en fortran 90:
program derivative_functionimplicit noneinteger, parameter :: pr = selected_real_kind(15,3)real(pr) :: x,hreal(pr) :: der_estimate, previous_der_estimatereal(kind=16) :: finteger :: i,nx = 2.0h = 1.0n = 10do i = 1, 10der_estimate = ( f(x+h) - f(x) ) / hif( i == 1) write(6,*) h, der_estimateif( i > 1) write(6,*) h, der_estimate, der_estimate - previous_der_estimateprevious_der_estimate = der_estimateh = h / 10.0end doend program derivative_function!----------------------------------------------------------------------------------------!real(kind=16) function f(x)implicit noneinteger, parameter :: pr = selected_real_kind(15,3)real(pr), intent(in) :: xf = x**2.0end function f!----------------------------------------------------------------------------------------!
donne
1.0000000000000000 5.00000000000000000.10000000000000001 4.1000000000000014 -0.899999999999998581.0000000000000000E-002 4.0099999999998914 -9.0000000000109992E-0021.0000000000000000E-003 4.0009999999996992 -9.0000000001921876E-0031.0000000000000000E-004 4.0001000000078335 -8.9999999186574087E-0041.0000000000000001E-005 4.0000100000270322 -8.9999980801280799E-0051.0000000000000002E-006 4.0000010006480116 -8.9993790206577273E-0061.0000000000000002E-007 4.0000000911533098 -9.0949470177292824E-0071.0000000000000002E-008 3.9999999756901152 -1.1546319456101628E-0071.0000000000000003E-009 4.0000003309614831 3.5527136788005009E-007
Dans cet exemple la dérivée de la fonction $f(x) = x^2$ en x = 2 est 4.
Références
| Liens | Site |
|---|---|
| Numerical Integration and Differentiation | oregonstate.edu |
| Numerical Analysis: Mathematics of Scientific Computing | utexas.edu |
| Numerical Modelling in Fortran: day 2 | upiter.ethz.ch |
| FORTDIFF: A Set of Subroutines for Fortran-to-Fortran Differentiation of Programs | interval.louisiana.edu |
| Fortran subroutines and functions | faculty.washington.edu |
