Definite and Indefinite Integrals - MATLAB Int
Definite and Indefinite Integrals - MATLAB Int
int
Definite and indefinite integrals
Syntax
F = int(expr)
F = int(expr,var)
F = int(expr,a,b)
F = int(expr,var,a,b)
Description
F = int(expr) computes the indefinite integral of expr. int uses the default integration variable example
determined by symvar(expr,1). If expr is a constant, then the default integration variable is x.
example
F = int(expr,var) computes the indefinite integral of expr with respect to the symbolic scalar variable
var.
F = int(expr,a,b) computes the definite integral of expr from a to b. int uses the default integration example
variable determined by symvar(expr,1). If expr is a constant, then the default integration variable is x.
example
F = int(expr,var,a,b) computes the definite integral of expr with respect to the symbolic scalar
variable var from a to b.
F = int( ___ ,Name,Value) specifies additional options using one or more Name,Value pair arguments. example
For example, 'IgnoreAnalyticConstraints',true specifies that int applies additional simplifications
to the integrand.
Note
The int function computes integral symbolically, and it is not related to integer data types in
MATLAB®. For more information about integers, see Integers.
https://www.mathworks.com/help/symbolic/sym.int.html 1/11
4/2/24, 9:49 PM Definite and indefinite integrals - MATLAB int
Copy Command
syms x Get
expr = -2*x/(1+x^2)^2;
F = int(expr) Get
F =
1
2
x + 1
Copy Command
syms x z Get
f(x,z) = x/(1+z^2);
Find the indefinite integrals of the multivariate expression with respect to the variables x and z.
Fx = int(f,x) Get
Fx(x, z) =
2
x
2
2 (z + 1)
Fz = int(f,z) Get
Fz(x, z) = x atan(z)
If you do not specify the integration variable, then int uses the first variable returned by symvar as the integration
variable.
var = x
F = int(f) Get
F(x, z) =
2
x
2
2 (z + 1)
https://www.mathworks.com/help/symbolic/sym.int.html 2/11
4/2/24, 9:49 PM Definite and indefinite integrals - MATLAB int
Copy Command
syms x Get
expr = x*log(1+x);
F = int(expr,[0 1])
F =
1
syms t Get
F = int(2*x,[sin(t) 1])
F =
2
cos(t )
When int cannot compute the value of a definite integral, numerically approximate the integral by using vpa.
syms x Get
f = cos(x)/sqrt(1 + x^2);
Fint = int(f,x,[0 10])
Fint =
10
cos( x)
dx
∫ 2
0 √x + 1
Fvpa = 0.37570628299079723478493405557162
To approximate integrals directly, use vpaintegral instead of vpa. The vpaintegral function is faster and
provides control over integration tolerances.
Fvpaint = 0.375706
https://www.mathworks.com/help/symbolic/sym.int.html 3/11
4/2/24, 9:49 PM Definite and indefinite integrals - MATLAB int
Copy Command
syms a x t z Get
M = [exp(t) exp(a*t); sin(t) cos(t)]
M =
t a t
e e
(sin(t ) cos(t ))
F = int(M,t) Get
F =
a t
⎛ e ⎞
t
⎜ e ⎟
a
⎜ ⎟
⎝ −cos(t ) sin(t )⎠
Apply IgnoreAnalyticConstraints
Copy Command
F(x) =
2
x
x acos(cos( x)) −
2 sign(sin( x))
By default, int uses strict mathematical rules. These rules do not let int rewrite acos(cos(x)) as x.
F = int(f,x,'IgnoreAnalyticConstraints',true) Get
F(x) =
2
x
https://www.mathworks.com/help/symbolic/sym.int.html 4/11
4/2/24, 9:49 PM Definite and indefinite integrals - MATLAB int
Copy Command
syms x t Get
F = int(x^t,x)
F =
⎧ log( x) if t = −1
⎪
⎨ t +1
x
⎪ if t ≠ −1
⎩ t + 1
By default, int returns the general results for all values of the other symbolic parameter t. In this example, int
returns two integral results for the case t = −1 and t ≠ −1 .
To ignore special cases of parameter values, set 'IgnoreSpecialCases' to true. With this option, int ignores the
special case t = −1 and returns the solution for t ≠ −1 .
F = int(x^t,x,'IgnoreSpecialCases',true) Get
F =
t +1
x
t + 1
Copy Command
syms x Get
f(x) = 1/(x-1)
f(x) =
1
x − 1
Compute the definite integral of this function from x = 0 to x = 2 . Since the integration interval includes the pole,
the result is not defined.
F = NaN
However, the Cauchy principal value of the integral exists. To compute the Cauchy principal value of the integral, set
'PrincipalValue' to true.
https://www.mathworks.com/help/symbolic/sym.int.html 5/11
4/2/24, 9:49 PM Definite and indefinite integrals - MATLAB int
F = 0
Copy Command
F =
x
x e dx
∫
You can apply integration by parts to F by using the integrateByParts function. Use exp(x) as the differential to
be integrated.
G = integrateByParts(F,exp(x)) Get
G =
x x
x e − e dx
∫
To evaluate the integral in G, use the release function to ignore the 'Hold' option.
Gcalc =
x x
x e − e
Compare the result to the integration result returned by int without setting the 'Hold' option.
Fcalc =
x
e ( x − 1)
Copy Command
https://www.mathworks.com/help/symbolic/sym.int.html 6/11
4/2/24, 9:49 PM Definite and indefinite integrals - MATLAB int
F(x) =
sin(sinh( x)) dx
∫
You can approximate the integrand function f ( x) as polynomials by using the Taylor expansion. Apply taylor to
expand the integrand function f ( x) as polynomials around x = 0 . Compute the integral of the approximated
polynomials.
fTaylor(x) =
9 7 5
x x x
− − + x
5670 90 15
Fapprox(x) =
10 8 6 2
x x x x
− − +
56700 720 90 2
expr — Integrand
symbolic expression | symbolic function | symbolic vector | symbolic matrix | symbolic number
Integration variable, specified as a symbolic variable. If you do not specify this variable, int uses the default
variable determined by symvar(expr,1). If expr is a constant, then the default variable is x.
a — Lower bound
number | symbolic number | symbolic variable | symbolic expression | symbolic function
Lower bound, specified as a number, symbolic number, variable, expression, or function (including expressions and
functions with infinities).
b — Upper bound
https://www.mathworks.com/help/symbolic/sym.int.html 7/11
4/2/24, 9:49 PM Definite and indefinite integrals - MATLAB int
Upper bound, specified as a number, symbolic number, variable, expression, or function (including expressions and
functions with infinities).
Name-Value Arguments
Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and
Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs
does not matter.
Before R2021a, use commas to separate each name and value, and enclose Name in quotes.
Example: 'IgnoreAnalyticConstraints',true specifies that int applies purely algebraic simplifications to the
integrand.
Indicator for applying purely algebraic simplifications to the integrand, specified as true or false. If the value is
true, apply purely algebraic simplifications to the integrand. This option can provide simpler results for
expressions, for which the direct use of the integrator returns complicated results. In some cases, it also enables
int to compute integrals that cannot be computed otherwise.
Using this option can lead to results not generally valid. This option applies mathematical identities that are
convenient, but the results do not always hold for all values of variables. For details, see Algorithms.
Indicator for ignoring special cases, specified as true or false. This ignores cases that require one or more
parameters to be elements of a comparatively small set, such as a fixed finite set or a set of integers.
Indicator for returning the principal value, specified as true or false. If the value is true, int computes the
Cauchy principal value of the integral. In live scripts, the Cauchy principal value of the unevaluated integral appears
as the symbol.
https://www.mathworks.com/help/symbolic/sym.int.html 8/11
4/2/24, 9:49 PM Definite and indefinite integrals - MATLAB int
Indicator for unevaluated integration, specified as true or false. If the value is true, int returns integrals without
evaluating them.
Tips
In contrast to differentiation, symbolic integration is a more complicated task. If int cannot compute an integral of an
expression, check for these reasons:
For some integrals that have closed form solutions, where these solutions are complicated and int returns
unresolved integrals, you can use simplify to obtain the closed form solutions. For example, the following code finds
the closed form solution of the integral of f(x):
syms x
f(x) = x*log(x/2+sqrt(x^2+1));
F = int(f,x)
simplify(F,Steps=10)
Otherwise, you can try approximating unresolved integrals by using one of these methods:
For indefinite integrals, use series expansions. Use this method to approximate an integral around a particular
value of the variable.
For indefinite integrals, int does not return a constant of integration in the result. The results of integrating
mathematically equivalent expressions may be different. For example, syms x; int((x+1)^2) returns (x+1)^3/3,
while syms x; int(x^2+2*x+1) returns (x*(x^2+3*x+3))/3, which differs from the first result by 1/3.
For indefinite integrals, int implicitly assumes that the integration variable var is real. For definite integrals, int
restricts the integration variable var to the specified integration interval. If one or both integration bounds a and b are
not numeric, int assumes that a <= b unless you explicitly specify otherwise.
Algorithms
When you use IgnoreAnalyticConstraints, int applies some of these rules:
log(a) + log(b) = log(a·b) for all values of a and b. In particular, the following equality is valid for all values of a, b, and c:
c c c
(a·b) = a ·b .
b
log(a ) = b·log(a) for all values of a and b. In particular, the following equality is valid for all values of a, b, and c:
b c b·c
(a ) = a .
If f and g are standard mathematical functions and f(g(x)) = x for all small positive numbers, then f(g(x)) = x is
assumed to be valid for all complex values x. In particular:
x
log(e ) = x
https://www.mathworks.com/help/symbolic/sym.int.html 9/11
4/2/24, 9:49 PM Definite and indefinite integrals - MATLAB int
, ,
asin(sin(x)) = x acos(cos(x)) = x atan(tan(x)) = x
, ,
asinh(sinh(x)) = x acosh(cosh(x)) = x atanh(tanh(x)) = x
x
Wk(x·e ) = x for all branch indices k of the Lambert W function.
Version History
expand all
Introduced before R2006a
See Also
diff | dsolve | functionalDerivative | symvar | vpaintegral | integrateByParts | changeIntegrationVariable |
release | rewrite
Topics
Integration
External Websites
Calculus Integrals (MathWorks Teaching Resources)
Beam Bending and Deflection (MathWorks Teaching Resources)
https://www.mathworks.com/help/symbolic/sym.int.html 10/11
4/2/24, 9:49 PM Definite and indefinite integrals - MATLAB int
https://www.mathworks.com/help/symbolic/sym.int.html 11/11