## Introduction to Matlab Integral

Matlab Integral is useful in finding areas under the curves. It is the reverse of differentiation in calculus and hence the functions are integrated by finding their anti-derivatives.

**Integrals are of 2 types:**

1. Indefinite integrals (Integrals without limits)

2. Definite integrals (Integrals with limits)

### Syntax

Let us now understand the syntax of ‘integral function’ in MATLAB:

`A = integral (Fx, Xminimum, Xmaximum)`

**Explanation:**

1. ‘integral function’ will calculate the numeric integration of input function ‘Fx’

2. ‘Xminimum’ and ‘Xmaximum’ will be used as a minimum and maximum limits for integration respectively

3. If we want to use more specific options for integral, we can use the syntax:

`A = integral (Fx, Xminimum, Xmaximum, Name, Value)`

### Examples to Implement Matlab Integral

Let us now understand how the code for ‘integral function’ looks like in MATLAB with the help of various examples:

3 Online Courses | 1 Hands-on Project| 8+ Hours| Verifiable Certificate of Completion

4.5

View Course

#### Example #1

In this example, we will use a simple polynomial function of degree 2 and will integrate it between the limits 0 to 4. We will follow the following 2 steps:

Step 1: Create the function of degree 2 in MATLAB

Step 2: Use the integral function to calculate the integration

**Code:**

`syms x`

[Initializing the variable ‘x’]
Fx = @(x) 4*x.^2

[Creating the polynomial function of degree 2]
A = integral (Fx, 0, 4)

[Passing input function ‘Fx’ and the required limits to the ‘integral function’]
[Mathematically, the integral of 4*x ^ 2, between the limits 0 to 4 is 85.3333]

**Output:**

**Explanation: **As we can see in the output, we have obtained integral of our input function ‘Fx’ as 85.3333 using ‘integral function’, which is the same as expected by us.

#### Example #2

In this example, we will use a polynomial function of degree 4 and will integrate it between the limits 0 to 2. We will follow the following 2 steps:

Step 1: Create the function of degree 4 in MATLAB

Step 2: Use the integral function to calculate the integration

**Code:**

`syms x`

[Initializing the variable ‘x’]
Fx = @ (x) (4 * x.^4 + x.^3 -2 * x.^2 +1)

[Creating the polynomial function of degree 4]
A = integral (Fx, 0, 2)

[Passing input function ‘Fx’ and the required limits to the ‘integral function’]
[Mathematically, the integral of 4 * x. ^ 4 + x. ^ 3 -2 * x. ^ 2 +1, between the limits 0 to 2 is 26.2667]

**Output:**

**Explanation:** As we can see in the output, we have obtained integral of our input function ‘Fx’ as 26.2667 using ‘integral function’, which is the same as expected by us.

#### Example #3

In this example, we will learn how to integrate a function between the limits 0 and infinity. For this example, we will use a function which is a combination of logarithmic and exponential functions. The code will comprise of the following 2 steps:

Step 1: Create a function containing logarithmic and exponential functions

Step 2: Use the integral function to calculate the integration

**Code:**

`syms x`

[Initializing the variable ‘x’]
Fx = @(x) exp(-x. ^3). * log(2 * x). ^3;

[Creating the function containing the exponential and logarithmic functions]
A = integral (Fx, 0, inf)

[Passing input function ‘Fx’ and the required limits to the ‘integral function’. Note that we have passed ‘inf’ which signifies infinity, as the upper limit]
[Mathematically, the integral of exp (-x. ^3). * log (2 * x). ^3, between the limits 0 to infinity is -2.9160]

**Output:**

**Explanation:** As we can see in the output, we have obtained integral of our input function ‘Fx’ as -2.9160 using ‘integral function’, which is the same as expected by us.

#### Example #4

In this example, we will learn how to use the syntax A = integral (Fx, Xminimum, Xmaximum, Name, Value)

For this example, we will use a vector function which is of the form [log(x) log(2x) log (3x) log (4x)]. The code will comprise of the following 2 steps:

Step 1: Create a function containing vector values

Step 2: Use the integral function to calculate the integration and add a ‘name-value pair’ argument

**Code:**

`syms x`

[Initializing the variable ‘x’]
Fx = @(x) log((1 : 4) * x);

[Creating the function containing vector values]
A = integral(Fx, 0, 2, 'ArrayValued', true)

[Passing input function ‘Fx’ and the required limits to the ‘integral function’. Note that we have passed ‘ArrayValued’, ‘true’, as the name value pair; which is used to calculate the integral of vector values]

**Output:**

**Explanation: **As we can see in the output, we have obtained integral of all the vector values in our array using integral function and ‘name-value pair’ argument.

### Conclusion

‘integral function’ can be used in MATLAB to calculate the integration of any function. We can set the desired limits on the integration using the arguments of the integral function. It is also possible to apply specific conditions using ‘name-value pair’ arguments.

### Recommended Articles

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