Mercurial > hg > octave-nkf
diff scripts/general/trapz.m @ 12612:16cca721117b stable
doc: Update all documentation for chapter on Numerical Integration
* cumtrapz.m, dblquad.m, quadgk.m, quadl.m, quadv.m, trapz.m,
triplequad.m, quad.cc, quadcc.cc: Improve docstrings.
* Quad-opts.in: Keep code sample together on a single line.
* mk-opts.pl: Update quad-options function description
* octave.texi: Update order of detailmenu to match order in quad.texi.
* quad.txi: Add language about when to use each quad function,
add examples of using trapz.
* aspell-octave.en.pws: Add new spelling words from quad.texi chapter
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 17 Apr 2011 19:57:07 -0700 |
parents | c792872f8942 |
children | f96b9b9f141b |
line wrap: on
line diff
--- a/scripts/general/trapz.m +++ b/scripts/general/trapz.m @@ -17,15 +17,38 @@ ## <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {@var{z} =} trapz (@var{y}) -## @deftypefnx {Function File} {@var{z} =} trapz (@var{x}, @var{y}) -## @deftypefnx {Function File} {@var{z} =} trapz (@dots{}, @var{dim}) +## @deftypefn {Function File} {@var{q} =} trapz (@var{y}) +## @deftypefnx {Function File} {@var{q} =} trapz (@var{x}, @var{y}) +## @deftypefnx {Function File} {@var{q} =} trapz (@dots{}, @var{dim}) +## +## Numerically evaluate the integral of points @var{y} using the trapezoidal +## method. +## @w{@code{trapz (@var{y})}} computes the integral of @var{y} along the first +## non-singleton dimension. When the argument @var{x} is omitted an +## equally spaced @var{x} vector with unit spacing (1) is assumed. +## @code{trapz (@var{x}, @var{y})} evaluates the integral with respect +## to the spacing in @var{x} and the values in @var{y}. This is useful if +## the points in @var{y} have been sampled unevenly. +## If the optional @var{dim} argument is given, operate along this dimension. ## -## Numerical integration using trapezoidal method. @code{trapz -## (@var{y})} computes the integral of the @var{y} along the first -## non-singleton dimension. If the argument @var{x} is omitted a -## equally spaced vector is assumed. @code{trapz (@var{x}, @var{y})} -## evaluates the integral with respect to @var{x}. +## If @var{x} is not specified then unit spacing will be used. To scale +## the integral to the correct value you must multiply by the actual spacing +## value (deltaX). As an example, the integral of @math{x^3} over the range +## [0, 1] is @math{x^4/4} or 0.25. The following code uses @code{trapz} to +## calculate the integral in three different ways. +## +## @example +## @group +## x = 0:0.1:1; +## y = x.^3; +## q = trapz (y) +## @result{} q = 2.525 # No scaling +## q * 0.1 +## @result{} q = 0.2525 # Approximation to integral by scaling +## trapz (x, y) +## @result{} q = 0.2525 # Same result by specifying @var{x} +## @end group +## @end example ## ## @seealso{cumtrapz} ## @end deftypefn