tintegrate: Numerically integrate one column with respect to another.

Package: nttools

Usage

tintegrate table integrand independent

Description

The program evaluates the integral of the column name passed to 'integrand' with respect to the column passed to 'independent' using the simple trapezoidal rule. The column passed to 'independent' must have values sorted in ascending order. INDEF values in either column are ignored, and there must be at least two good points common to both columns. The result is written to STDOUT and also recorded as a task parameter 'integral'.

If the 'independent' parameter is null or blank, the values in the 'integrand' column will simply be added up. Note that this is not exactly the same as the trapezoidal rule for integrating over row number. (A row number column can be created using 'tcalc'.) When integrating over a column that contains the row numbers, 'tintegrate' adds together all rows except the first and last with unit weight; the first and last are included with a weight of one half.

Parameters

table [file name]
The input table.
integrand [string]
Column name whose contents will be the integrand.
independent [string]
Column name whose contents will be the independent variable; the values in this column must be increasing with row number. If 'independent' is null, then 'tintegrate' will just sum the values in the 'integrand' column.
(integral) [real]
The result returned by the task. This is an output parameter; it is not directly changed by the user.
(ptsused) [integer]
The number of points used in calculating the integral. This is also an output parameter and is not specified by the user.

Examples

1. Calculate the integral of flux over wavelength, printing the result to STDOUT (and also storing it in the 'integral' parameter).

tt> tintegrate intab flux lambda
       integral= 0.8752311663155779 using 401 points

2. Sum the values of flux, rather than integrating over wavelength.

tt> tintegrate intab flux ""
       integral= 30.32557976245881 using 401 points

as an alternative:

tt> tstat intab flux
# civ  flux
# nrows            mean     stddev   median       min      max
  401     0.07562488719   0.171107  -0.0381  -0.72729  0.22527
tt> =0.07562488719 * 401
30.32557976319

3. Integrate the flux over row number. This is the same as summing the flux except for the first and last rows.

tt> tcalc intab row rownum datatype="real" colfmt="%8.1f"
tt> tintegrate intab flux row
      integral= 30.34466478228569 using 401 points

Bugs

References

This task was written by David Giaretta.

See also

tcalc tstat