Main Content


Integration by substitution



G = changeIntegrationVariable(F,old,new) applies integration by substitution to the integrals in F, in which old is replaced by new. old must depend on the previous integration variable of the integrals in F and new must depend on the new integration variable. For more information, see Integration by Substitution.

When specifying the integrals in F, you can return the unevaluated form of the integrals by using the int function with the 'Hold' option set to true. You can then use changeIntegrationVariable to show the steps of integration by substitution.


collapse all

Apply a change of variable to the definite integral abf(x+c)dx.

Define the integral.

syms f(x) y a b c
F = int(f(x+c),a,b)
F = 

abf(c+x)dxint(f(c + x), x, a, b)

Change the variable x+c in the integral to y.

G = changeIntegrationVariable(F,x+c,y)
G = 

a+cb+cf(y)dyint(f(y), y, a + c, b + c)

Find the integral of cos(log(x))dx using integration by substitution.

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

syms x t
F = int(cos(log(x)),'Hold',true)
F = 

cos(log(x))dxint(cos(log(x)), x, 'Hold = TRUE', true)

Substitute the expression log(x) with t.

G = changeIntegrationVariable(F,log(x),t) 
G = 

etcos(t)dtint(exp(t)*cos(t), t, 'Hold = TRUE', true)

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

H = release(G)
H = 

etcos(t)+sin(t)2(exp(t)*(cos(t) + sin(t)))/2

Restore log(x) in place of t.

H = simplify(subs(H,t,log(x)))
H = 

2xsin(π4+log(x))2(sqrt(sym(2))*x*sin(sym(pi)/4 + log(x)))/2

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

Fcalc = int(cos(log(x)))
Fcalc = 

2xsin(π4+log(x))2(sqrt(sym(2))*x*sin(sym(pi)/4 + log(x)))/2

Find the closed-form solution of the integral xtan(log(x))dx.

Define the integral using the int function.

syms x
F = int(x*tan(log(x)),x)
F = 

xtan(log(x))dxint(x*tan(log(x)), x)

The int function cannot find the closed-form solution of the integral.

Substitute the expression log(x) with t. Apply integration by substitution.

syms t
G = changeIntegrationVariable(F,log(x),t)
G = 

e2t2Fhypergeom1(1,-i; 1-i; -e2ti)i2+et2+2i2Fhypergeom1(1,1-i; 2-i; -e2ti)-14-14i(exp((2*t))*hypergeom([1, -sym(1i)], [1 - sym(1i)], -exp((2*t*sym(1i))))*sym(1i))/2 + exp((t*(sym(2) + 2i)))*hypergeom([1, 1 - sym(1i)], [2 - sym(1i)], -exp((2*t*sym(1i))))*(- sym(1/4) - sym(1/4)*sym(1i))

The closed-form solution is expressed in terms of hypergeometric functions. For more details on hypergeometric functions, see hypergeom.

Compute the integral 01esin(x)dx numerically with high precision.

Define the integral 01esin(x)dx. A closed-form solution to the integral does not exist.

syms x
F = int(exp(sqrt(sin(x))),x,0,1)
F = 

01esin(x)dxint(exp(sqrt(sin(x))), x, 0, 1)

You can use vpa to compute the integral numerically to 10 significant digits.

F10 = vpa(F,10)
F10 = 1.944268879vpa('1.944268879')

Alternatively, you can use the vpaintegral function and specify the relative error tolerance.

Fvpa = vpaintegral(exp(sqrt(sin(x))),x,0,1,'RelTol',1e-10)
Fvpa = 1.944268879vpa('1.944268879')

The vpa function cannot find the numerical integration to 70 significant digits, and it returns the unevaluated integral in the form of vpaintegral.

F70 = vpa(F,70)
F70 = 1.944268879138581167466225761060083173280747314051712224507065962575967vpa('1.944268879138581167466225761060083173280747314051712224507065962575967')

To find the numerical integration with high precision, you can perform a change of variable. Substitute the expression sin(x) with t. Compute the integral numerically to 70 significant digits.

syms t;
G = changeIntegrationVariable(F,sqrt(sin(x)),t)
G = 

0sin(1)2tet1-t4dtint((2*t*exp(t))/sqrt(1 - t^4), t, 0, sqrt(sin(sym(1))))

G70 = vpa(G,70)
G70 = 1.944268879138581167466225761060083173280747314051712224507065962575967vpa('1.944268879138581167466225761060083173280747314051712224507065962575967')

Input Arguments

collapse all

Expression containing integrals, specified as a symbolic expression, function, vector, or matrix.

Subexpression to be substituted, specified as a symbolic scalar variable, expression, or function. old must depend on the previous integration variable of the integrals in F.

New subexpression, specified as a symbolic scalar variable, expression, or function. new must depend on the new integration variable.

More About

collapse all

Integration by Substitution

Mathematically, the substitution rule is formally defined for indefinite integrals as


and for definite integrals as


Introduced in R2019b