Contents Previous Next Subchapters Current Chapters-> trapz gaussq quad2d gaussq2d gaussleg quadint int2inf ode4rk expmat ode45rk odepade odestiff Parent Chapters-> Omatrix6 integration quad2d Search Tools-> contents reference index search

Two Dimensional Integration Using Gauss-Legendre Quadrature
 Syntax `quad2d(function `fvec`, `xmin`, `xmax`, `ymin`, `ymax` ...` `       , `tol`, `trace`, `m`)` Where tol, trace and m are optional See Also dblquad , gaussq2d , quadint

Description
Computes a numerical approximation for `I` defined by ```             /xmax      g(y) = |     f(x, y) * dx             /xmin             /ymax      I    = |      g(y) * dy             /ymin ```Both the inner integral defining `g(y)` and the outer integral defining `I` are approximated using Gauss-Legendre quadrature. The arguments xmin, xmax, ymin, ymax are real or double-precision scalars and of the same type. ``` ```fvec`(`x`, `y```) ```Returns a real, double-precision or complex column vector that equals ```                                    T      [f(x(1), y), ... , f(x(n), y)] ```where `x` is a vector with the same type as xmin, `n` is the number of elements in `x`, and `y` is a scalar with the same type as ymin. ``` ```tol``` ```is a real or double-precision vector with four elements. The first element of tol specifies the relative accuracy for the integration (relative to the integral of the absolute value of the function). The second element specifies an absolute accuracy for the integration. The total allowable error is the sum of the absolute and relative error. The third (fourth) element specifies an absolute minimum for the size of a quadrature interval in the x (y) direction. Individual Quadrature interval sizes will be separately reduced until the accuracy requirement is met but will never be reduced below this value. If tol is not present, the default value ```      tol = 1d-3 * [1, 0, (xmax - xmin), (ymax - ymin)] ```is used. In addition, if the length of tol is less than 4, the default value is used for the missing elements. ``` ```trace``` ```is a logical, integer, real, double-precision or complex scalar. If it is not equal to zero, each function value `g(y)` corresponds to a single symbol plotted in the current viewport at `(y, g(y))`. If trace is not present, the default value false use used. ``` ```m``` ```is an integer scalar that is equal to an integer and that specifies the number of weights and abscissa pairs for each quadrature interval. It may also be a character row vector equal to "quad" or "quad8" which specifies 2 or 4 pairs respectively. The default value for m is 2.

Example
Suppose that ```      f(x, y) = y * sin(x) + x * cos(y)      xmin    = pi      xmax    = 2 * pi      ymin    = 0      ymax    = pi ```If follows that ```             / 2 * pi      g(y) = |   [y * sin(x) + x * cos(y)] * dx             / pi           = y * [cos(pi) - cos(2 * pi)] + (2 * pi - pi) * cos(y)           = - 2 * y + pi * cos(y)             / pi      I    = |   [- 2 * y + pi * cos(y)] * dy              / 0           = - 2 * [pi^2 / 2 - 0^2 / 2] + pi * [sin(pi) - sin(0)]           = - pi^2   ```The program below computes an approximation for the integral above. If you execute the program, O-Matrix will reply ```      -9.8691 ``` which is close to `2 * pi`. ``` clear function f(x, y) begin      return y * sin(x) + x * cos(y) end xmin  = PI xmax  = 2 * PI ymin  = 0d0 ymax  = PI tol   = 1d-3 * [1, 0, 1, 1] trace = true m     = 2 quad2d(function f, xmin, xmax, ymin, ymax, tol, trace, m) ``` Mlmode
In mlmode this function is called `dblquad`. In addition, the first argument is a character row vector called fun instead of `function `fvec. The call ```      feval(```fvec`, `x`, `y```) ```should evaluate the function where x is a vector and y is a scalar. If the file `temp.m` contains the following text ```      function f = temp(x, y)      f = y * sin(x) + x * cos(y); ``` and you enter ```      fun   = 'temp';      xmin  = pi;      xmax  = 2 * pi;      ymin  = 0;      ymax  = pi;      tol   = 1e-3 * [1, 0, 1, 1];      trace = 1;      m     = 'quad';      dblquad(fun, xmin, xmax, ymin, ymax, tol, trace, m) ``` O-Matrix will reply ```      -9.8691 ```