lettura simple

Indefinite Integral on Matlab

Let me try to explain how to calculate indefinite integrals using Matlab in a way that's simple and intuitive.

So, let's start with the basics. In mathematics, indefinite integrals are the reverse operation of derivatives. An indefinite integral is a function that, when differentiated, gives you back the original function. $$ \int f(x) \ dx = F(x)+c $$ It's denoted by the symbol ∫ and read as "integral of", where c is an arbitrary constant. To put it simply, the indefinite integral of a function f(x) is a function F(x) such that the derivative of F(x) + c is equal to f(x). $$ \frac{d \ F(x)+x}{dx} = f(x) $$

The Integral of a Polynomial

Now, when it comes to calculating the indefinite integral of a polynomial function using Matlab, we can use the "polyint" function.

polyint(P)

This function takes an array of numeric coefficients of the polynomial in descending order of exponents as its parameter.

Let's take an example to illustrate this.

Consider the polynomial function

$$ P(x) = 2x^3 + 4x + 3 $$

To calculate its indefinite integral, we first define an array "P" that contains the coefficients of the polynomial.

>> P = [2 0 4 3]

Note. Here, the first element of the array corresponds to the coefficient of the highest degree term, the second element to the coefficient of the second-highest degree term, and so on

Now, to calculate the indefinite integral of P(x), we simply call the polyint() function with "P" as its parameter.

>> polyint(P)

This function returns an array that contains the coefficients of the primitive function.

In this case, the result is [0.5 0 2 3 0]

ans =
0.50000 0.00000 2.00000 3.00000 0.00000

Which means that the indefinite integral of P(x) is

$$ \int 2x^3 + 4x+3 \ dx = \frac{1}{2} x^4 + 2x^2 + 3x + c $$

The constant c at the end needs to be added manually.

Verification. To verify this result, we can use the additive property of integrals. The integral of a sum is equal to the sum of the integrals. So, we can write: $$ \int 2x^3 + 4x+3 \ dx $$ $$ \int 2x^3 \ dx + \int 4x \ dx + \int 3 \ dx $$ We can then solve each of these integrals separately, and add the results together to get the indefinite integral of P(x). $$ \frac{1}{2}x^4 + 2x^2 + 3x + c $$

Integration of a function

To calculate the integral of any mathematical function on Matlab, we can make use of the int() function.

int(f,dx)

Now, this function has two parameters:

  • the first one, "f", is the mathematical expression of the function with the unknown variables defined in symbols
  • the second parameter, "dx", represents the integration variable

Note. It's important to note that if the second parameter is not specified, the function will assume that the variable is "x" by default. The "int()" function is based on symbolic computation, which means that we need to define the variables as symbols using the "syms" statement.

To give you an example, consider the indefinite integral of the function f(x)=1/x

$$ \int \frac{1}{x} \ dx $$

We can define the symbol of the unknown variable "x" using the "syms" function

>> syms x

Then compute the indefinite integral of the expression 1/x using the int() function.

>> int(1/x)

The result is the antiderivative of the function f = 1/x, which is equal to the natural logarithm of "x".

ans = log(x)

The indefinite integral of the function f=1/x is log(x).

$$ \int \frac{1}{x} \ dx = \log(x) + c $$

The constant "c" is considered implicit and you need to add it manually.

What about a function with two or more variables?

Now, if we have a function with two or more variables, it is better to specify the integration variable as well.

For instance, consider the integral of a function with two variables, such as f(x,y)=x2y2

$$ \int x^2y^2 \ dy $$

In this case, the integration variable is "y".

We can define the symbols of the two variables using the "syms" function.

syms x y

Then we compute the integral with respect to the variable "y" by specifying it as the second parameter of the int() function.

>> int(x^2*y^2,y)

The result is the primitive function:

(x^2*y^3)/3

Therefore, the solution to the indefinite integral is:

$$ \int x^2y^2 \ dy = \frac{x^3y^3}{3} $$

By following these simple steps, we can calculate any indefinite integral in Matlab.

And that's it! Hopefully, this explanation was helpful and clear enough.




Report a mistake or post a question




FacebookTwitterLinkedinLinkedin