# changeIntegrationVariable

Integration by substitution

## Description

example

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.

## Examples

collapse all

Apply a change of variable to the definite integral ${\int }_{\mathit{a}}^{\mathit{b}}\mathit{f}\left(\mathit{x}+\mathit{c}\right)\text{\hspace{0.17em}}\mathit{dx}$.

Define the integral.

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

${\int }_{a}^{b}f\left(c+x\right)\mathrm{d}x$

Change the variable $\mathit{x}+\mathit{c}$ in the integral to $\mathit{y}$.

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

${\int }_{a+c}^{b+c}f\left(y\right)\mathrm{d}y$

Find the integral of $\int \mathrm{cos}\left(\mathrm{log}\left(\mathit{x}\right)\right)\mathit{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 =

$\int \mathrm{cos}\left(\mathrm{log}\left(x\right)\right)\mathrm{d}x$

Substitute the expression log(x) with t.

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

$\int {\mathrm{e}}^{t} \mathrm{cos}\left(t\right)\mathrm{d}t$

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

H = release(G)
H =

$\frac{{\mathrm{e}}^{t} \left(\mathrm{cos}\left(t\right)+\mathrm{sin}\left(t\right)\right)}{2}$

Restore log(x) in place of t.

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

$\frac{\sqrt{2} x \mathrm{sin}\left(\frac{\pi }{4}+\mathrm{log}\left(x\right)\right)}{2}$

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

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

$\frac{\sqrt{2} x \mathrm{sin}\left(\frac{\pi }{4}+\mathrm{log}\left(x\right)\right)}{2}$

Find the closed-form solution of the integral $\int \mathit{x}\text{\hspace{0.17em}}\mathrm{tan}\left(\mathrm{log}\left(\mathit{x}\right)\right)\mathit{dx}$.

Define the integral using the int function.

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

$\int x \mathrm{tan}\left(\mathrm{log}\left(x\right)\right)\mathrm{d}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 =

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

Compute the integral ${\int }_{0}^{1}{\mathit{e}}^{\sqrt{\mathrm{sin}\left(\mathit{x}\right)}}\mathit{dx}$ numerically with high precision.

Define the integral ${\int }_{0}^{1}{\mathit{e}}^{\sqrt{\mathrm{sin}\left(\mathit{x}\right)}}\mathit{dx}$. A closed-form solution to the integral does not exist.

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

${\int }_{0}^{1}{\mathrm{e}}^{\sqrt{\mathrm{sin}\left(x\right)}}\mathrm{d}x$

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

F10 = vpa(F,10)
F10 = $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.944268879$

The vpa function cannot find the numerical integration to 70 significant digits and it returns the unevaluated integral.

F70 = vpa(F,70)
F70 =

${\int }_{0}^{1}{\mathrm{e}}^{\sqrt{\mathrm{sin}\left(x\right)}}\mathrm{d}x$

To find the numerical integration with high precision, you can perform a change of variable. Substitute the expression $\sqrt{\mathrm{sin}\left(\mathit{x}\right)}$ with $\mathit{t}$. Compute the integral numerically to 70 significant digits.

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

${\int }_{0}^{\sqrt{\mathrm{sin}\left(1\right)}}\frac{2 t {\mathrm{e}}^{t}}{\sqrt{1-{t}^{4}}}\mathrm{d}t$

G70 = vpa(G,70)
G70 = $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.

collapse all

### Integration by Substitution

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

$\int f\left(g\left(x\right)\right)\text{\hspace{0.17em}}g\text{'}\left(x\right)\text{\hspace{0.17em}}dx={\left(\int f\left(t\right)\text{\hspace{0.17em}}dt\right)|}_{t=g\left(x\right)}$

and for definite integrals as

$\underset{a}{\overset{b}{\int }}f\left(g\left(x\right)\right)\text{\hspace{0.17em}}g\text{'}\left(x\right)\text{\hspace{0.17em}}dx=\underset{g\left(a\right)}{\overset{g\left(b\right)}{\int }}f\left(t\right)\text{\hspace{0.17em}}dt.$