回 帖 发 新 帖 刷新版面

主题:晕!不小心结贴了!再求助积分程序修改吧

那个帖子不小心结了[em2][em2][em2],期待高手帮忙看下,小程序
program jifenQDAGS
     use imsl
     implicit none
     real a,b,erra,errest,f,res,errrel
     external f
     ERRA=1.0e-3
     ERRREL=1.0e-2
     a=0.0
     b=3.0

   CALL QDAGS (F, a, b, RES, ERRA,ERRREL, ERREST)

   WRITE (*,*) RES, ERREST
    END      
      
    REAL FUNCTION F (X)
    REAL X      
    
    F = x*x
    RETURN      
    END      

得到的积分结果为什么总是0呢?无论函数形式什么样,总是会出现0的结果。奇怪啊

回复列表 (共6个回复)

沙发

我试着修改了一下,给res一个初始值 res=2.0,得到的积分结果就是2.0,也就是说程序没有执行求导过程,问题出在哪里呢?

板凳

用IMSL的人不是很多, 你试试把那个函数的接口帖出来吧. 把那个子函数参数的详细信息帖出来.

3 楼


QDAGS
Integrates a function (which may have endpoint singularities).
Required Arguments
F — User-supplied FUNCTION to be integrated. The form is F(X), where
X − Independent variable. (Input)
F − The function value. (Output)
F must be declared EXTERNAL in the calling program.
A — Lower limit of integration. (Input)
B — Upper limit of integration. (Input)
RESULT — Estimate of the integral from A to B of F. (Output)

Optional Required Arguments
ERRABS — Absolute accuracy desired. (Input)
Default: ERRABS = 1.e-3 for single precision and 1.d-8 for double precision.
ERRREL — Relative accuracy desired. (Input)
Default: ERRREL = 1.e-3 for single precision and 1.d-8 for double precision.
ERREST — Estimate of the absolute value of the error. (Output)

FORTRAN 90 Interface
Generic: CALL QDAGS (F, A, B, RESULT [,…])
Specific: The specific interface names are S_QDAGS and D_QDAGS.
FORTRAN 77 Interface
Single: CALL QDAGS (F, A, B, ERRABS, ERRREL, RESULT, ERREST)
Double: The double precision name is DQDAGS.

Description
The routine QDAGS is a general-purpose integrator that uses a globally adaptive scheme to reduce
the absolute error. It subdivides the interval [A, B] and uses a 21-point Gauss-Kronrod rule to
estimate the integral over each subinterval. The error for each subinterval is estimated by comparison with the 10-point Gauss quadrature rule. This routine is designed to handle functions with endpoint singularities. However, the performance on functions, which are well-behaved at the
endpoints, is quite good also. In addition to the general strategy described in QDAG, this routine
uses an extrapolation procedure known as the ε-algorithm. The routine QDAGS is an implementation of the routine QAGS, which is fully documented by Piessens et al. (1983). Should QDAGS fail to produce acceptable results, then either IMSL routines QDAG or QDAG* may be
appropriate. These routines are documented in this chapter.

Example
The value of
( ) 1 1/ 2
0
∫ ln x x− dx = −4
is estimated. The values of the actual and estimated error are machine dependent.
USE QDAGS_INT
USE UMACH_INT
IMPLICIT NONE
INTEGER NOUT
REAL A, ABS, B, ERRABS, ERREST, ERROR, ERRREL, EXACT, F, &
RESULT
INTRINSIC ABS
EXTERNAL F
! Get output unit number
CALL UMACH (2, NOUT)
! Set limits of integration
A = 0.0
B = 1.0
! Set error tolerances
ERRABS = 0.0
CALL QDAGS (F, A, B, RESULT, ERRABS=ERRABS, ERREST=ERREST)
! Print results
EXACT = -4.0
ERROR = ABS(RESULT-EXACT)
WRITE (NOUT,99999) RESULT, EXACT, ERREST, ERROR
99999 FORMAT (' Computed =', F8.3, 13X, ' Exact =', F8.3, /, /, &
' Error estimate =', 1PE10.3, 6X, 'Error =', 1PE10.3)
END
!
REAL FUNCTION F (X)
REAL X
REAL ALOG, SQRT
INTRINSIC ALOG, SQRT
F = ALOG(X)/SQRT(X)
RETURN
END

Output
Computed = -4.000 Exact = -4.000
Error estimate = 1.519E-04 Error = 2.098E-05


4 楼


问题找到了!放错res位置

program jifenQDAGS
     use imsl
         implicit none
         real a,b,erra,errest,f,res,errrel
         external f
     ERRA=1.0e-3
     ERRREL=1.0e-2
         a=0.0
         b=3.0
   CALL QDAGS (F, a, b, ERRREL, ERRA,RES, ERREST)
   WRITE (*,*) RES, ERREST
        END          
    REAL FUNCTION F (X)
        REAL X          
        F = x*x
        RETURN          
    END 

悲剧啊

5 楼

防止位置弄错你可以用关键词调用的
CALL QDAGS (F=f, a=a, b=b, ERRREL=errest, ERRA=erra,RES=res, ERREST=errest)
这样调用弄错位置都没关系.

6 楼

经典啊!!多谢了

我来回复

您尚未登录,请登录后再回复。点此登录或注册