使用idl的曲线下面积

时间:2018-06-21 12:25:10

标签: idl-programming-language

我在dff(x轴)和dc(y轴)之间有一条曲线,并使用IN_TABULATED函数计算了曲线下的面积。

X=[-0.00205553,-0.00186668,-0.00167783,-0.00148899,-0.00130014,-0.00111129,-0.000922443,-0.000733597,-0.000450326,-0.000261480,0.000116216,0.000399487,  0.000588333,0.000777179,0.000966027,0.00115488,0.00134372,0.00153257,0.00172141,0.00181584,0.00200468]
F=[0.00000,21.0000,26.0000,57.0000,94.0000,148.000,248.000,270.000,388.000,418.000,379.000,404.000,358.000,257.000,183.000,132.000,81.0000,47.0000,23.0000,17.0000,431.000]
A=INT_TABULATED(X,F)
print, A

现在,我需要从n,0(从右到左)开始循环,并计算A1(即A的0.01)并在此处停止,然后打印代表A1区域的dff值。我怎样才能做到这一点?任何建议都会有所帮助。

1 个答案:

答案 0 :(得分:0)

我不确定我是否完全理解这个问题,所以让我先说明一下我的理解。您有一条与A积分的曲线。从右边开始,您希望X值(将其称为X1)包围着0.01(A的总面积)。换句话说,曲线F下的总面积的0.99在X1的左侧,而面积的0.01在右侧。

假设这种解释是正确的,这是一个解决方案: 首先,遍历数据并计算从0到每个点的积分。

npoints = n_elements(x)

; Initialize a vector to hold integration results 
area_cumulative = [] 

; Loop through each data point, calculating integrals from 0 to that point
for index = 0, npoints-1 do begin

    ; Assume area under first point is zero, otherwise, calculate integral
    if index eq 0 then area_up_to_point = 0d0 $
      else area_up_to_point = int_tabulated(x[0:index], f[0:index])

    ; Store integral value in the cumulative vector
        area_cumulative = [area_cumulative, area_up_to_point]

endfor

然后,您可以插值找到X1

;;; Find where cumulative distribution reaches 0.99 of A

a1 = 0.99 * a

x1 = interpol(x, area_cumulative, a1)

这是一个例子。上方的图是您的数据,下方的图是累积面积(从x [0]到x的积分)。红色虚线显示X1 = 0.001952。灰色阴影区域占总面积的0.01。

Plot illustrating how to find X1

希望这会有所帮助!