Main Content

int

Definite and indefinite integrals

Description

example

F= int(expr)computes the indefinite integral ofexpr.intuses the default integration variable determined bysymvar(expr,1). Ifexpris a constant, then the default integration variable isx.

example

F= int(expr,var)computes the indefinite integral ofexprwith respect to the symbolic scalar variablevar.

example

F= int(expr,a,b)computes the definite integral ofexprfromatob.intuses the default integration variable determined bysymvar(expr,1). Ifexpris a constant, then the default integration variable isx.

int(expr,[a b])相当于int(expr,a,b).

example

F= int(expr,var,a,b)computes the definite integral ofexprwith respect to the symbolic scalar variablevarfromatob.

int(expr,var,[a b])相当于int(expr,var,a,b).

example

F= int(___,Name,Value)specifies additional options using one or moreName,Valuepair arguments. For example,'IgnoreAnalyticConstraints',truespecifies thatintapplies additional simplifications to the integrand.

Examples

collapse all

Define a univariate expression.

symsxexpr = -2*x/(1+x^2)^2;

Find the indefinite integral of the univariate expression.

F = int(expr)
F =

1 x 2 + 1

Define a multivariate function with variablesxandz.

symsxzf(x,z) = x/(1+z^2);

Find the indefinite integrals of the multivariate expression with respect to the variablesxandz.

Fx = int(f,x)
Fx(x, z) =

x 2 2 z 2 + 1

Fz = int(f,z)
Fz(x, z) =
                       
                        
                         
                          
                           
                            x
                           
                           
                           
                            
                             
                              atan
                            
                            
                             
                              (
                             
                              
                               
                                z
                              
                             
                             
                              )
                            
                           
                          
                         
                        
                       

If you do not specify the integration variable, thenintuses the first variable returned bysymvaras the integration variable.

var = symvar(f,1)
var =
                       
                        
                         
                          x
                        
                       
F = int(f)
F(x, z) =

x 2 2 z 2 + 1

Integrate a symbolic expression from0to1.

symsxexpr = x*log(1+x); F = int(expr,[0 1])
F =

1 4

Integrate another expression fromsin(t)to1.

symstF = int(2*x,[sin(t) 1])
F =
                       
                        
                         
                          
                           
                            
                             
                              cos
                            
                            
                             
                              (
                             
                              
                               
                                t
                              
                             
                             
                              )
                            
                           
                          
                          
                           
                            2
                          
                         
                        
                       

Whenintcannot compute the value of a definite integral, numerically approximate the integral by usingvpa.

symsxf = cos(x)/sqrt(1 + x^2); Fint = int(f,x,[0 10])
Fint =

0 10 cos ( x ) x 2 + 1 d x

Fvpa = vpa(Fint)
Fvpa =
                       
                        
                         
                          0.37570628299079723478493405557162
                        
                       

To approximate integrals directly, usevpaintegralinstead ofvpa. Thevpaintegralfunction is faster and provides control over integration tolerances.

Fvpaint = vpaintegral(f,x,[0 10])
Fvpaint =
                       
                        
                         
                          0.375706
                        
                       

Define a symbolic matrix containing four expressions as its elements.

symsaxtzM = [exp(t) exp(a*t); sin(t) cos(t)]
M =

( e t e a t sin ( t ) cos ( t ) )

Find indefinite integrals of the matrix element-wise.

F = int(M,t)
F =

( e t e a t a - cos ( t ) sin ( t ) )

Define a symbolic function and compute its indefinite integral.

symsf(x)f(x) = acos(cos(x)); F = int(f,x)
F(x) =

x acos ( cos ( x ) ) - x 2 2 sign ( sin ( x ) )

By default,intuses strict mathematical rules. These rules do not letintrewriteacos(cos(x))asx.

If you want a simple practical solution, set'IgnoreAnalyticConstraints'totrue.

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

x 2 2

Define a symbolic expression x t and compute its indefinite integral with respect to the variable x .

symsxtF = int(x^t,x)
F =

{ log ( x ) if t = - 1 x t + 1 t + 1 if t - 1

By default,intreturns the general results for all values of the other symbolic parametert. In this example,intreturns two integral results for the case t = - 1 and t - 1 .

To ignore special cases of parameter values, set'IgnoreSpecialCases'totrue. With this option,intignores the special case t = - 1 and returns the solution for t - 1 .

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

x t + 1 t + 1

Define a symbolic function f ( x ) = 1 / ( x - 1 ) that has a pole at x = 1 .

symsxf(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 = int (F (0 - 2))
F =
                       
                        
                         
                          NaN
                        
                       

However, the Cauchy principal value of the integral exists. To compute the Cauchy principal value of the integral, set“PrincipalValue”totrue.

F = int(f,[0 2],“PrincipalValue”,true)
F =
                       
                        
                         
                          0
                        
                       

Find the integral of x e x dx .

Define the integral without evaluating it by setting the'Hold'option totrue.

symsxg(y)F = int(x*exp(x),'Hold',true)
F =

x e x d x

You can apply integration by parts toFby using theintegrateByPartsfunction. Useexp(x)as the differential to be integrated.

G = integrateByParts (F, exp (x))
G =

x e x - e x d x

To evaluate the integral inG, use thereleasefunction to ignore the'Hold'option.

Gcalc = release(G)
Gcalc =
                       
                        
                         
                          
                           
                            
                             
                              x
                             
                             
                             
                              
                               
                                e
                              
                              
                               
                                x
                              
                             
                            
                           
                           
                            -
                           
                            
                             
                              e
                            
                            
                             
                              x
                            
                           
                          
                         
                        
                       

Compare the result to the integration result returned byintwithout setting the'Hold'option.

Fcalc = int(x*exp(x))
Fcalc =
                       
                        
                         
                          
                           
                            
                             
                              e
                            
                            
                             
                              x
                            
                           
                           
                           
                           
                            
                             
                              
                               
                                x
                               
                                -
                               
                                1
                              
                             
                            
                           
                          
                         
                        
                       

Ifintcannot compute a closed form of an integral, then it returns an unresolved integral.

symsf(x)f(x) = sin(sinh(x)); F = int(f,x)
F(x) =

sin ( sinh ( x ) ) d x

You can approximate the integrand function f ( x ) as polynomials by using the Taylor expansion. Applytaylorto expand the integrand function f ( x ) as polynomials around x = 0 . Compute the integral of the approximated polynomials.

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

x 9 5670 - x 7 90 - x 5 15 + x

Fapprox = int(fTaylor,x)
Fapprox(x) =

x 10 56700 - x 8 720 - x 6 90 + x 2 2

Input Arguments

collapse all

Integrand, specified as a symbolic expression, function, vector, matrix, or number.

Integration variable, specified as a symbolic variable. If you do not specify this variable,intuses the default variable determined bysymvar(expr,1). Ifexpris a constant, then the default variable isx.

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

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 asName1=Value1,...,NameN=ValueN, whereNameis the argument name andValueis 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 encloseNamein quotes.

Example:'IgnoreAnalyticConstraints',truespecifies thatintapplies purely algebraic simplifications to the integrand.

Indicator for applying purely algebraic simplifications to the integrand, specified astrueorfalse. If the value istrue, 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 enablesintto 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, seeAlgorithms.

Indicator for ignoring special cases, specified astrueorfalse. 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 astrueorfalse. If the value istrue, compute the Cauchy principal value of the integral. In live script, the Cauchy principal value of unevaluated integral shows as thesymbol.

Indicator for unevaluated integration, specified astrueorfalse. If the value istrue,intreturns integrals without evaluating them.

提示s

  • In contrast to differentiation, symbolic integration is a more complicated task. Ifintcannot compute an integral of an expression, check for these reasons:

    • The antiderivative does not exist in a closed form.

    • The antiderivative exists, butint不能鳍d it.

    Ifintcannot 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.

  • For indefinite integrals,intdoes 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, whilesyms x; int(x^2+2*x+1)returns(x*(x^2+3*x+3))/3, which differs from the first result by1/3.

  • For indefinite integrals,intimplicitly assumes that the integration variablevaris real. For definite integrals,intrestricts the integration variablevarto the specified integration interval. If one or both integration boundsaandbare not numeric,intassumes thata <= bunless you explicitly specify otherwise.

Algorithms

When you useIgnoreAnalyticConstraints,intapplies some of these rules:

  • log(a) + log(b) = log(a·b)for all values ofaandb. In particular, the following equality is valid for all values ofa,b,c:

    (a·b)c=ac·bc.

  • log(ab) =b·log(a)for all values ofaandb. In particular, the following equality is valid for all values ofa,b,c:

    (ab)c=ab·c.

  • Iffandgare standard mathematical functions andf(g(x)) =xfor all small positive numbers, thenf(g(x)) =xis assumed to be valid for all complex valuesx. 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

    • Wk(x·ex) =xfor all branch indiceskof the LambertWfunction.

Version History

Introduced before R2006a