## Introduction to Matlab Double Integral

Matlab Double Integral is the extension of the definite integral. In double integral, the integration is performed for functions with 2 variables. In its simplest form, integration for functions with 1 variable is done over a 1-Dimensional space, likewise, integration of functions with 2 variables is done over a 2-D space. In MATLAB, we use ‘integral2 function’ to get the double integration of a function.

**Syntax**

Let us now understand the syntax of integral2 function in MATLAB:

`I = integral2 (Func, minX, maxX, minY, maxY)`

I = integral2 (Func, minX, maxX, minY, maxX, Name, Value)

**Explanation:**

I = integral2 (Func, minX, maxX, minY, maxY) will integrate the function ‘Func’ (here ‘Func’ is a function of 2 variables X and Y) over the region minX ≤ X ≤ maxX and minY ≤ Y ≤ maxY

I = integral2 (Func, minX, maxX, minY, maxX, Name, Value) can be used to pass more options to the integral2 function. These options are passed as paired arguments

### Examples to Implement Matlab Double Integral

Let us now understand the code to calculate the double integral in MATLAB using ‘integral2 function’.

4.5 (6,332 ratings)

View Course

#### Example #1

In this example, we will take a function of cos with 2 variables ‘x’ and ‘y’. We will follow the following 2 steps:

Step 1: Create a function of x and y

Step 2: Pass the function and required limits to the integral2 function

**Code:**

`Func = @ (x,y) (x + cos (y) + 1)`

[Creating the cos function in ‘x’ and ‘y’]
I = integral2 (Func, 0, 1, 0, 2)

[Calling the integral2 function and passing the desired limits as 0 <= x <= 1; 0 <= y <= 2)]
[Mathematically, the double integral of x + cos (y) + 1 is 3.9093]

**Output:**

**Explanation:** As we can see in the output, we have obtained double integral of our input function as 3.9093, which is the same as expected by us.

#### Example #2

In this example, we will take a function of sin with 2 variables ‘x’ and ‘y’. We will follow the following 2 steps:

Step 1: Create a sin function of x and y

Step 2: Pass the function and required limits to the integral2 function

**Code:**

`Func = @(x,y) (sin(y) + x.^3 + 2)`

[Creating the sin function in ‘x’ and ‘y’]
I = integral2 (Func, 0, 1, 0, 2)

[Calling the integral function and passing the desired limits as 0 <= x <= 1; 0 <= y <= 2)]
[Mathematically, the double integral of sin(y) + x.^3 + 2 is 5.9161]

**Output:**

**Explanation: **As we can see in the output, we have obtained double integral of our input function as 5.9161, which is the same as expected by us.

#### Example #3

In this example, we will take a polynomial function of x and y. We will follow the following 2 steps:

Step 1: Create a polynomial function of x and y

Step 2: Pass the function and required limits to the integral2 function

**Code:**

`Func = @(x,y) (35*y.^3 - 15*x)`

[Creating the polynomial function in ‘x’ and ‘y’]
I = integral2 (Func, 0, 1, 0, 2)

[Calling the integral function and passing the desired limits as 0 <= x <= 1; 0 <= y <= 2)]
[Mathematically, the double integral of 35*y.^3 - 15*x is 125]

**Output:**

**Explanation: **As we can see in the output, we have obtained double integral of our input function as 125, which is the same as expected by us.

#### Example #4

In this example, we will take a polynomial function of x and y and of degree 3. We will follow the following 2 steps:

Step 1: Create a polynomial function of x and y and degree 3

Step 2: Pass the function and required limits to the integral2 function

**Code:**

`Func = @(x,y) ((20*y.^3) + 3*x.^2)`

[Creating the polynomial function in ‘x’ and ‘y’]
I = integral2 (Func, 0, 1, 0, 2)

[Calling the integral function and passing the desired limits as 0 <= x <= 1; 0 <= y <= 2)]
[Mathematically, the double integral of (20*y.^3) + 3*x.^2 is 82]

**Output:**

**Explanation: **As we can see in the output, we have obtained double integral of our input function as 82, which is the same as expected by us.

#### Example #5

In this example, we will take a polynomial function with the division. We will follow the following 2 steps:

Step 1: Create a polynomial function of x and y and with division

Step 2: Pass the function and required limits to the integral2 function

**Code:**

`Func = @(x,y) 1./(sqrt(x.^3 + y.^2))`

[Creating the polynomial function in ‘x’ and ‘y’ and division]
I = integral2 (Func, 0, 1, 0, 2)

[Calling the integral function and passing the desired limits as 0 <= x <= 1; 0 <= y <= 2)]
[Mathematically, the double integral of 1./(sqrt(x.^3 + y.^2)) is 2.9012]

**Output:**

**Explanation: **As we can see in the output, we have obtained double integral of our input function as 2.9012, which is the same as expected by us.

### Conclusion

Integral2 function can be used in MATLAB to get the double integral of a function. Double integral is used to integrate the function of 2 variables over a 2-D region specified by the limits.

### Recommended Articles

This is a guide to Matlab Double Integral. Here we discuss an introduction to Matlab Double Integral, syntax, examples. You can also go through our other related articles to learn more –