NCL Home > Documentation > Functions > General applied math


Integrate a sequence of equally spaced points using Simpson's Rule.


	function simpeq (
		fi     : numeric,  
		dx [1] : numeric   

	return_val  :  float or double



An array of one or more dimensions. Missing values are not allowed. The rightmost dimension is the dimension to be interpolated. This may array reordering (reshaping)


A constant representing the interval between points.

Return value

The return value will have same dimensions as all but the rightmost dimension of fi (or be a scalar if fi is one-dimensional). The return type will be double if fi is double, and float otherwise.


This function performs the Classic Simpson's three-point formula for integration. The number of points may be odd or even. Missing values are not allowed.

The finer the dx (ie, the more points) the more accurate the result.

See Also

ftcurvi, simpne, wgt_vertical_n


The finer the dx (ie, the more points) the more accurate the result.

Example 1: Evaluate exp(x) from x=1.8 to x=3.4. Use an odd an even number of points.

   x  = fspan(1.8, 3.4, 8)          ; generate 8 equally spaced values
   dx = x(1)-x(0)
   y  = exp(x)
   simpeq_8 = funcref>simpeq(y,dx)  ; = 23.9175 

   X  = fspan(1.8, 3.4, 9)          ; generate 9 equally spaced values
   DX = x(1)-x(0)
   Y  = exp(X)
   simpeq_9 = simpeq(Y,DX)          ; = 23.9147 

The use of a function (here, exp) is for convenience. The fi (here, y) could be from a table or series of equally spaced values.

Example 2: Assume f is dimensioned nloc x ntim. For each location, integrate over time:

  dt     = 3.5
  result = simpeq(f,dt)         ; result(nloc)

Example 3: Assume f is dimensioned ntim x klev x nlat x mlon with named dimensions "time", "lev", "lat", and "lon". Integrate over time. This requires that the variable be reshaped (reordered) so that 'time' is the rightmost dimension.

  dt = 1.0
  result  = simpeq(f(lev|:,lat|:,lon|:,time|:),dt)    ; result(klev,nlat,mlon)