Go to the documentation of this file.00001
00002 REAL FUNCTION BETAI (X, PIN, QIN)
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 LOGICAL FIRST
00038 SAVE EPS, ALNEPS, SML, ALNSML, FIRST
00039 DATA FIRST /.TRUE./
00040
00041 IF (FIRST) THEN
00042 EPS = R1MACH(3)
00043 ALNEPS = LOG(EPS)
00044 SML = R1MACH(1)
00045 ALNSML = LOG(SML)
00046 ENDIF
00047 FIRST = .FALSE.
00048
00049 IF (X .LT. 0. .OR. X .GT. 1.0) CALL XERMSG ('SLATEC', 'BETAI',
00050 + 'X IS NOT IN THE RANGE (0,1)', 1, 2)
00051 IF (PIN .LE. 0. .OR. QIN .LE. 0.) CALL XERMSG ('SLATEC', 'BETAI',
00052 + 'P AND/OR Q IS LE ZERO', 2, 2)
00053
00054 Y = X
00055 P = PIN
00056 Q = QIN
00057 IF (Q.LE.P .AND. X.LT.0.8) GO TO 20
00058 IF (X.LT.0.2) GO TO 20
00059 Y = 1.0 - Y
00060 P = QIN
00061 Q = PIN
00062
00063 20 IF ((P+Q)*Y/(P+1.).LT.EPS) GO TO 80
00064
00065
00066
00067
00068 PS = Q - AINT(Q)
00069 IF (PS.EQ.0.) PS = 1.0
00070 XB = P*LOG(Y) - ALBETA(PS, P) - LOG(P)
00071 BETAI = 0.0
00072 IF (XB.LT.ALNSML) GO TO 40
00073
00074 BETAI = EXP (XB)
00075 TERM = BETAI*P
00076 IF (PS.EQ.1.0) GO TO 40
00077
00078 N = MAX (ALNEPS/LOG(Y), 4.0E0)
00079 DO 30 I=1,N
00080 TERM = TERM*(I-PS)*Y/I
00081 BETAI = BETAI + TERM/(P+I)
00082 30 CONTINUE
00083
00084
00085
00086 40 IF (Q.LE.1.0) GO TO 70
00087
00088 XB = P*LOG(Y) + Q*LOG(1.0-Y) - ALBETA(P,Q) - LOG(Q)
00089 IB = MAX (XB/ALNSML, 0.0E0)
00090 TERM = EXP (XB - IB*ALNSML)
00091 C = 1.0/(1.0-Y)
00092 P1 = Q*C/(P+Q-1.)
00093
00094 FINSUM = 0.0
00095 N = Q
00096 IF (Q.EQ.REAL(N)) N = N - 1
00097 DO 50 I=1,N
00098 IF (P1.LE.1.0 .AND. TERM/EPS.LE.FINSUM) GO TO 60
00099 TERM = (Q-I+1)*C*TERM/(P+Q-I)
00100
00101 IF (TERM.GT.1.0) IB = IB - 1
00102 IF (TERM.GT.1.0) TERM = TERM*SML
00103
00104 IF (IB.EQ.0) FINSUM = FINSUM + TERM
00105 50 CONTINUE
00106
00107 60 BETAI = BETAI + FINSUM
00108 70 IF (Y.NE.X .OR. P.NE.PIN) BETAI = 1.0 - BETAI
00109 BETAI = MAX (MIN (BETAI, 1.0), 0.0)
00110 RETURN
00111
00112 80 BETAI = 0.0
00113 XB = P*LOG(MAX(Y,SML)) - LOG(P) - ALBETA(P,Q)
00114 IF (XB.GT.ALNSML .AND. Y.NE.0.) BETAI = EXP (XB)
00115 IF (Y.NE.X .OR. P.NE.PIN) BETAI = 1.0 - BETAI
00116 RETURN
00117
00118 END