Documentation for pp_lib

Generated by IDLdoc

single page | use frames     summary     class     fields     routine details     file attributes

./

pp_integral.pro


Routines

top source pp_integral

result = pp_integral(x, y [, xmin=xmin] [, xmax=xmax] [, cumulative=cumulative] [, xinc=xinc] [, yinc=yinc] [, xstart=xstart] [, xend=xend] [, xbox=xbox] [, ybox=ybox] [, newton=newton] [, local=local] [, lsquadratic=lsquadratic] [, quadratic=quadratic] [, spline=spline])

Calculates the area under the y(x) curve provided. The function must be ordered in x, but it does not matter whether the order is increasing or decreasing.

There are two possible ways that the input function is interpreted, determined by the keyword local. See the description of local below, since it may significantly alter the result.

If the method selected requires interpolation, it can be linear, 3 or 4-point quadratic, or spline. This is determined by setting the quadratic, lsquadratic, or spline keywords (linear if none of these 3 keywords is set).

Return value

If xmin and xmax are not provided, returns the area under the curve over its whole extension.

If xmin and xmax are scalars, returns the area between these x values. If they are arrays of n elements, returns the n areas, calculated starting at each xmin element, and ending at the corresponding xmax element.

Every value in xmax is must be larger than or equal to the correspoinding value in xmin.

Parameters

x in required

An array of locations where the function is sampled. Must be ordered (increasing or decreasing).

y in required

An array with the function values corresponding to the locations in x.

Keywords

xmin in out optional

A scalar or array with the start of the range(s) where the area is to be calculated. If not provided, the minimum location of the function is used. Must have the same number of elements as xmax, and every element in xmin must be smaller than or equal to the corresponding element in xmax. If any value of xmin is smaller than the beginning of the x range, it is clipped to the beginning.

xmax in out optional

A scalar or array with the end of the range(s) where the area is to be calculated. If not provided, the maximum location of the function is used. Must have the same number of elements as xmin, and every element in xmax must be larger than or equal to the corresponding element in xmin. If any value of xmax is larger than the end of the x range, it is clipped to the end.

cumulative in optional default=0

If set, and xmin and xmax are not provided, the areas returned are the cumulative areas at the end of each x point, starting at the first x point. If xmax and xmin are provided, this keyword is ignored.

xinc out optional

Returns the x values, in increasing order.

yinc out optional

Returns the y values, in order of increasing x.

xstart out optional

If local is not set, returns the location where each input pixel starts. If local is set, this is ignored.

xend out optional

If local is not set, returns the location where each input pixel ends. If local is set, this is ignored.

xbox out optional

Used when not in local mode, to return the input x values in pairs of equal values, so that plotting xbox,ybox shows the rectangles that are how the input values were interpreted.

ybox out optional

Used when not in local mode, to return the input y values in pairs of equal values, so that plotting xbox,ybox shows the rectangles that are how the input values were interpreted.

newton in optional default=0

If local is set and newton is set, the function integrations are done with int_tabulated, which uses a 5 point Newton-Cotes formula. If not set, trapezoid integration is done. If local is not set, this has no effect.

local in optional default=0

Determines how the input function is interpreted, which determines how the areas are calculated. If set, the function is interpreted literally, that is, as in a simple mathematical function: the y values are the local evaluation y(x).

If not set, the y values are interpreted as a measured sample, that is, as the average of the "flux" falling inside the region centered at the corresponding x values: x locations are interpreted as the centers of bins. Since this interpretation is equivalent to a literal interpretation of a function made of rectangular regions, in this method there are no interpolations (partial areas, if any, are just the corresponding fractions of the rectangles).

lsquadratic in optional default=0

If the method requires interpolation, this is passed on to interpol, to select 4 point quadratic interpolation.

If none of lsquadratic, quadratic and spline are set, interpolation is linear.

quadratic in optional default=0

If the method requires interpolation, this is passed on to interpol, to select 3 point quadratic interpolation.

If none of lsquadratic, quadratic and spline are set, interpolation is linear.

spline in optional default=0

If the method requires interpolation, this is passed on to interpol, to select spline interpolation.

If none of lsquadratic, quadratic and spline are set, interpolation is linear.

Examples

Make up a simple constant function to show the difference between local and non-local modes:

x=[0d0,1d0] y=[2d0,2d0] print,pp_integral(x,y,xmin=xmin,xmax=xmax) ;4.0000000 print,xmin,xmax ;-0.50000000 1.5000000 ;(the x locations are considered the middle of the bins, so the bins extend beyond the range min(x),max(x)) print,pp_integral(x,y,xmin=lxmin,xmax=lxmax,/local) ;2.0000000 print,lxmin,lxmax ;0.0000000 1.0000000
Make up a well sampled function, so that the difference between local and non-local is small:
x=dindgen(10001)*!dpi/1d4 y=sin(x) a=pp_integral(x,y,xmin=[0d0,0d0],xmax=!dpi*[0.5d0,1d0]) b=pp_integral(x,y,xmin=[0d0,0d0],xmax=!dpi*[0.5d0,1d0],/local) print,a ;1.0003142 2.0000000 print,b ;1.0000000 2.0000000 print,a-b ;0.00031410992 -4.9348009e-08

Author information

Author:

Paulo Penteado (pp.penteado@gmail.com), Feb/2010

Statistics

Lines:
73 lines
Cyclomatic complexity:
23
Modified cyclomatic complexity:
23

File attributes

Modification date: Wed Jun 29 22:15:28 2016
Lines: 73
Docformat: rst rst