You are on page 1of 7

int

Definite and indefinite integrals

Syntax

int(expr,var)
int(expr,var,a,b)
int( ___ ,Name,Value)

Description
int(expr,var) computes the indefinite integral of expr with respect to the symbolic scalar example

variable var. Specifying the variable var is optional. If you do not specify it, int uses the
default variable determined by symvar. If expr is a constant, then the default variable is x.
example
int(expr,var,a,b) computes the definite integral of expr with respect to var from a to b.
If you do not specify it, int uses the default variable determined by symvar. If expr is a
constant, then the default variable is x.
int(expr,var,[a b]) is equivalent to int(expr,var,a,b).
example
int( ___ ,Name,Value) specifies additional using one or more Name,Value pair arguments.
For example, 'IgnoreAnalyticConstraints',true specifies that int applies additional
simplifications to the integrand.

Examples collapse all

 Indefinite Integral of Univariate Expression

Find an indefinite integral of this univariate expression.

syms x
f = -2*x/(1+x^2)^2;
int(f)

ans =
1/(x^2 + 1)

 Indefinite Integrals of Multivariate Expression

Find indefinite integrals of this multivariate expression with respect to the variables x and z.

syms x z
f = x/(1+z^2);
int(f,x)
int(f,z)
ans =
x^2/(2*(z^2 + 1))

ans =
x*atan(z)
If you do not specify the integration variable, int uses the variable returned by symvar. For this
expression, symvar returns x.

symvar(f, 1)

ans =
x

 Definite Integrals of Symbolic Expressions

Integrate an expression from 0 to 1.

syms x
f = x*log(1+x);
int(f,[0 1])

ans =
1/4
Integrate an expression from sin(t) to 1.

syms t
int(2*x, [sin(t) 1])

ans =
cos(t)^2
When int cannot compute a definite integral, numerically approximate the integral by using vpa.

syms x
f = cos(x)/sqrt(1 + x^2);
fInt = int(f,x,[0 10]);
fVpa = vpa(fInt)

fVpa =
0.37570628299079723478493405557162
To approximate integrals directly, use vpaintegral instead of vpa. The vpaintegral function is
faster and provides control over integration tolerances.

fVpa = vpaintegral(f,x,[0 10])

fVpa =
0.375706

 Integrals of Matrix Elements

Find indefinite integrals for the expressions listed as the elements of a matrix.
ans =
[ exp(t), exp(a*t)/a]
[ -cos(t), sin(t)]

 Apply IgnoreAnalyticConstraints

Compute this indefinite integral. By default, int uses strict mathematical rules. These rules do not let
int rewrite asin(sin(x)) and acos(cos(x)) as x.

syms x
f = acos(sin(x));
int(f,x)

ans =
x*acos(sin(x)) + x^2/(2*sign(cos(x)))
If you want a simple practical solution, try IgnoreAnalyticConstraints.

int(f, x, 'IgnoreAnalyticConstraints', true)

ans =
-(x*(x - pi))/2

 Ignore Special Cases

Compute this integral with respect to the variable x. By default, int returns the integral as a piecewise
object where every branch corresponds to a particular value (or a range of values) of the symbolic
parameter t.

syms x t
int(x^t, x)

ans =
piecewise(t == -1, log(x), t ~= -1, x^(t + 1)/(t + 1))
To ignore special cases of parameter values, use IgnoreSpecialCases. With this option, int
ignores the special case t=-1 and returns only the branch where t<>–1.

int(x^t, x, 'IgnoreSpecialCases', true)

ans =
x^(t + 1)/(t + 1)

 Find Cauchy Principal Value

Compute this definite integral, where the integrand has a pole in the interior of the interval of
integration. Mathematically, this integral is not defined.
syms x
f = 1/(x-1);
int(f,x,0,2)

ans =
NaN
However, the Cauchy principal value of the integral exists. Use PrincipalValue to compute the
Cauchy principal value of the integral.

int(f,x,0,2,'PrincipalValue',true)

ans =
0

 Approximate Indefinite Integrals

If int cannot compute a closed form of an integral, it returns an unresolved integral.

syms x
f = sin(sinh(x));
int(f,x)

ans =
int(sin(sinh(x)), x)
If int cannot compute a closed form of an indefinite integral, try to approximate the expression around
some point using taylor, and then compute the integral. For example, approximate the expression
around x = 0.

fApprox = taylor(f, x, 'ExpansionPoint', 0, 'Order', 10);


int(fApprox,x)

ans =
x^10/56700 - x^8/720 - x^6/90 + x^2/2

Input Arguments collapse all

expr — Integrand
 symbolic expression | symbolic function | symbolic vector | symbolic matrix | symbolic number

Integrand, specified as a symbolic expression or function, a constant, or a vector or matrix of symbolic


expressions, functions, or constants.

var — Integration variable


 symbolic variable

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
 number | symbolic number | symbolic variable | symbolic expression | symbolic function

Upper bound, specified as a number, symbolic number, variable, expression, or function (including
expressions and functions with infinities).

Name-Value Pair Arguments


Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and
Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several
name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'IgnoreAnalyticConstraints',true specifies that int applies purely algebraic


simplifications to the integrand.
collapse all

'IgnoreAnalyticConstraints' — Indicator for applying purely algebraic


 simplifications to integrand
false (default) | true

Indicator for applying purely algebraic simplifications to 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.
Sometimes, it also enables int to compute integrals that cannot be computed otherwise.

Using this option can lead to wrong or incomplete results.

'IgnoreSpecialCases' — Indicator for ignoring special cases


 false (default) | true

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.

'PrincipalValue' — Indicator for returning principal value


 false (default) | true

Indicator for returning principal value, specified as true or false. If the value is true, compute the
Cauchy principal value of the integral.
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:
˗ The antiderivative does not exist in a closed form.
˗ The antiderivative exists, but int cannot find it.

If int cannot compute a closed form of an integral, it returns an unresolved integral.


Try approximating such 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 definite integrals, use numeric approximations.

• Results returned by int do not include integration constants.


• 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 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:
  (a·b)c = ac·bc.
• log(ab) = 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:
  (ab)c = ab·c.
• 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:
˗ log(ex) = x
˗ asin(sin(x)) = x, acos(cos(x)) = x, atan(tan(x)) = x
˗ asinh(sinh(x)) = x, acosh(cosh(x)) = x, atanh(tanh(x)) = x
˗ lambertWk(x·ex) = x for all values of k

See Also
diff | functionalDerivative | symprod | symsum | symvar | vpaintegral

Topics
Integration

Introduced before R2006a

You might also like