Differential program in fortran
24/03/2019
Hello , I’m Sakura Ebi
In this article , I introduce the differential program of fortran.
In this program has a function of calculate the differential of \(f(x)\) at any position.
differential formula is bellow
\[
f'(x) = \frac{d}{dx} f(x)
\]
source-code of this processing is below
function DIF_F(fun,x) implicit none double precision fun,x,DIF_F,dx dx = 1.0E-8 dIF_F = (fun(x+dx)-fun(x))/dx end function
Terminal Output of below shows differential of \( f(x) = x^2\) at \(x = 0,1…5\)

To show above Output list,I made a test program below.
This function needs the external statement.
program test implicit none external func double precision x,func,DIF_F print *, "x","f'(x)","2x","error" x = 0.d0 print *, x,DIF_F(func,x),2*x,DIF_F(func,x)-2*x x = 1.d0 print *, x,DIF_F(func,x),2*x,DIF_F(func,x)-2*x x = 2.d0 print *, x,DIF_F(func,x),2*x,DIF_F(func,x)-2*x x = 3.d0 print *, x,DIF_F(func,x),2*x,DIF_F(func,x)-2*x x = 4.d0 print *, x,DIF_F(func,x),2*x,DIF_F(func,x)-2*x x = 5.d0 print *, x,DIF_F(func,x),2*x,DIF_F(func,x)-2*x end program
Thanks by Sakua Ebi
In Japanese
微分プログラム [fortran]