Changing Variables and Other Calculus Tools

Itai Seggev, Wolfram Research

(RowDefault[, (Spacer1), , (Spacer1), ])  #WolframTechConf

ABSTRACT

In recent versions, we have added functionality to make the Wolfram Language more directly applicable to the calculus classroom.  I will focus, in particular, on the new functions ImplicitD, IntegrateChangeVariables, and DSolveChangeVariables.  Other calculus enhancements will be covered as time permits.

Or: how I learned to stop worrying and love the chain rule

Many calculus tools are built on the chain rule:

Implicit differentiation

Just an application of the chain rule

Integration change of variables [change of variables formula]

Built on top of the chain rule

Changing variables in DEs

A more advanced, yet still direct, application of the change of variables

This covers three major new calculus functions in 13.1

Time permitting, I’ll cover nice enhancements from 13.2 having nothing to do with the chain rule…

ImplicitD

A core topic in calculus

A direct application of the chain rule

(and the implicit function theorem)

Specify:

equation(s)

dependent variable(s)

independent variable(s)

optionally: expression to differentiate

Basic examples

Find ((∂y)/(∂x)), assuming y(x) is defined implicitly by (x^2)+(y^2)==1:

ImplicitD[(x^2)+(y^2)==1,y,x]

The same computation, more verbosely:

ImplicitD[y,(x^2)+(y^2)==1,y,x]

Compute (∂/(∂x))(y^2) under the same conditions:

ImplicitD[(y^2),(x^2)+(y^2)==1,y,x]

Compute (((∂^2)y)/(∂(x^2))):

ImplicitD[(x^2)+(y^2)==1,y,{x,2}]

Somewhat fancier examples:

Differentiate (e^(x+y+z)) w.r.t x along the curve defined by two equations:

ImplicitD[(E^(x+y+z)),{(x^2)+(y^3)+(z^4)==5,Log[x y]==z},{y,z},x]

Find {((∂y)/(∂x)),((∂z)/(∂x))} along the same curve:

ImplicitD[{(x^2)+(y^3)+(z^4)==5,Log[x y]==z},{y,z},x]

Compute (((∂^3)y)/(∂(x^2) ∂t)) assuming y is an implicit function of x and t:

ImplicitD[y^t==x,y,{x,2},t]

Find instead (Grad[y, {x,t}]) (notice the double list):

ImplicitD[y^t==x,y,{{x,t}}]

Application: tangents to a curve in 3D

Find the tangent to the curve defined by the following two equations:

curve={x^2+2y^2+3z^2==1,x y == z};

First, find the derivative of y and z with respect to x:

{yx,zx}=ImplicitD[curve,{y,z},x]

The tangent lines are then given parametrically by:

{x,y,z}+t {1,yx,zx}

Instead of finding equations defining these lines, we just create pictures. First, create lines from what we have:

tangents=InfiniteLine[{x,y,z},{1,yx,zx}]

Find some points on the curve:

SeedRandom[RandomGeneratorState[]];
points=FindInstance[Append[curve,2 y+3 x z!=0],{x,y,z},Reals,3,RandomSeeding->Inherited]

Visualize the curve along with the tangent lines at these three points:

Show[
Region[ImplicitRegion[curve,{x,y,z}],PlotTheme->{"Detailed","ThickLines"}],
Graphics3D[{{,PointSize[Large],Point[{x,y,z}]/.points},{,Thick,tangents/.points}}],
ImageSize->Medium,PlotRangePadding->.2]

Note: the curve is smooth, but at the extreme values of x (namely ±1), y and z are not locally defined as functions of x:

{{x,y,z},ImplicitD[curve,{x,z},y]}/.FindInstance[Append[curve,2 y+3 x z==0],{x,y,z},Reals,3]

IntegrateChangeVariables

Goes by a variety of names:

u-substitution (particularly univariate)

change of variables formula (particularly multivariate)

changing coordinate systems

reverse chain rule

Supports:

indefinite integrals

definite integrals

region integrals

Old variables inferred from integrals

Changes can be specified as equations or as coordinate systems

Indefinite Integrals

Perform the simple substitution u==(x^2):

IntegrateChangeVariables[(InactiveIntegrate[(E^(x^2)) x, x]),u,u==(x^2)]

Evaluate a rational integral using trigonometric substitution:

IntegrateChangeVariables[(InactiveIntegrate[(1/(1+(x^2))), x]),θ,x==Tan[θ]]

Activate[%] /.θ->ArcTan[x]

Rewrite a 4D integral in terms of hyperspherical coordinates:

IntegrateChangeVariables[Inactive[Integrate][1,w,x,y,z],{r,ψ,θ,φ},"Cartesian"->"Hyperspherical"]

Verify the answer using the change of variables formula:

CoordinateTransformData["Hyperspherical"->"Cartesian","MappingJacobianDeterminant",{r,ψ,θ,φ}]//Simplify

Since we started from Cartesian coordinates, this is also the "VolumeFactor" property of the target coordinates:

CoordinateChartData["Hyperspherical","VolumeFactor",{r,ψ,θ,φ}]

Definite Integrals

Evaluate a rational integral using trigonometric substitution:

IntegrateChangeVariables[(InactiveIntegrate[((4 z)/(((1+(z^2)))^2)), z, 0, 1]),x,x==2ArcTan[z]]

Substitute the endpoints into the antiderivative:

Apply[Subtract, - Cos[x] /. {{x->(π/2)},{x->0}}]

Verify the result:

Activate[(InactiveIntegrate[((4 z)/(((1+(z^2)))^2)), z, 0, 1])]

Convert an integral from cylindrical to spherical coordinates:

Note the variable name clash!

IntegrateChangeVariables[(InactiveIntegrate[(r^2) (Sqrt[(r^2)+(z^2)]), r, 0, 4, θ, 0, π, z, ((3 r)/4), 3]),{ρ,(Subscript[θ, s]),φ},"Cylindrical"->"Spherical"]

Verify the change:

Activate[%]

%==Activate[(InactiveIntegrate[(r^2) (Sqrt[(r^2)+(z^2)]), r, 0, 4, θ, 0, π, z, ((3 r)/4), 3])]

Compute the relevant Jacobian determinant:

CoordinateTransformData["Spherical"->"Cylindrical","MappingJacobianDeterminant",{ρ,(Subscript[θ, s]),φ}]

So we see one ρ comes from the determinant, one is equal to (Sqrt[(r^2)+(z^2)]) and then (ρ^2) (sin^2)(θ) comes from (r^2).

Gaussian Integrals

A classic problem is to compute the integrate ℐ==(InactiveIntegrate[exp(-(x^2)), x, -∞, ∞]):

ℐ=Inactive[Integrate][Exp[-x^2],{x,-∞,∞}]

The trick is to instead consider (ℐ^2)==(InactiveIntegrate[exp(-(x^2)-(y^2)), x, -∞, ∞, y, -∞, ∞]):

ℐ2=Inactive[Integrate][Exp[-x^2-y^2],{x,-∞,∞},{y,-∞,∞}]

Convert from Cartesian to polar coordinates:

IntegrateChangeVariables[ℐ2, {r,θ},"Cartesian"->"Polar"]

The θ integral is now trivial; apply a u-substitution to the r integral:

2π IntegrateChangeVariables[ (InactiveIntegrate[(E^(-(r^2)))r, r, 0, ∞]), u,r^2==u]

Evaluate using the fundamental theorem of calculus:

Apply[Subtract, - π Exp[-u] /. {{u->∞},{u->0}}]

Verify that ℐ in fact equals the square root of the foregoing result:

Activate[ℐ]==(Sqrt[π])

Visualize our hard work!

Plot[Callout[Exp[-(x^2)],(Sqrt[π]),],{x,-5,5},Filling->Axis]

DSolveChangeVariables

Definitely experimental

Supports all the main flavors of (N)DSolve(Value).

Tries to do a variety of techniques which are all broadly “changing variables”:

reparameterization

changing coordinate systems

separation of variables

Old dependent and independent variables inferred from input DSolve expression

Changes can be specified as equations or as coordinate systems

ODEs

Use the reparameterization x==exp(t) to transform the Cauchy-Euler to a constant coefficient ODE:

DSolveChangeVariables[(InactiveHead[DSolve])[(x^2) y''[x]+p x y'[x]+q y[x]==0,y,x],y,t,x==(E^t)]//Simplify

Reduce the non-linear Ricatti equation to linear form using the ansatz y(x)==(((x^(a+1)) η'(x))/(η(x))):

DSolveChangeVariables[(InactiveHead[DSolve])[y'[x]+(x^(-a-1)) ((y[x])^2)==(x^a),y[x],x],η,x,y[x]==(((x^(a+1)) η'[x])/(η[x]))]//Simplify

Make it explicitly linear by multiplying everything out:

MapAt[MultiplySides[#,η[x],Assumptions->η[x]!=0]&,%,{1}]//ExpandAll

Transform an ODE with an arbitrary coefficient function in it to the SHO equation:

DSolveChangeVariables[(InactiveHead[DSolve])[y''[x]+f[x] y'[x]+((((f[x])^2)/4)+((f'[x])/2)+a) y[x]==0,y,x],u,x,y[x]==u[x] Exp[-(1/2) ∫f[x]\[DifferentialD]x]]//FullSimplify

MapAt[DivideSides[#1,(E^(-(1/2) ∫f[x]\[DifferentialD]x)),Assumptions->(E^(-(1/2) ∫f[x]\[DifferentialD]x)) !=0 ]&,%,1]

PDEs

Transform a 3D Poisson's equation from Cartesian to the cylindrical coordinate system:

DSolveChangeVariables[(InactiveHead[DSolve])[Laplacian[u[x,y,z],{x,y,z}]==(z^2)((x^2)+(y^2)),u,{x,y,z}],u,{r,θ,(OverTilde[z])},"Cartesian"->"Cylindrical"]//Simplify

Attempt to transform the wave equation:

DSolveChangeVariables[(InactiveHead[DSolve])[Laplacian[u[x,y,z,t],{x,y,z}]-(((∂_({t,2}))u[x,y,z,t])/(c^2))==0,u,{x,y,z,t}],{u},{r,θ,(OverTilde[z]),(OverTilde[t])},"Cartesian"->"Cylindrical"]//Simplify

Need to only transform spatial coordinates:

DSolveChangeVariables[(InactiveHead[DSolve])[Laplacian[u[x,y,z,t],{x,y,z}]-(((∂_({t,2}))u[x,y,z,t])/(c^2))==0,u,{x,y,z,t}],{u},{r,θ,(OverTilde[z]),t},Thread[{x,y,z}==CoordinateTransform["Cylindrical"->"Cartesian",{r,θ,(OverTilde[z])}]]]//Simplify

Only transform the variables that need to be transformed:

(%/.(OverTilde[z])->z)==DSolveChangeVariables[(InactiveHead[DSolve])[Laplacian[u[x,y,z,t],{x,y,z}]-(((∂_({t,2}))u[x,y,z,t])/(c^2))==0,u,{x,y,z,t}],{u},{r,θ,z,t},Thread[{x,y}==CoordinateTransform["Polar"->"Cartesian",{r,θ}]]]//Simplify

Replace a bivariate function with a product of univariate ones:

DSolveChangeVariables[(InactiveHead[DSolve])[-(∂_({x,2}))u[x,t]+(∂_({t}))u[x,t]-(∂_({x}))(x u[x,t])==0,u,{x,t}],{X,T},{x,t},u[x,t]==Exp[-((x^2)/2)] X[x] T[t]]//Simplify

This is leads to separation of variables:

MapAt[Expand[((#)/(Exp[-((x^2)/2)] X[x] T[t]))]&,%,{{1,1}}]

Potpourri (aka, 13.2 features)

Power series

Can now get exact power series, returned as an inactive sum:

Asymptotic[Exp[x],{x,0,∞}]

Activate the result to reconstruct the function:

Activate[%]

Some related power series:

Asymptotic[{Sin[x],Cos[x]},{x,0,∞}]

Get the Maclaurin series along with convergence criteria:

Asymptotic[(1/(1-z)),{z,0,∞},GenerateConditions->True]

Compute a Taylor series:

Asymptotic[Log[z],{z,1,∞},GenerateConditions->True]

Undetermined coefficients

Many ODEs for which the method of undetermined coefficients gives simpler results than other methods are now automatically recognized.

A simple example

New:

DSolve[5y''[x]+2y[x]==x (E^(3x)) ,y,x]

Old:

DSolve[5y''[x]+2y[x]==x (E^(3x)) ,y,x]

A bit more complicated

DSolve[5y''[x]+2y'[x]-6y[x]==((x^3)+2x-1) (E^(-3x)) ,y,x]

Old:

DSolve[5y''[x]+2y'[x]-6y[x]==((x^3)+2x-1) (E^(-3x)) ,y,x]

I think I see a difference…

DSolve[Derivative[4][y][x]+Derivative[3][y][x]+2 y''[x]+3 y'[x]+4 y[x]==(x^2) Cos[x],y,x]

Versus old:

DSolve[Derivative[4][y][x]+Derivative[3][y][x]+2 y''[x]+3 y'[x]+4 y[x]==(x^2) Cos[x],y,x]

In conclusion

ImplicitD provides general implicit differentiation

IntegrateChangeVariables and DSolveChangeVariables provide a start on important variable change use cases

We continue to refine our calculus support

Come to our Office Hours at 15:30, downstairs

Questions?