Matlab Operations | Calculating Integrals

int is the command function for calculating integrals. In the Matlab command window, enter the program in the format:

int(f,x,[a,b])

Press Enter to output the result. Where

int(f,x): The function f calculates the indefinite integral with respect to the symbolic variable x;

int(f,x,[a,b]): The function f calculates the definite integral with respect to the symbolic variable x over the interval [a,b].

Example 1: Calculate the indefinite integral of f(x)=2sin(3x+1).

Solution: Enter the following in the command window:

>> syms x;

>> f=3*sin(3*x+1);

>> int(f,x)

ans =-cos(3*x + 1)+C

Matlab Operations | Calculating IntegralsNote: When calculating the indefinite integral, the result obtained by Matlab is an antiderivative, and the indefinite integral represents the entire set of antiderivatives, so we need to consider the “+C” in the result.

Example 2: Given f(x)=2e^2x, calculate the definite integral of f(x) over [0,1].

Solution: Enter the following in the command window:

>> syms x;

>> f=2*exp(2*x);

>> int(f,[0,1])

ans =exp(2) – 1

Example 3: Given f(x)=xcosx, calculate the definite integral of f(x) over [0,π].

Solution: Enter the following in the command window:

>> syms x;

>> f=x*cos(x);

>> int(f,[0,pi]) Matlab Operations | Calculating Integrals: In MATLAB, “π” is represented as “pi”

ans =-2

🎀

Thank you for your attention~

I hope the above content is helpful to you!

🎀

Leave a Comment