Matlab

How to Integrate a Function in MATLAB Using Int() Function

Integration is a mathematical operation used for finding the antiderivatives of the function and has many applications in science and engineering. We can easily integrate simple functions by ourselves, but it is very difficult to integrate them manually when dealing with very complex ones. So to integrate complex functions, MATLAB provides the built-in int() function which easily finds the integration of any complex function in a short time interval.

This article is going to teach us how to integrate a function in MATLAB using the int() function.

How to Integrate a Function in MATLAB Utilizing int() Function?

The int() function is a built-in MATLAB function that makes it easier for you to integrate a function or expression. This function takes a function or expression as an input and returns a mathematical expression as input and returns its integration.

The int() function is particularly useful for performing symbolic calculations and solving more complex mathematical problems in MATLAB.

Syntax for int() Function in MATLAB

The simple syntax for the int() function in MATLAB is given below:

int(f)

int(f,a,b)

Here:

int(f) finds the indefinite integration of the given function f with respect to a given variable. If the function is constant, then it returns a default variable x.

int(f,a,b) finds the definite integration of the given function f from a to b with respect to a given variable. If the function is constant, then it returns a default variable x.

Examples

In this section, we are going to implement the int() function to find the integration of the given functions using some examples.

Example 1

To find the indefinite integration of the given expression with respect to x, use the following code.

syms x

int(x^7)

Example 2

The following example finds the definite integration of the given trigonometric function ranging from pi/4 to pi/2 with respect to x.

syms x

int(sin(3*x), pi/4, pi/2)

Example 3

In this example, we find the indefinite integration of the given rational expression with respect to x:

syms x

int(3*x^2/(1+x^3)^2)

Example 4

In this example, first, we define the integration variables x and y then use the int() function to find the integration of the given expression with respect to x and y.

syms x y

int(x*y/(1+y^3))

Example 5

The example utilizes the int() function to determine the definite integration of the provided equation from -1 to 1 with respect to x after first defining the integration variable x.

syms x

int(x*log(1+x), [-1 1])

Example 6

In this example, first, we define the integration variables x, a, t, and, z and then use the int() function to find the indefinite integration of the given expressions in the matrix with respect to the integration variable.

syms a x t z

int([exp(t) a*t; tan(t) cos(t)])

Example 7

The following example first defines the integration variable x and then uses the int() function to find the indefinite integration by parts of the given expression with respect to x.

syms x

int(x^3*exp(x)/5)

Conclusion

The int() function in MATLAB provides a convenient way to perform the integration of functions or expressions. It is particularly useful for solving complex mathematical problems and performing symbolic calculations. By using the int() function, we can find both indefinite and definite integrals, allowing us to compute antiderivatives and evaluate definite integrals over specific intervals. This guide illustrated how to integrate a function in MATLAB using the int() function with examples.

About the author

Komal Batool Batool

I am passionate to research technologies and new ideas and that has brought me here to write for the LinuxHint. My major focus is to write on programming languages and computer science related topics.