Double Integral in MATLAB
Last Updated :
08 Mar, 2022
The double integral of a non-negative function f(x, y) defined on a region in the plane tells us about the volume of the region under the graph. The double integral of a function of two variables, f(x, y) over the region R can be expressed as follows :
\int \int_{R}^{} f(x,y)dA = \int \int_{R}^{} f(x,y)dx dy
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)
Syntax:
integral2(fun,xmin,xmax,ymin,ymax)
This function approximates the integral of any function f = fun(x,y) in the region xmin ≤ x ≤ xmax and ymin(x) ≤ y ≤ ymax(x)
Example 1:
Matlab
% MATLAB Code to
% Create a function in x and y
% Function : y*sin(x) + x*cos(y)
f = @(x,y) y.*sin(x)+x.*cos(y);
disp("f(x,y) :");
disp(f);
% Double Integral of f(x)
% over pi≤x≤2*pi and 0≤y≤pi
d = integral2(f,pi,2*pi,0,pi);
disp("Double Integral of f(x) :");
disp(d);
Output :

Example 2:
Matlab
% MATLAB Code to
% Create a function in x and y
% Function : y*sin(x) + x*cos(y)
f = @(x,y) y.*sin(x)+x.*cos(y);
disp("f(x,y) :");
disp(f);
% Double Integral of f(x)
% over pi≤x≤2*pi and 0≤y≤x
ymax = @(x) x;
d = integral2(f,pi,2*pi,0,ymax);
disp("Double Integral of f(x) :");
disp(d);
Output :

Syntax:
F = integral2(fun,xmin,xmax,ymin,ymax,Name,Value)
It specifies additional options with one or more Name, Value pair arguments. The most popular Name used is 'Method'
The Possible values are:
- tiled: The limits for the integration must be finite for this method to work. It subdivides the integration zone into simpler rectangular areas if needed after transforming it to a rectangular shape.
- iterated: In this method, iterated integration is applied. It is the process of repeatedly integrating the results of the previous integrations when the function consists of more than one variable. In the function. In this method, the integration limits can be infinite.
- auto: The 'auto' method is used as the default value. It chooses tiled or iterated based on the limits chosen. If limits are infinite then it chooses 'iterated' otherwise it calculates using the 'tiled' method.
Example 3:
Matlab
% MATLAB Code to
% Create a function in x and y
% Function : y*sin(x) + x*cos(y)
f = @(x,y) y.*sin(x)+x.*cos(y);
disp("f(x,y) :");
disp(f);
% Double Integral of f(x) using Tiled Method
% over pi≤x≤2*pi and 0≤y≤pi
d = integral2(f,pi,2*pi,0,pi,'Method','Tiled');
disp("Double Integral of f(x) :");
disp(d);
Output :

Example 4:
Matlab
% MATLAB code for iterated
% Create a function in x and y
% Function : x*y*e^-(x+y)
f = @(x,y) y.*x.*exp(-(x+y))
disp("f(x,y) :");
disp(f);
% Double Integral of f(x) using Iterated method
% over 0≤x≤Inf and 0≤y≤Inf
d = integral2(f,0,Inf,0,Inf,'Method','Iterated');
disp("Double Integral of f(x) :");
disp(d);
Output:
Similar Reads
Double Integral Double integral is a mathematical tool for computing the integral of a function of two variables across a two-dimensional region on the xy plane. It expands the concept of a single integral by integrating the functions of two variables over regions, surfaces, or areas in the plane. In case two varia
9 min read
Integration in MATLAB Integration is defined as the process of finding the anti derivative of a function. It is used to calculate area, volume, displacement, and many more. In this article, we will see how to perform integration on expressions in MATLAB. There are two types of Integration: Indefinite integral: Let f(x) b
3 min read
2D Line Plot in MATLAB '2D' stands for 2-dimensional and a 2D line is a line that is moved in 2-dimensions. A line in 2D means that we could move in forward and backward direction but also in any direction like left, right, up, down. In MATLAB we have a function named plot() which allows us to plot a line in 2 directions.
4 min read
2D Array Interpolation in MATLAB In this article, we are going to discuss "2D Array Interpolation" in MATLAB with the help of two linspace() and interp2() functions. Functions Usedlinspace( ) The linspace() function is used for the generation linearly spaced vector. Syntax: linspace(a, b) linspace(a, b, n) Here, linspace(a, b) is
4 min read
M - Files in MATLAB MATLAB provides a feature to store a sequence of statements in a file and execute these statements at the MATLAB prompt exactly as if have typed each command sequentially. Such files are called M-files or script files because they contain file extensions as '.m'. M-files are basically text files whe
3 min read
Local Functions in MATLAB Functions in any programming language are some blocks of code, which could be reused whenever required, by just calling the name. It reduces so much of human effort and also rewriting of the same code, and makes the entire code big. Declaring a function:Before moving forward let's see how actually t
2 min read