4066
Calculating Incomplete Beta Functions with IDL
Tolerance controls allow you to calculate the accuracy of the incomplete beta and gamma functions. See the Help Article #3182 for calculating Incomplete Gamma Functions.
Working With Tolerances in the Incomplete Beta Function: this example shows the difference in accuracy between the incomplete beta function computed with a low tolerance and the incomplete beta function computed with a high tolerance. The resulting surfaces show the relative errors of each. The relative error of the low tolerance ranges from 0 to 0.00002 percent. The relative error of the high tolerance ranges from 0 to 0.00000000008 percent.
More accuracy usually provides better results, but can cause slower computation speeds. If faster speeds are important, a less accurate calculation may be more desirable. This trade-off can be maintained through tolerances. Iteration controls allow you to expand the computation enough to converge to a result. Calculation of these functions may not converge to a result within the default number of iterations. If the number of iterations is increased, the calculation may converge.
Code Example:
PRO usingIBETAwithEPS
; Define an array of parametric exponents.
parameterA = (DINDGEN(101)/100. + 1.D) # REPLICATE(1.D, 101)
parameterB = REPLICATE(1.D, 101) # (DINDGEN(101)/10. + 1.D)
; Define the upper limits of integration.
upperLimits = REPLICATE(0.1D, 101, 101)
; Compute the incomplete beta functions.
betaFunctions = IBETA(parameterA, parameterB, $
upperLimits)
; Compute the incomplete beta functions with a less
; accurate tolerance set.
laBetaFunctions = IBETA(parameterA, parameterB, $
upperLimits, EPS = 3.0e-4)
; Compute relative error.
relativeError = 100.* $
ABS((betaFunctions - laBetaFunctions)/betaFunctions)
; Display resulting relative error.
WINDOW, 0, TITLE = 'Compare IBETA with Less Accurate EPS'
SURFACE, relativeError, parameterA, parameterB, $
/XSTYLE, /YSTYLE, TITLE = 'Relative Error', $
XTITLE = 'Parameter A', YTITLE = 'Parameter B', $
ZTITLE = 'Percent Error (%)', CHARSIZE = 1.5
; Compute the incomplete beta functions with a more
; accurate tolerance set.
maBetaFunctions = IBETA(parameterA, parameterB, $
upperLimits, EPS = 3.0e-10)
; Compute relative error.
relativeError = 100.* $
ABS((betaFunctions - maBetaFunctions)/betaFunctions)
; Display resulting relative error.
WINDOW, 1, TITLE = 'Compare IBETA with More Accurate EPS'
SURFACE, relativeError, parameterA, parameterB, $
/XSTYLE, /YSTYLE, TITLE = 'Relative Error', $
XTITLE = 'Parameter A', YTITLE = 'Parameter B', $
ZTITLE = 'Percent Error (%)', CHARSIZE = 1.5
END
_______________________________________________________
Reviewed by BC on 09/05/2014