0

I have a curve between dff(x axis) and dc(y axis) and I calculated the area under the curve using IN_TABULATED function.

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

Now, I need to have a loop start from n,0 (from right to left) and calculate A1 which is 0.01 of A and to stop there, then print dff values which represent A1's area. How can I do this? Any suggestion will be helpful.

A.KT
  • 11
  • 4

1 Answers1

0

I'm not sure I fully understand the question, so let me begin by stating my interpretation. You have a curve which integrates to A. Starting from the right, you want the X-value (let's call it X1) which encloses 0.01 of A (the total area under the curve). In other words, 0.99 of the total area under the curve F is to the left of X1, and 0.01 of the area is to the right.

Assuming this interpretation is correct, here's a solution: First, loop through the data and calculate the integral from 0 to each point.

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

Then, you can interpolate to find X1:

;;; Find where cumulative distribution reaches 0.99 of A

a1 = 0.99 * a

x1 = interpol(x, area_cumulative, a1)

Here's an illustration. The upper plot is your data, and the lower plot is the cumulative area (integral from x[0] to x). The red dashed lines show X1 = 0.001952. The gray shaded region contains 0.01 of the total area.

Plot illustrating how to find X1

Hope this helps!

Steve G
  • 182
  • 9