!*************************************************** !* Chebyshev Approximation of a user defined real * !* function FUNC(X) in double precision. * !* ----------------------------------------------- * !* SAMPLE RUN: * !* (Approximate integral of sin(x) from x=0 to * !* x=PI). * !* * !* X Chebyshev Eval. -COS(X)+1 * !* of integral * !* ---------------------------------------------- * !* 0.00000000E+00 -0.11102230E-15 0.00000000E+00 * !* 0.15707963E+00 0.12311655E-01 0.12311659E-01 * !* 0.31415927E+00 0.48943486E-01 0.48943484E-01 * !* 0.47123890E+00 0.10899348E+00 0.10899348E+00 * !* 0.62831853E+00 0.19098301E+00 0.19098301E+00 * !* 0.78539816E+00 0.29289320E+00 0.29289322E+00 * !* 0.94247780E+00 0.41221476E+00 0.41221475E+00 * !* 0.10995574E+01 0.54600948E+00 0.54600950E+00 * !* 0.12566371E+01 0.69098300E+00 0.69098301E+00 * !* 0.14137167E+01 0.84356552E+00 0.84356553E+00 * !* 0.15707963E+01 0.10000000E+01 0.10000000E+01 * !* 0.17278760E+01 0.11564344E+01 0.11564345E+01 * !* 0.18849556E+01 0.13090169E+01 0.13090170E+01 * !* 0.20420352E+01 0.14539905E+01 0.14539905E+01 * !* 0.21991149E+01 0.15877852E+01 0.15877853E+01 * !* 0.23561945E+01 0.17071068E+01 0.17071068E+01 * !* 0.25132741E+01 0.18090169E+01 0.18090170E+01 * !* 0.26703538E+01 0.18910065E+01 0.18910065E+01 * !* 0.28274334E+01 0.19510565E+01 0.19510565E+01 * !* 0.29845130E+01 0.19876883E+01 0.19876883E+01 * !* 0.31415927E+01 0.20000000E+01 0.20000000E+01 * !* * !* F90 Release By J-P Moreau, Paris. * !* (www.jpmoreau.fr) * !*************************************************** ! To link with Chebyshev.f90. PROGRAM TESTCHEBINT parameter(NMAX=50,ONE=1.d0,ZERO=0.d0) real*8 PI,X0,X1, COEFF(NMAX), CINT(NMAX) real*8 DX, X PI=4.d0*datan(1.d0) N=10 X0=ZERO; X1=PI !calculate Chebyshev coefficients of FUNC(X) call CHEBFT(X0,X1,COEFF,N) NPTS=2*N+1 DX=(X1-X0)/(NPTS-1) X=X0-DX !calculate Chebyshev coefficients of integral of FUNC(X) call CHINT(X0,X1,COEFF,CINT,N) !compare Chebyshev evaluation of integral with exact value !(the constant of integration is set such as initial value !of integral is zero). print *,' X Chebyshev Eval. -COS(X)+1 ' print *,' of integral ' print *,' ----------------------------------------------' do I=1, NPTS X=X+DX write(*,20) X, CHEBEV(X0,X1,CINT,N,X), -DCOS(X)+ONE end do 20 format(3E16.8) END !user defined function real*8 function FUNC(x) real*8 x FUNC=DSIN(x) return end !end of file Tchebint.f90