Double Integral in MATLAB (original) (raw)

Last Updated : 8 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:

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 : ysin(x) + xcos(y) f = @(x,y) y.*sin(x)+x.*cos(y); disp("f(x,y) :"); disp(f);

% Double Integral of f(x) % over pi≤x≤2pi and 0≤y≤pi d = integral2(f,pi,2pi,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 : ysin(x) + xcos(y) f = @(x,y) y.*sin(x)+x.*cos(y); disp("f(x,y) :"); disp(f);

% Double Integral of f(x) % over pi≤x≤2pi and 0≤y≤x ymax = @(x) x; d = integral2(f,pi,2pi,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:

Example 3:

Matlab `

% MATLAB Code to % Create a function in x and y % Function : ysin(x) + xcos(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≤2pi and 0≤y≤pi d = integral2(f,pi,2pi,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 : xye^-(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: