Numerically evaluate double integral - MATLAB integral2 (2024)

Numerically evaluate double integral

collapse all in page

Syntax

q = integral2(fun,xmin,xmax,ymin,ymax)

q = integral2(fun,xmin,xmax,ymin,ymax,Name,Value)

Description

example

q = integral2(fun,xmin,xmax,ymin,ymax) approximatesthe integral of the function z = fun(x,y) overthe planar region xminxxmax and ymin(x)yymax(x).

example

q = integral2(fun,xmin,xmax,ymin,ymax,Name,Value) specifiesadditional options with one or more Name,Value pairarguments.

Examples

collapse all

Integrate Triangular Region with Singularity at the Boundary

Open Live Script

Consider the function

f(x,y)=1(x+y)(1+x+y)2.

This function is undefined when x and y are zero. integral2 performs best when singularities are on the integration boundary.

Create the anonymous function.

fun = @(x,y) 1./( sqrt(x + y) .* (1 + x + y).^2 )
fun = function_handle with value: @(x,y)1./(sqrt(x+y).*(1+x+y).^2)

Integrate over the triangular region bounded by 0x1 and 0y1-x.

ymax = @(x) 1 - x;q = integral2(fun,0,1,0,ymax)
q = 0.2854

Evaluate Double Integral in Polar Coordinates

Define the function

f(θ,r)=rrcosθ+rsinθ(1+rcosθ+rsinθ)2

fun = @(x,y) 1./( sqrt(x + y) .* (1 + x + y).^2 );polarfun = @(theta,r) fun(r.*cos(theta),r.*sin(theta)).*r;

Define a function for the upper limit of r.

rmax = @(theta) 1./(sin(theta) + cos(theta));

Integrate over the region bounded by 0θπ/2 and 0rrmax.

q = integral2(polarfun,0,pi/2,0,rmax)
q = 0.2854

Evaluate Double Integral of Parameterized Function with Specific Method and Error Tolerance

Open Live Script

Create the anonymous parameterized function f(x,y)=ax2+by2 with parameters a=3 and b=5.

a = 3; b = 5;fun = @(x,y) a*x.^2 + b*y.^2;

Evaluate the integral over the region 0x5 and -5y0. Specify the 'iterated' method and approximately 10 significant digits of accuracy.

format longq = integral2(fun,0,5,-5,0,'Method','iterated',...'AbsTol',0,'RelTol',1e-10)
q = 1.666666666666667e+03

Input Arguments

collapse all

funIntegrand
function handle

Integrand, specified as a function handle, defines the functionto be integrated over the planar region xminxxmax and ymin(x)≤yymax(x).The function fun must accept two arrays of thesame size and return an array of corresponding values. It must performelement-wise operations.

Data Types: function_handle

xminLower limit of x
real number

Lower limit of x, specified as a real scalarvalue that is either finite or infinite.

Data Types: double | single

xmaxUpper limit of x
real number

Upper limit of x, specified as a real scalarvalue that is either finite or infinite.

Data Types: double | single

yminLower limit of y
real number | function handle

Lower limit of y, specified as a real scalarvalue that is either finite or infinite. You can specify ymin tobe a function handle (a function of x) when integratingover a nonrectangular region.

Data Types: double | function_handle | single

ymaxUpper limit of y
real number | function handle

Upper limit of y, specified as a real scalarvalue that is either finite or infinite. You also can specify ymax tobe a function handle (a function of x) when integratingover a nonrectangular region.

Data Types: double | function_handle | single

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'AbsTol',1e-12 sets the absoluteerror tolerance to approximately 12 decimal places of accuracy.

AbsTolAbsolute error tolerance
nonnegative real number

Absolute error tolerance, specified as the comma-separated pairconsisting of 'AbsTol' and a nonnegative real number. integral2 usesthe absolute error tolerance to limit an estimate of the absoluteerror, |qQ|, where q isthe computed value of the integral and Q is the(unknown) exact value. integral2 might providemore decimal places of precision if you decrease the absolute errortolerance. The default value is 1e-10.

Note

AbsTol and RelTol worktogether. integral2 might satisfy the absoluteerror tolerance or the relative error tolerance, but not necessarilyboth. For more information on using these tolerances, see the Tips section.

Example: 'AbsTol',1e-12 sets the absoluteerror tolerance to approximately 12 decimal places of accuracy.

Data Types: double | single

RelTolRelative error tolerance
nonnegative real number

Relative error tolerance, specified as the comma-separated pairconsisting of 'RelTol' and a nonnegative real number. integral2 usesthe relative error tolerance to limit an estimate of the relativeerror, |qQ|/|Q|,where q is the computed value of the integral and Q isthe (unknown) exact value. integral2 might providemore significant digits of precision if you decrease the relativeerror tolerance. The default value is 1e-6.

Note

RelTol and AbsTol worktogether. integral2 might satisfy the relativeerror tolerance or the absolute error tolerance, but not necessarilyboth. For more information on using these tolerances, see the Tips section.

Example: 'RelTol',1e-9 sets the relative errortolerance to approximately 9 significant digits.

Data Types: double | single

MethodIntegration method
'auto' (default) | 'tiled' | 'iterated'

Integration method, specified as the comma-separated pair consistingof 'Method' and one of the methods described below.

Integration MethodDescription
'auto'For most cases, integral2 uses the 'tiled' method.It uses the 'iterated' method when any of the integrationlimits are infinite. This is the default method.
'tiled'integral2 transforms the region of integrationto a rectangular shape and subdivides it into smaller rectangularregions as needed. The integration limits must be finite.
'iterated'integral2 calls integral toperform an iterated integral. The outer integral is evaluated over xminxxmax. The inner integral is evaluatedover ymin(x)yymax(x).The integration limits can be infinite.

Example: 'Method','tiled' specifies the tiledintegration method.

Data Types: char | string

Tips

  • The integral2 function attemptsto satisfy:

    abs(q - Q) <= max(AbsTol,RelTol*abs(q))
    where q isthe computed value of the integral and Q is the(unknown) exact value. The absolute and relative tolerances providea way of trading off accuracy and computation time. Usually, the relativetolerance determines the accuracy of the integration. However if abs(q) issufficiently small, the absolute tolerance determines the accuracyof the integration. You should generally specify both absolute andrelative tolerances together.
  • The 'iterated' method can be moreeffective when your function has discontinuities within the integrationregion. However, the best performance and accuracy occurs when yousplit the integral at the points of discontinuity and sum the resultsof multiple integrations.

  • When integrating over nonrectangular regions, thebest performance and accuracy occurs when ymin, ymax,(or both) are function handles. Avoid setting integrand function valuesto zero to integrate over a nonrectangular region. If you must dothis, specify 'iterated' method.

  • Use the 'iterated' method when ymin, ymax,(or both) are unbounded functions.

  • When parameterizing anonymous functions, be aware that parameter values persist for the life of the function handle. For example, the function fun = @(x,y) x + y + a uses the value of a at the time fun was created. If you later decide to change the value of a, you must redefine the anonymous function with the new value.

  • If you are specifying single-precision limits of integration,or if fun returns single-precision results, youmight need to specify larger absolute and relative error tolerances.

References

[1] L.F. Shampine “VectorizedAdaptive Quadrature in MATLAB®,” Journalof Computational and Applied Mathematics, 211, 2008, pp.131–140.

[2] L.F. Shampine, "MATLAB Programfor Quadrature in 2D." Applied Mathematicsand Computation. Vol. 202, Issue 1, 2008, pp. 266–274.

Extended Capabilities

Version History

Introduced in R2012a

See Also

integral | integral3 | trapz

Topics

  • Singularity on Interior of Integration Domain
  • Parameterizing Functions
  • Create Function Handle

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Numerically evaluate double integral - MATLAB integral2 (1)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Numerically evaluate double integral - MATLAB integral2 (2024)

FAQs

How to calculate double integral in MATLAB? ›

MATLAB allows users to calculate the double integral of a function using the integral2() method. Different syntax of integral2() method are: F = integral2(fun,xmin,xmax,ymin,ymax) F = integral2(fun,xmin,xmax,ymin,ymax,Name,Value)

How to use dblquad in MATLAB? ›

q = dblquad(fun,xmin,xmax,ymin,ymax) calls the quad function to evaluate the double integral fun(x,y) over the rectangle xmin <= x <= xmax , ymin <= y <= ymax . The input argument, fun , is a function handle that accepts a vector x , a scalar y , and returns a vector of integrand values.

How to calculate the integral in MATLAB? ›

F = int( expr , a , b ) computes the definite integral of expr from a to b . int uses the default integration variable determined by symvar ( expr,1 ). If expr is a constant, then the default integration variable is x .

What is the interpretation of double integral? ›

Double integral is mainly used to find the surface area of a 2d figure, and it is denoted using ' ∫∫'. We can easily find the area of a rectangular region by double integration. If we know simple integration, then it will be easy to solve double integration problems.

How to solve a double integral numerically? ›

To solve numerical double integral the multiple-segment trapezoidal or Simpson's rule would be applied in the first dimension with each value of the second dimension held constant. Then the method would be applied to integrate the second dimension.

How do you evaluate a double integral? ›

Evaluate a double integral by computing an iterated integral over a region bounded by two vertical lines and two functions of x, or two horizontal lines and two functions of y. Simplify the calculation of an iterated integral by changing the order of integration.

How to use double precision in MATLAB? ›

d = double( s ) converts the symbolic values s to double precision. Converting symbolic values to double precision is useful when a MATLAB® function does not accept symbolic values. For differences between symbolic and double-precision numbers, see Choose Numeric or Symbolic Arithmetic.

What is DBLquad? ›

dblquad() method, we can get the double integration of a given function from limit a to b by using scipy. integrate. dblquad() method. Syntax : scipy.integrate.dblquad(func, a, b) Return : Return the double integrated value of a polynomial.

How to use Laplacian in MATLAB? ›

l = laplacian( f , v ) returns the Laplacian of the symbolic field f with respect to the vector v in Cartesian coordinates. If f is an array, then the function computes the Laplacian for each element of f and returns the output l that is the same size as f .

Can MATLAB evaluate integrals? ›

Description. release( expr ) evaluates the integrals in the expression expr . The release function ignores the 'Hold' option in the int function when the integrals are defined.

How does vpa work in MATLAB? ›

vpa Uses Guard Digits to Maintain Precision

The value of the digits function specifies the minimum number of significant digits used. Internally, vpa can use more digits than digits specifies. These additional digits are called guard digits because they guard against round-off errors in subsequent calculations.

How do you estimate the value of an integral? ›

The most commonly used techniques for numerical integration are the midpoint rule, trapezoidal rule, and Simpson's rule. The midpoint rule approximates the definite integral using rectangular regions whereas the trapezoidal rule approximates the definite integral using trapezoidal approximations.

How do you find the value of a double integral? ›

How do you calculate double integrals? To calculate double integrals, use the general form of double integration which is ∫ ∫ f(x,y) dx dy, where f(x,y) is the function being integrated and x and y are the variables of integration.

What is the rule for double integral? ›

A double integral is an integral of a two-variable function f (x, y) over a region R. If R = [a, b] × [c, d], then the double integral can be done by iterated integration (integrate first with respect to y, and then integrate with respect to x).

What do double integrals give you? ›

Double integrals are a way to integrate over a two-dimensional area. Among other things, they lets us compute the volume under a surface.

How do you make a double an integer in MATLAB? ›

Float and double data can be changed to integer using int32 and int64 depending on how large the float/double number is.
  1. Ex: If X is the number to be converted, then X can be converted to integer in this way :
  2. X = int32(X) or X= int64(X)
  3. (X is converted to integer and then the converted integer is stored back in X)
Jun 27, 2022

What is the formula for double integration method? ›

The general form of a double integral is ∫ a b ∫ c d f ( x , y ) d x d y . Double integrals are read from inside to outside, and the first integration that must occur is the innermost integral. In the expression above, the innermost integral is ∫ c d f ( x , y ) d x , and the first integration is taken over x.

How do you find the double derivative in MATLAB? ›

If you use nested diff calls and do not specify the differentiation variable, diff determines the differentiation variable for each call. For example, find the second derivative of the expression x*y by calling the diff function twice. In the first call, diff differentiates x*y with respect to x and returns y .

References

Top Articles
Latest Posts
Article information

Author: Stevie Stamm

Last Updated:

Views: 5942

Rating: 5 / 5 (60 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Stevie Stamm

Birthday: 1996-06-22

Address: Apt. 419 4200 Sipes Estate, East Delmerview, WY 05617

Phone: +342332224300

Job: Future Advertising Analyst

Hobby: Leather crafting, Puzzles, Leather crafting, scrapbook, Urban exploration, Cabaret, Skateboarding

Introduction: My name is Stevie Stamm, I am a colorful, sparkling, splendid, vast, open, hilarious, tender person who loves writing and wants to share my knowledge and understanding with you.