Integration is one of the fundamental tasks in mathematics utilized to compute the area under the curve, the volume of solids, and other quantities. Integration can be of multiple types, such as single integral and double integral. A single integral is utilized for calculating the area under the curve in a single dimension while we perform a double integral to calculate the area under the curve in two dimensions. The major advantage of using the double integral over the single integral is the ability to solve more complex problems.
Read this guide to find out how you can solve double integral in MATLAB.
What are Double Integrals?
Double integrals are used in mathematics and engineering to calculate the region’s volume in the graph. The double integral of the function f(x,y) over the region R can be defined as:
Where dA is the area element (a small area associated with the point (x,y)). We can evaluate double integral by dividing the region R into many thin slices and then adding up the volume of these slices.
How to Solve Double Integrals in MATLAB?
The integral2() is a built-in function in MATLAB that allows you to solve double integrals. This function numerically estimates the double integrals of the function f(x,y) over the given region R. This function accepts the function f and the points of the region R as arguments and approximates the value of a double integral.
Syntax
In MATLAB, the integral2() has different syntaxes as given below:
q = integral2(fun,xmin,xmax,ymin,ymax,Name,Value)
Description
Here:
The function q = integral2(fun,xmin,xmax,ymin,ymax) approximates the double integral of the given function fun over the region xmin<=x<=xmax and ymin<=y<=ymax.
The function q = integral2(fun,xmin,xmax,ymin,ymax,Name,Value) estimates the double integrals by specifying the additional options Name and Value.
The available options are:
-
- Method: It specifies the method used to estimate the integral and it could be the default method tiled, or other methods such as iterated.
- AbsTol: It specifies the absolute tolerance for the error. The default value is 1e-6.
- RelTol: It specifies the relative tolerance for the error. The default value is 1e-6.
Examples
Consider some examples to understand how to solve double integrals in MATLAB using the integral2() function.
Example 1: How to Solve Double Integral Utilizing the integral2() Function?
In this MATLAB code, we first declare a function named fun. After that, we approximate the double integral of the given function over the specified region R using the integral2() function.
ymax = @(x) sqrt(1 + x);
q = integral2(fun,-1,1,0,ymax)
Example 2: How to Solve Double Integral Using the Iterated Method?
This MATLAB code first defines a function fun with two variables x and y. After that, it uses the integral2() function to estimate the double integral of the given function using the iterated method.
q = integral2(fun,-pi ,pi, -pi/2,pi/2,'Method','iterated')
Conclusion
Double integrals are important concepts used in mathematics and engineering. These integrals allow us to compute the volume of the function in the form f(x,y) over the region R in the plane. MATLAB provides a built-in integral2() function that numerically estimates the double integral over the region R. This guide has discussed what double integral is and how to solve it in MATLAB using the integral2() function.