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) be a function. Then the family of all antiderivatives is called the indefinite integral of a function f(x) and it is denoted by ∫f(x)dx. The symbol ∫f(x)dx is read as the indefinite integral of f(x) with respect to x. Thus ∫f(x)dx= ∅(x) + C. Thus, the process of finding the indefinite integral of a function is called the integration of the function.
- Definite integrals: Definite integrals are the extension after indefinite integrals, definite integrals have limits [a, b]. It gives the area of a curve bounded between given limits. It is denoted by ∫f(x)dx under the limit of a and b, it denotes the area of curve F(x) bounded between a and b, where a is the lower limit and b is the upper limit.
Before moving to Integration, we first need to assign an expression to a variable in MATLAB which can be done by using the inline() function. It creates a function to contain the expression.
Syntax:
f = inline(expr, var)
Here f is the inline function created to contain the expression, expr can be any expression and var is the variable in that expression.
Now, after assigning the expression using the inline() function, we need to integrate the expression. This task can be performed using the int() function. The int() function is used to integrate expressions in MATLAB.
Syntax:
int(f,v)
Parameters:
Indefinite Integral
Indefinite integrals are those integrals that do not have any limit and containing an arbitrary constant.
Step-wise Approach:
Step 1: Use Inline function for the creation of the function for integration.
Matlab
f=inline( 'x^2+3*x' , 'x' );
g=inline( 'sin(y) + cos(y)^2' , 'y' );
|
Step 2: Create a symbolic function.
Step 3: Use int to find out the integration.
Matlab
p=int (f(x),x);
q=int (g(y),y);
|
Complete Code:
Matlab
f=inline( 'x^2+3*x' , 'x' );
g=inline( 'sin(y) + cos(y)^2' , 'y' );
syms x;
syms y;
p=int (f(x),x);
q=int (g(y),y);
p
q
|
Output:

Definite Integral
Definite integrals are those integrals that have an upper limit and a lower limit. Let’s take the above example and add the limits.
Step-wise Approach:
Step 1: Use the Inline function for the creation of the function for integration.
Matlab
f=inline( 'x^2+3*x' , 'x' );
g=inline( 'sin(y) + cos(y)^2' , 'y' );
|
Step 2: Create a symbolic function.
Step 3: Use int to find out the integration and pass down the values of the lower limit, upper limit.
Matlab
p=int (f(x),1,4);
q=int (g(y),1,3);
double(q);
|
Complete Code:
Matlab
f=inline( 'x^2+3*x' , 'x' );
g=inline( 'sin(y) + cos(y)^2' , 'y' );
syms x;
syms y;
p=int (f(x),1,4);
q=int (g(y),1,3);
double(q);
p
q
|
Output:
