Definite and indefinite integrals - MATLAB int (2024)

Definite and indefinite integrals

collapse all in page

Syntax

F = int(expr)

F = int(expr,var)

F = int(expr,a,b)

F = int(expr,var,a,b)

F = int(___,Name,Value)

Description

example

F = int(expr) computes the indefinite integral of expr. int uses the default integration variable 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.

example

F = int(expr,a,b) computes the definite integral of expr from a to b. int uses the default integration variable determined by symvar(expr,1). If expr is a constant, then the default integration variable is x.

int(expr,[a b]) is equivalent to int(expr,a,b).

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.

int(expr,var,[a b]) is equivalent to int(expr,var,a,b).

example

F = int(___,Name,Value) specifies additional options using one or more Name,Value pair arguments. 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.

Examples

collapse all

Indefinite Integral of Univariate Expression

Open Live Script

Define a univariate expression.

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

Find the indefinite integral of the univariate expression.

F = int(expr)
F =

1x2+1

Indefinite Integrals of Multivariate Function

Open Live Script

Define a multivariate function with variables x and z.

syms x zf(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)
Fx(x, z) =

x22z2+1

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

If you do not specify the integration variable, then int uses the first variable returned by symvar as the integration variable.

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

x22z2+1

Open Live Script

Integrate a symbolic expression from 0 to 1.

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

14

Integrate another expression from sin(t) to 1.

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

When int cannot compute the value of a definite integral, numerically approximate the integral by using vpa.

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

010cos(x)x2+1dx

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.

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

Integrals of Matrix Elements

Open Live Script

Define a symbolic matrix containing four expressions as its elements.

syms a x t zM = [exp(t) exp(a*t); sin(t) cos(t)]
M =

(eteatsin(t)cos(t))

Find indefinite integrals of the matrix element-wise.

F = int(M,t)
F =

(eteata-cos(t)sin(t))

Apply IgnoreAnalyticConstraints

Open Live Script

Define a symbolic function and compute its indefinite integral.

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

xacos(cos(x))-x22sign(sin(x))

By default, int uses strict mathematical rules. These rules do not let int rewrite acos(cos(x)) as x.

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

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

x22

Ignore Special Cases

Open Live Script

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

syms x tF = int(x^t,x)
F =

{log(x)ift=-1xt+1t+1ift-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)

Find Cauchy Principal Value

Open Live Script

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

syms xf(x) = 1/(x-1)
f(x) =

1x-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' to true.

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

Unevaluated Integral and Integration by Parts

Open Live Script

Find the integral of xexdx.

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

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

xexdx

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))
G =

xex-exdx

To evaluate the integral in G, use the release function to ignore the 'Hold' option.

Gcalc = release(G)
Gcalc =xex-ex

Compare the result to the integration result returned by int without setting the 'Hold' option.

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

Approximate Indefinite Integrals

Open Live Script

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

syms f(x)f(x) = sin(sinh(x));F = int(f,x)
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 = taylor(f,x,'ExpansionPoint',0,'Order',10)
fTaylor(x) =

x95670-x790-x515+x

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

x1056700-x8720-x690+x22

Input Arguments

collapse all

exprIntegrand
symbolic expression | symbolic function | symbolic vector | symbolic matrix | symbolic number

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

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

aLower 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).

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

IgnoreAnalyticConstraintsIndicator for applying purely algebraic simplifications to integrand
false (default) | true

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.

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

PrincipalValueIndicator for returning principal value
false (default) | true

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 Definite and indefinite integrals - MATLAB int (1) symbol.

HoldIndicator for unevaluated integration
false (default) | true

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:

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

    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 xf(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 definite integrals, use numeric approximations.

  • 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:

    (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

    • Wk(x·ex)=x for all branch indices k of the Lambert W function.

Version History

Introduced before R2006a

expand all

int(___,'Hold',true) returns integrals without evaluating them. Use release to return the evaluated integrals by ignoring the 'Hold' option in the int function.

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)

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Definite and indefinite integrals - MATLAB int (2)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Definite and indefinite integrals - MATLAB int (2024)

FAQs

How do you integrate an indefinite integral in MATLAB? ›

F = int( expr ) computes the indefinite integral of expr . int uses the default integration variable determined by symvar ( expr,1 ). If expr is a constant, then the default integration variable is x . F = int( expr , var ) computes the indefinite integral of expr with respect to the symbolic scalar variable var .

How do you know if an integral is definite or indefinite? ›

There are no limits of integration in an indefinite integral. A definite integral represents a number when the lower and upper limits are constants. The indefinite integral represents a family of functions whose derivatives are f. The difference between any two functions in the family is a constant.

What is definite integral and indefinite integral? ›

Definite and Indefinite Integrals. The definite integral of f(x) is a NUMBER and represents the area under the curve f(x) from x=a to x=b. The indefinite integral of f(x) is a FUNCTION and answers the question, "What function when differentiated gives f(x)?"

Does MATLAB calculate integrals? ›

You can use MATLAB® and Symbolic Math Toolbox™ to calculate integrals numerically and symbolically.

How to use ln in MATLAB? ›

but remember ln is just an e-log. Suppose we need to compute ln(x) in matlab, then simply write log(x) in the matlab. Here, log(x) represents the natural logarithm with base e. ln(X) = log(X), where the left had side is the mathematical symbolism and the right hand side is the Matlab code.

Can I do definite integration without indefinite? ›

Is it possible to do definite integration without studying indefinite integration? Yes. For a continuous function,definite integration is defined as-algebric sum of area under curve and x axis. If you can geometrically compute the area,then algebric calculus can be avoided.

What is the difference between definite and indefinite? ›

The definite article (the) is used before a noun to indicate that the identity of the noun is known to the reader. The indefinite article (a, an) is used before a noun that is general or when its identity is not known. There are certain situations in which a noun takes no article.

Which is more difficult definite or indefinite integral? ›

Indefinite gives you the complete area of the function where as in definite you're restricting it to certain limits to get the area which you specifically want. Definite Integration is comparatively less challenging than Indefinite Integration because of the useful Properties.

How do you define a definite integral? ›

The definite integral of any function can be expressed either as the limit of a sum or if there exists an antiderivative F for the interval [a, b], then the definite integral of the function is the difference of the values at points a and b.

Is indefinite integral the same as antiderivative? ›

All antiderivatives are the same, up to adding a constant, so most people use the terms indefinite integral and anti-derivative interchangably. Even the constants match up. Changing the value of a in ∫xaf(t)dt changes F(x) by a constant, so both anti-derivatives and integrals are only defined up to a constant.

Why is it called indefinite integral? ›

If F is a primitive of f, so is F+C for any constant C, the so called constant of integration. The indefinite integral of f can be thought of as the set of all primitives of f: ∫f=F+C. Why indefinite? Because is there some indefinition due to the constant C.

How to use MATLAB to evaluate an integral? ›

You can apply integration by parts to F by using the integrateByParts function. Use exp(x) as the differential to be integrated. To evaluate the integral in G , use the release function to ignore the 'Hold' option. Compare the result to the integration result returned by int without setting the 'Hold' option.

Can MATLAB do double integrals? ›

q = dblquad(fun,xmin,xmax,ymin,ymax) calls the quad function to evaluate the double integral fun(x,y) over the rectangle xmin <= x <= xmax , ymin <= y <= ymax . The input argument, fun , is a function handle that accepts a vector x , a scalar y , and returns a vector of integrand values.

How do you integrate a formula in MATLAB? ›

q = integral( fun , xmin , xmax ) numerically integrates function fun from xmin to xmax using global adaptive quadrature and default error tolerances. q = integral( fun , xmin , xmax , Name,Value ) specifies additional options with one or more Name,Value pair arguments.

How to put infinity in MATLAB? ›

MATLAB® represents infinity by the special value Inf . Infinity results from operations like division by zero and overflow, which lead to results too large to represent as conventional floating-point values.

How to integrate a function in MATLAB using Trapz? ›

Q = trapz(___, dim ) integrates along the dimension dim using any of the previous syntaxes. You must specify Y , and optionally can specify X . If you specify X , then it can be a scalar or a vector with length equal to size(Y,dim) . For example, if Y is a matrix, then trapz(X,Y,2) integrates each row of Y .

References

Top Articles
Latest Posts
Article information

Author: Lakeisha Bayer VM

Last Updated:

Views: 5920

Rating: 4.9 / 5 (49 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Lakeisha Bayer VM

Birthday: 1997-10-17

Address: Suite 835 34136 Adrian Mountains, Floydton, UT 81036

Phone: +3571527672278

Job: Manufacturing Agent

Hobby: Skimboarding, Photography, Roller skating, Knife making, Paintball, Embroidery, Gunsmithing

Introduction: My name is Lakeisha Bayer VM, I am a brainy, kind, enchanting, healthy, lovely, clean, witty person who loves writing and wants to share my knowledge and understanding with you.