Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
133 views

Differential Equation Solving With DSolve

Differential Equation Solving With DSolve used Mathematica the most powerful math software

Uploaded by

xxleonard
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
133 views

Differential Equation Solving With DSolve

Differential Equation Solving With DSolve used Mathematica the most powerful math software

Uploaded by

xxleonard
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 118

Wolfram Mathematica Tutorial Collection

DIFFERENTIAL EQUATION SOLVING WITH DSOLVE

For use with Wolfram Mathematica 7.0 and later.

For the latest updates and corrections to this manual: visit reference.wolfram.com For information on additional copies of this documentation: visit the Customer Service website at www.wolfram.com/services/customerservice or email Customer Service at info@wolfram.com Comments on this manual are welcomed at: comments@wolfram.com Content authored by: Devendra Kapadia

Printed in the United States of America. 15 14 13 12 11 10 9 8 7 6 5 4 3 2

2008 Wolfram Research, Inc. All rights reserved. No part of this document may be reproduced or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without the prior written permission of the copyright holder. Wolfram Research is the holder of the copyright to the Wolfram Mathematica software system ("Software") described in this document, including without limitation such aspects of the system as its code, structure, sequence, organization, look and feel, programming language, and compilation of command names. Use of the Software unless pursuant to the terms of a license granted by Wolfram Research or as otherwise authorized by law is an infringement of the copyright. Wolfram Research, Inc. and Wolfram Media, Inc. ("Wolfram") make no representations, express, statutory, or implied, with respect to the Software (or any aspect thereof), including, without limitation, any implied warranties of merchantability, interoperability, or fitness for a particular purpose, all of which are expressly disclaimed. Wolfram does not warrant that the functions of the Software will meet your requirements or that the operation of the Software will be uninterrupted or error free. As such, Wolfram does not recommend the use of the software described in this document for applications in which errors or omissions could threaten life, injury or significant loss. Mathematica, MathLink, and MathSource are registered trademarks of Wolfram Research, Inc. J/Link, MathLM, .NET/Link, and webMathematica are trademarks of Wolfram Research, Inc. Windows is a registered trademark of Microsoft Corporation in the United States and other countries. Macintosh is a registered trademark of Apple Computer, Inc. All other trademarks used herein are the property of their respective owners. Mathematica is not associated with Mathematica Policy Research, Inc.

Contents
Introduction to Differential Equation Solving with DSolve . . . . . . . . . . . . . . . . . . . . . . Classification of Differential Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ordinary Differential Equations (ODEs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Overview of ODEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . First-Order ODEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Linear Second-Order ODEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Nonlinear Second-Order ODEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Higher-Order ODEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Systems of ODEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Lie Symmetry Methods for Solving Nonlinear ODEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 7 11 11 12 24 33 36 42 50 55 55 56 66 70 70 71 76 76 77 82 85 89 89 90 94 98

Partial Differential Equations (PDEs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Introduction to PDEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . First-Order PDEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Second-Order PDEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Differential-Algebraic Equations (DAEs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Introduction to DAEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Examples of DAEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Initial and Boundary Value Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Introduction to Initial and Boundary Value Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . Linear IVPs and BVPs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Nonlinear IVPs and BVPs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . IVPs with Piecewise Coefficients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Working with DSolve~A Users Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Setting Up the Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Verification of the Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Plotting the Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The GenerateParameters Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 Symbolic Parameters and Inexact Quantities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 Is the Problem Well-Posed? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

Introduction to Differential Equation Solving with DSolve


The Mathematica function DSolve finds symbolic solutions to differential equations. (The Mathematica function NDSolve , on the other hand, is a general numerical differential equation solver.) DSolve can handle the following types of equations: Ordinary Differential Equations (ODEs), in which there is a single independent variable t and one or more dependent variables xi HtL. DSolve is equipped with a wide variety of techniques for solving single ODEs as well as systems of ODEs. Partial Differential Equations (PDEs), in which there are two or more independent variables and one dependent variable. Finding exact symbolic solutions of PDEs is a difficult problem, but DSolve can solve most first-order PDEs and a limited number of the second-order PDEs found in standard reference books. Differential-Algebraic Equations (DAEs), in which some members of the system are differential equations and the others are purely algebraic, having no derivatives in them. As with PDEs, it is difficult to find exact solutions to DAEs, but DSolve can solve many examples of such systems that occur in applications.
solve a differential equation for y@xD

DSolve@eqn,y@xD,xD

DSolve@8eqn1 ,eqn2 ,<,8y1 @xD,y2 @xD,<,xD


solve a system of differential equations for yi @xD
Finding symbolic solutions to ordinary differential equations.

DSolve returns results as lists of rules. This makes it possible to return multiple solutions to an equation. For a system of equations, possibly multiple solution sets are grouped together. You can use the rules to substitute the solutions into other calculations.
This finds the general solution for the given ODE. A rule for the function that satisfies the equation is returned.
In[1]:=

DSolve@8y '@xD y@xD<, y@xD, xD

x Out[1]= 99y@xD C@1D==

Differential Equation Solving with DSolve

You can pick out a specific solution by using . (ReplaceAll ).


In[2]:=

y@xD . DSolve@8y '@xD y@xD<, y@xD, xD

x Out[2]= 9 C@1D=

A general solution contains arbitrary parameters C @iD that can be varied to produce particular solutions for the equation. When an adequate number of initial conditions are specified, DSolve returns particular solutions to the given equations.
Here, the initial condition y@0D == 1 is specified, and DSolve returns a particular solution for the problem.
In[3]:=

sol = DSolve@8y '@xD y@xD, y@0D 1<, y@xD, xD

x Out[3]= 99y@xD ==

This plots the solution. ReplaceAll (.) is used in the Plot command to substitute the solution for y@xD.
In[4]:=

Plot@y@xD . sol, 8x, - 3, 2<D


7 6 5

Out[4]=

4 3 2 1 -3 -2 -1 1 2

DSolve@eqn,y,xD DSolve@8eqn1 ,eqn2 ,<,8y1 ,y2 ,<,xD

solve a differential equation for y as a pure function

solve a system of differential equations for the pure functions yi


Finding symbolic solutions to ordinary differential equations as pure functions.

When the second argument to DSolve is specified as y instead of y@xD, the solution is returned as a pure function. This form is useful for verifying the solution of the ODE and for using the solution in further work. More details are given in "Setting Up the Problem".

Differential Equation Solving with DSolve

The solution to this differential equation is given as a pure function.


In[5]:=

eqn = 8y '@xD y@xD ^ 2, y@0D 1<; sol = DSolve@eqn, y, xD


1 1-x F>>

Out[6]= ::y FunctionB8x<,

This verifies the solution.


In[7]:=

eqn . sol

Out[7]= 88True, True<<

This solves a system of ODEs. Each solution is labeled according to the name of the function (here, x and y), making it easier to pick out individual functions.
In[8]:=

eqns = 8Ht ^ 2 + 1L * x '@tD - t * x@tD + y@tD - Sign@tD, Ht ^ 2 + 1L * y '@tD - x@tD - t * y@tD + t * UnitStep@tD, x@0D - 1 2, y@0D 2<; sol = DSolve@eqns, 8x, y<, tD
-1 + 4 t + 2 ! ArcTan@tD t 0 -t True
1

+2t

LogA1 + t2 E t 0 True F,

Out[9]= ::x FunctionB8t<,

2 I1 + t2 M 4+t-2t ! y FunctionB8t<, 2 I1 + t M
2

ArcTan@tD t 0 -t True

+2

LogA1 + t2 E t 0 True F>>

This substitutes a random value for the independent variable and shows that the solutions are correct at that point.
In[10]:=

eqns . sol . 8t RandomReal@D<

Out[10]= 88True, True, True, True<<

This plots the solutions.


In[11]:=

Plot@8x@tD . sol, y@tD . sol<, 8t, - 10, 10<D


2

Out[11]=
-10 -5 5 10

-1

DSolve@eqn,u@x,yD,8x,y<D

solve a partial differential equation for u@x, yD

Finding symbolic solutions to partial differential equations.

While general solutions to ordinary differential equations involve arbitrary constants, general

Differential Equation Solving with DSolve

While general solutions to ordinary differential equations involve arbitrary constants, general solutions to partial differential equations involve arbitrary functions. DSolve labels these arbitrary functions as C @iD.
Here is the general solution to a linear first-order PDE. In the solution, C @1D labels an arbitrary function of
In[12]:=

-x+y xy

eqn = x ^ 2 * D@u@x, yD, xD + y ^ 2 * D@u@x, yD, yD - Hx + yL * u@x, yD; sol = DSolve@eqn 0, u, 8x, y<D
-x + y xy FF>>

Out[13]= ::u FunctionB8x, y<, -x y C@1DB

This obtains a particular solution to the PDE for a specific choice of C @1D.
In[14]:=

fn = u@x, yD . sol@@1DD . 8C@1D@t_D Sin@t ^ 2D + Ht 10L<


-x + y 10 x y + SinB H-x + yL2 x2 y2 F

Out[14]= -x y

Here is a plot of the surface for this solution.


In[15]:=

Plot3D@fn, 8x, - 5, 5<, 8y, - 5, 5<D

Out[15]=

DSolve can also solve differential-algebraic equations. The syntax is the same as for a system of ordinary differential equations.
This solves a DAE.
In[16]:=

eqns = 8f ''@xD == g@xD, f@xD + g@xD == 3 Sin@xD, f@PiD == 1, f '@PiD == 0<; sol = DSolve@eqns, 8f, g<, xD
1 2 1 2 H-2 Cos@xD + 3 p Cos@xD - 3 x Cos@xD + 3 Sin@xDLF, H2 Cos@xD - 3 p Cos@xD + 3 x Cos@xD + 3 Sin@xDLF>>

Out[17]= ::f FunctionB8x<,

g FunctionB8x<,

This verifies the solutions.

Differential Equation Solving with DSolve

This verifies the solutions.


In[18]:=

Simplify@eqns . solD

Out[18]= 88True, True, True, True<<

A plot of the solutions shows that their sum satisfies the algebraic relation f @xD + g@xD 3 Sin@xD.
In[19]:=

Plot@8f@xD . sol, g@xD . sol, f@xD + g@xD . sol<, 8x, - 5, 5<D

Out[19]=
-4 -2 2 4

-5

Goals of Differential Equation Solving with DSolve Tutorials


The design of DSolve is modular: the algorithms for different classes of problems work independently of one another. Once a problem has been classified (as described in "Classification of Differential Equations"), the available methods for that class are tried in a specific sequence until a solution is obtained. The code has a hierarchical structure whereby the solution of complex problems is reduced to the solution of relatively simpler problems, for which a greater variety of methods is available. For example, higher-order ODEs are typically solved by reducing their order to 1 or 2. The process described is done internally and does not require any intervention from the user. For this reason, these tutorials have the following basic goals. To provide enough information and tips so that users can pose problems to DSolve in the most appropriate form and apply the solutions in their work. This is accomplished through a substantial number of examples. A summary of this information is given in "Working with DSolve". To give a catalog of the kinds of problems that can be handled by DSolve as well as the nature of the solutions for each case. This is provided in the tutorials on ODEs, PDEs, DAEs, and boundary value problems (BVPs). The author hopes that these Differential Equation Solving with DSolve tutorials will be useful in acquiring a basic knowledge of DSolve and also serve as a ready reference for information on more advanced topics.

Differential Equation Solving with DSolve

The author hopes that these Differential Equation Solving with DSolve tutorials will be useful in acquiring a basic knowledge of DSolve and also serve as a ready reference for information on more advanced topics.

Differential Equation Solving with DSolve

Classification of Differential Equations


While differential equations have three basic types~ordinary (ODEs), partial (PDEs), or differential-algebraic (DAEs), they can be further described by attributes such as order, linearity, and degree. The solution method used by DSolve and the nature of the solutions depend heavily on the class of equation being solved. The order of a differential equation is the order of the highest derivative in the equation.
This is a first-order ODE because its highest derivative is of order 1.
In[1]:=

DSolve@x ^ 2 H1 - x ^ 2L * y '@xD Hx - 3 x ^ 3 - y@xDL y@xD, y@xD, xD


-x + x3 C@1D - Log@xD >>

Out[1]= ::y@xD

Here is the general solution to a fourth-order ODE.


In[2]:=

DSolve@y ''''@xD - 16 * y@xD x ^ 2, y@xD, xD


x2 16 + 2 x C@1D + -2 x C@3D + C@2D Cos@2 xD + C@4D Sin@2 xD>>

Out[2]= ::y@xD -

A differential equation is linear if the equation is of the first degree in y and its derivatives, and if the coefficients are functions of the independent variable.
This is a nonlinear second-order ODE that represents the motion of a circular pendulum. It is nonlinear because Sin@ y@ xDD is not a linear function of y@ xD. The Solve::ifun warning message appears because Solve uses JacobiAmplitude (the inverse of EllipticF) to find an expression for y@ xD.
In[3]:=

sol = DSolve@y ''@xD + 3 * Sin@y@xDD 0, y, xD


Solve::ifun : Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.

Out[3]= ::y FunctionB8x<, -2 JacobiAmplitudeB

:y FunctionB8x<, 2 JacobiAmplitudeB

2 1 2

FF>, 6 + C@1D 12 H6 + C@1DL Hx + C@2DL2 , FF>> 6 + C@1D

H6 + C@1DL Hx + C@2DL2 ,

12

Differential Equation Solving with DSolve

This plots the solutions. The discontinuity in the graphs at x = -3 results from the choice of inverse functions used by Solve .
In[4]:=

Plot@8y@xD . sol@@1DD . 8C@1D - 1, C@2D 3<, y@xD . sol@@2DD . 8C@1D - 1, C@2D 3<<, 8x, - 5, 5<D
1.0 0.5

Out[4]=

-4

-2 -0.5 -1.0

It should be noted that sometimes the solutions to fairly simple nonlinear equations are only available in implicit form. In these cases, DSolve returns an unevaluated Solve object.
This nonlinear differential equation only has an implicit solution. The Solve::tdep messages can be ignored; they appear because Solve cannot find an explicit expression for y@ xD because non-algebraic functions (ArcTan and Log) are involved.
In[5]:=

DSolve@Hy@xD + x - 1L * y '@xD - y@xD + 2 x + 3 0, y@xD, xD


Solve::tdep : The equations appear to involve the variables to be solved for in an essentially non-algebraic way. Solve::tdep : The equations appear to involve the variables to be solved for in an essentially non-algebraic way.
2 H2+3 xL -1+x+y@xD

Out[5]= SolveB

2 3

-2 + 2 ArcTanB 2

H-1 + x + y@xDL2 3 + F - LogB

H2+3 xL K-2+

2+3 x -1+x+y@xD

-1+x+y@xD

F C@1D + H2 + 3 xL
2

4 3

Log@2 + 3 xD, y F

When the coefficients of a linear ODE do not depend on x, the ODE is said to have constant coefficients.
This is an ODE with constant coefficients.
In[6]:=

eqn = y '''@xD + 3 * y ''@xD - 25 * y '@xD + 21 * y@xD; sol = DSolve@eqn 0, y@xD, xD

-7 x C@1D + x C@2D + 3 x C@3D== Out[7]= 99y@xD

The previous equation is also homogeneous: all terms contain y or derivatives of y and its righthand side is zero. Adding a function of the independent variable makes the equation inhomogeneous. The general solution to an inhomogeneous equation with constant coefficients is obtained by adding a particular integral to the solution to the corresponding homogeneous equation.
Here, x2 is added to the right-hand side of the previous equation, making the new equation inhomogeneous. The general solution to this new equation is the sum of the previous solution and a particular integral.

Differential Equation Solving with DSolve

Here, x2 is added to the right-hand side of the previous equation, making the new equation inhomogeneous. The general solution to this new equation is the sum of the previous solution and a particular integral.
In[8]:=

sol2 = DSolve@eqn x ^ 2, y@xD, xD


1124 + 1050 x + 441 x2 9261 + -7 x C@1D + x C@2D + 3 x C@3D>>

Out[8]= ::y@xD

When the coefficients of an ODE depend on x, the ODE is said to have variable coefficients. Since equations with variable coefficients that are rational functions of x have singularities that are easily classified, there are sophisticated algorithms available for solving them.
The coefficients of this equation are rational functions of x.
In[9]:=

sol = DSolve@8y ''@xD - HH1 xL - H3 H16 x ^ 2LLL * y@xD 0, y@1D 1, y '@1D 4<, y@xD, xD
1 8 -2-2
x

Out[9]= ::y@xD

J-11 4 + 19 4

N x14 >>

There is a close relationship between functions and differential equations. Starting with a function of almost any type, it is possible to construct a differential equation satisfied by that function. Conversely, any differential equation gives rise to one or more functions, in the form of solutions to that equation. In fact, many special functions from classical analysis have their origins in the solution of differential equations. Mathieu functions are one such class of special functions. Mathieu was interested in studying the vibrations of elliptical membranes. The eigenfunctions for the wave equation that describes this motion are given by products of Mathieu functions.
This linear second-order ODE with rational coefficients has a general solution given by Mathieu functions.
In[10]:=

DSolve@Ht - 1L Ht + 1L * y ''@tD + t * y '@tD + H- 2 - 6 * t ^ 2L * y@tD 0, y@tD, tD


3 3 , ArcCos@tDF + C@2D MathieuSB5, - , ArcCos@tDF>> 2 2

Out[10]= ::y@tD C@1D MathieuCB5, -

The presence of ArcCos@tD in the previous solution suggests that the equation can be given a simpler form using trigonometric functions. This is the form in which these equations were introduced by Mathieu in 1868.
In[11]:=

DSolve@y ''@xD + H3 Cos@2 xD + 5L y@xD == 0, y, xD


3 2 3 , xF + C@2D MathieuSB5, - , xFF>> 2

Out[11]= ::y FunctionB8x<, C@1D MathieuCB5, -

10

Differential Equation Solving with DSolve

This plots the surface for a particular product of solutions to this equation.
In[12]:=

Plot3DBMathieuCB5, -

3 2

, xF * MathieuSB5, -

3 2

, yF, 8x, - 3, 3<, 8y, - 3, 3<F

Out[12]=

The degree of a differential equation is the highest power of the highest-order derivative in the equation.
This is a first-order ODE of degree 2.
In[13]:=

sol = DSolve@8y '@xD ^ 2 1 - x ^ 2, y@0D 2<, y, xD


1 2 1 2 4-x 4+x 1 - x2 - ArcSin@xD F>, 1 - x2 + ArcSin@xD F>>

Out[13]= ::y FunctionB8x<,

:y FunctionB8x<,

The higher degree leads to non-uniqueness of the solution.


In[14]:=

Plot@8y@xD . sol@@1DD, y@xD . sol@@2DD<, 8x, 0, 1<D


2.5

Out[14]= 2.0

1.5

0.2

0.4

0.6

0.8

1.0

The examples in this tutorial have focused on the classification of ODEs. The classification of PDEs is similar but more involved. PDEs can also be classified by linearity or nonlinearity, order, degree, and constant or variable coefficients. More important is the classification that identifies a PDE as hyperbolic, parabolic, or elliptic. These classifications are discussed in further detail in "Second-Order PDEs".

Differential Equation Solving with DSolve

11

Ordinary Differential Equations (ODEs)


Overview of Ordinary Differential Equations (ODEs)
There are four major areas in the study of ordinary differential equations that are of interest in pure and applied science. Exact solutions, which are closed-form or implicit analytical expressions that satisfy the given problem. Numerical solutions, which are available for a wider class of problems, but are typically only valid over a limited range of the independent variables. Qualitative theory, which is concerned with the global properties of solutions and is particularly important in the modern approach to dynamical systems. Existence and uniqueness theorems, which guarantee that there are solutions with certain desirable properties provided a set of conditions is fulfilled by the differential equation. Of these four areas, the study of exact solutions has the longest history, dating back to the period just after the discovery of calculus by Sir Isaac Newton and Gottfried Wilhelm von Leibniz. The following table introduces the types of equations that can be solved by DSolve.

12

Differential Equation Solving with DSolve

name of equation

general form

date of discovery

mathematician

Separable Homogeneous Linear first-order ODE Bernoulli Riccati Exact first-order ODE Clairaut Linear with constant coefficients Hypergeometric Legendre Bessel Mathieu Abel Chini

y HxL ! f HxL gHyL y HxL !


x f J yHxL N

1691 1691 1694 1695


2

G. Leibniz G. Leibniz G. Leibniz James Bernoulli Count Riccati L. Euler A-C. Clairaut L. Euler L. Euler M. Legendre F. Bessel E. Mathieu N. H. Abel M. Chini

y HxL + PHxL yHxL ! QHxL y HxL + PHxL yHxL ! QHxL y HxL ! f HxL + gHxL yHxL + hHxL yHxL

1724 1734 1734 1743 1769 1785 1824 1868 1834 1924

M d x + N d y ! 0 with yHxL ! x y HxL + f Hy HxLL y HxL + an-1 y


HnL Hn-1L

!M !y

!N !x

HxL + + a0 yHxL ! PHxL

with a1 constant

xH1 - xL y HxL + Hc - Ha + b + 1L xL y HxL a b yHxL ! 0 I1 - x2 M y HxL - 2 x y HxL + nHn + 1L yHxL = 0 x2 y HxL + x y HxL + Ix2 - n2 M y HxL = 0 y HxL + Ha - 2 q cosH2 xLL yHxL = 0 y HxL ! f HxL + gHxL yHxL + hHxL yHxL2 + k HxL yHxL3 y HxL ! f HxL + g HxL y HxL + h HxL y HxLn

Examples of ODEs belonging to each of these types are given in other tutorials (clicking a link in the table will bring up the relevant examples).

First-Order ODEs
Straight Integration
This equation is solved by simply integrating the right-hand side with respect to x.
In[1]:=

sol = DSolve@y '@xD x ^ 2 * Sin@xD + Sqrt@1 + x ^ 2D, y, xD


1 2 x 1 + x2 + ArcSinh@xD 2 + C@1D - I-2 + x2 M Cos@xD + 2 x Sin@xDF>>

Out[1]= ::y FunctionB8x<,

Differential Equation Solving with DSolve

13

Here is a plot of the integral curves for different values of the arbitrary constant C @1D.
In[2]:= In[3]:=

tab = Table@y@xD . sol@@1DD . 8C@1D -> k<, 8k, - 80, 80, 40<D; Plot@Evaluate@tabD, 8x, 3, 18<D
400

300

200

Out[3]=
100

6 -100

10

12

14

16

18

Separable Equations
The general solution to this equation is found by separation of variables.
In[1]:=

DSolveBy @xD

x2 y@xD ^ 2 3 - x2

, y, xF
2

Out[1]= ::y FunctionB8x<,

F>>
x 3

3-x

- 3 ArcSinB

F - 2 C@1D

Even when variables can be separated, the final solution might be accompanied by a warning message from Solve , or it might only be given as an InverseFunction object.
Solving this ODE generates a warning message because Solve obtains an expression for y@xD using Log, the inverse of Exp. This warning message can be ignored.
In[2]:=

DSolveBy @xD

x2 Exp@y@xDD 3 - x2

, y, xF

Solve::ifun : Inverse functions are being used by Solve , so some solutions may not be found; use Reduce for complete solution information.
Out[2]= ::y FunctionB8x<, -LogB

1 2

3 - x2 -

3 2

ArcSinB

x 3

F - C@1DFF>>

14

Differential Equation Solving with DSolve

The solution to this equation is given as an InverseFunction object, in order to get an explicit expression for y@xD.
In[3]:=

sol = DSolveBy @xD 9-x


2

x2 Log@y@xDD * Sin@y@xDD

, y@xD, xF

InverseFunction::ifun : Inverse functions are being used. Values may be lost for multivalued inverses. InverseFunction::ifun : Inverse functions are being used. Values may be lost for multivalued inverses. Solve::tdep : The equations appear to involve the variables to be solved for in an essentially non-algebraic way.
Out[3]= ::y@xD InverseFunction@CosIntegral@1D - Cos@1D Log@1D &DB

1 2

-3 + x x

3 + x + 9 ArcSinhB

-3 + x 6

F + C@1DF>>

Homogeneous Equations
Here is a homogeneous equation in which the total degree of both the numerator and the denominator of the right-hand side is 2. The two parts of the solution list give branches of the integral curves in the form y = f HxL.
In[1]:=

eqn = y '@xD - Hx ^ 2 - 3 y@xD ^ 2L Hx * y@xDL; sol = DSolve@eqn, y, xD


x2 2 + x6 C@1D F>, :y FunctionB8x<, x2 2 + x6 C@1D F>>

Out[2]= ::y FunctionB8x<, -

This plots both branches together, showing the complete integral curves y2 ! C @1D x6 + several values of C @1D.
In[3]:= In[4]:= In[5]:=

x2 2

for

tab1 = Table@y@xD . sol@@1DD . C@1D k, 8k, 0, 3, 0.5<D; tab2 = Table@y@xD . sol@@2DD . C@1D k, 8k, 0, 3, 0.5<D; Plot@Evaluate@Join@tab1, tab2DD, 8x, 0, 1.7<D

Out[5]=

0.5 -2

1.0

1.5

-4

If an initial condition is specified, DSolve picks the branch that passes through the initial point. The DSolve::bvnul message indicates that one branch of the general solution (the lower

Differential Equation Solving with DSolve

15

If an initial condition is specified, DSolve picks the branch that passes through the initial point. The DSolve::bvnul message indicates that one branch of the general solution (the lower branch in the previous graph) did not give a solution satisfying the given initial condition y@1D 3.
In[6]:=

DSolve@8eqn, y@1D 3<, y@xD, xD


DSolve::bvnul : For some branches of the general solution, the given boundary conditions lead to an empty solution.
x2 I1 + 17 x4 M

Out[6]= ::y@xD

>> 2

Linear First-Order Equations


The following is a linear first-order ODE because both y@xD and y @ xD occur in it with power 1 and y @xD is the highest derivative. Note that the solution contains the imaginary error function Erfi .
In[1]:=

DSolve@y '@xD + x * y@xD Exp@3 xD, y@xD, xD


x2 2

Out[1]= ::y@xD

C@1D +

- 2

x2 2

p 2

ErfiB

3+x 2

F>>

Here is the solution for a more general linear first-order ODE. The K variables are used as dummy variables for integration. The Erfi term in the previous example comes from the integral in the second term of the general solution as follows.
In[2]:=

sol = DSolve@y '@xD + y@xD Q@xD, y@xD, xD


x 1

-x -x K@1D Q@K@1DD K@1D>> Out[2]= ::y@xD C@1D +

A more traditional form of the solution can be obtained by replacing K@1D with a variable such as t.
In[3]:=

sol . 8K@1D t<


x 1

-x -x t Out[3]= ::y@xD C@1D + Q@tD t>>

Inverse Linear Equations


It may happen that a given ODE is not linear in yHxL but can be viewed as a linear ODE in xHyL. In this case, it is said to be an inverse linear ODE.

16

Differential Equation Solving with DSolve

This is a inverse linear ODE. It is constructed by interchanging x and y in an earlier example.


In[1]:=

DSolve@y '@xD 1 H- x * y@xD + Exp@3 * y@xDDL, y@xD, xD


Solve::tdep : The equations appear to involve the variables to be solved for in an essentially non-algebraic way.
1 2

Out[1]= SolveBx

y@xD2

C@1D +

- 2

y@xD2 2

p 2

ErfiB

3 + y@xD 2

F, y@xDF

Bernoulli Equations
A Bernoulli equation is a first-order equation of the form y HxL + PHxL yHxL ! QHxLyHxLn . The problem of solving equations of this type was posed by James Bernoulli in 1695. A year later, in 1696, G. Leibniz showed that it can be reduced to a linear equation by a change of variable.
Here is an example of a Bernoulli equation.
In[1]:=

eqn = y '@xD + 11 x * y@xD x ^ 3 * y@xD ^ 3

3 3 Out[1]= 11 x y@xD + y @xD x y@xD

In[2]:=

sol = DSolve@eqn, y, xD
11 1 + 11 x2 + 121 11 x C@1D
2

Out[2]= ::y FunctionB8x<, -

F>, :y FunctionB8x<,

11 1 + 11 x2 + 121 11 x C@1D
2

F>>

This verifies that the solution is correct.


In[3]:=

eqn . sol Simplify

Out[3]= 8True, True<

In general, the solution to a Bernoulli equation will consist of n - 1 branches, where n is the degree of yHxL in the equation.

Differential Equation Solving with DSolve

17

Here is an example of a Bernoulli equation with n = 5. The solution has four branches.
In[4]:=

DSolve@3 x * y '@xD - 7 x * Log@xD * y@xD ^ 5 - y@xD 0, y@xD, xD


714 x13 I12 x73 + 7 C@1D - 28 x73 Log@xDM :y@xD 714 x13 I12 x73 + 7 C@1D - 28 x73 Log@xDM
14 14

Out[4]= ::y@xD -

>, :y@xD -

714 x13 I12 x73 + 7 C@1D - 28 x73 Log@xDM 714 x13


14

>,

>, :y@xD

>>
14

I12 x73 + 7 C@1D - 28 x73 Log@xDM

Riccati Equations
A Riccati equation is a first-order equation of the form y HxL ! f HxL + gHxL yHxL + hHxL yHxL2 . This equation was used by Count Riccati of Venice (1676|1754) to help in solving second-order ordinary differential equations. Solving Riccati equations is considerably more difficult than solving linear ODEs.
Here is a simple Riccati equation for which the solution is available in closed form.
In[1]:=

DSolve@y '@xD + H2 x ^ 2L - 3 y@xD ^ 2 0, y@xD, xD Simplify


3 x5 - 2 C@1D 3 x6 + 3 x C@1D >>

Out[1]= ::y@xD -

Any Riccati equation can be transformed to a second-order linear ODE. If the latter can be solved explicitly, then a solution for the Riccati equation can be derived.
Here is an example of a Riccati equation and the corresponding second-order ODE, which is Legendres equation.
In[2]:=

DSolve@u '@xD HH2 xL H1 - x ^ 2LL * u@xD - HH15 4L H1 - x ^ 2LL - u@xD ^ 2, u@xD, xD Simplify
5 3 5 , xF + C@1D LegendrePB , xF - x LegendreQB , xF + LegendreQB , xF 2 2 2 2 3 3 2 I-1 + x2 M C@1D LegendrePB , xF + LegendreQB , xF >> 2 2 3

Out[2]= ::u@xD 5 -x C@1D LegendrePB

In[3]:=

DSolve@H1 - x ^ 2L * y ''@xD - 2 x * y '@xD + H15 4L * y@xD 0, y@xD, xD


3 3 , xF + C@2D LegendreQB , xF>> 2 2

Out[3]= ::y@xD C@1D LegendrePB

18

Differential Equation Solving with DSolve

Finally, consider the following Riccati equation. It is integrable because the sum of the coefficients of the terms on the right-hand side is 0.
In[4]:= In[5]:= In[6]:=

eqn = y '@xD 3 x + 5 * y@xD - H3 x + 5L * y@xD ^ 2; RightHandSideCoeffs = 83 x, 5, - H3 x + 5L<; Total@RightHandSideCoeffs D

Out[6]= 0

In[7]:=

sol = DSolve@eqn, y, xD
-5 x-3 x C@1D +
1 12
2

Out[7]= ::y FunctionB8x<, 1 +

F>> 3 p ErfB
5+6 x 2 3

-6

-x H5+3 xL

+5

2512

This verifies the solution.


In[8]:=

eqn . sol Simplify

Out[8]= 8True<

Exact Equations
Here is an example of an exact ODE.
In[1]:= In[2]:= In[3]:=

P@x_, y_D := - H5 x ^ 2 - 2 y ^ 2 + 11L Q@x_, y_D := HSin@yD + 4 x * y + 3L Simplify@D@P@x, yD, yD - D@Q@x, yD, xDD

Out[3]= 0

In[4]:=

eqn = y '@xD == - P@x, y@xDD Q@x, y@xDD


11 + 5 x2 - 2 y@xD2 3 + Sin@y@xDD + 4 x y@xD

Out[4]= y @xD

In[5]:=

sol = DSolve@eqn, y@xD, xD


Solve::tdep : The equations appear to involve the variables to be solved for in an essentially non-algebraic way.

Out[5]= SolveB-11 x -

5 x3 3

- Cos@y@xDD + 3 y@xD + 2 x y@xD2 C@1D, y@xDF

Differential Equation Solving with DSolve

19

This verifies the solution.


In[6]:=

Solve@D@sol@@1DD, xD, y '@xDD Simplify


11 + 5 x2 - 2 y@xD2 3 + Sin@y@xDD + 4 x y@xD >>

Out[6]= ::y @xD

Here is a contour plot of the solution.


In[7]:=

ContourPlot@Evaluate@sol@@1, 1DD . 8y@xD y<D, 8x, - 5, 5<, 8y, - 5, 5<D

Out[7]=

If an equation is not exact, it may be possible to find an integrating factor (a multiplier for the functions P and Q, defined previously) that converts the equation into exact form. DSolve tries a variety of techniques to automatically find integrating factors in such situations.

Clairaut Equations
A Clairaut equation is a first-order equation of the form yHxL ! x y HxL + f Hy HxLL. A remarkable feature of this nonlinear equation is that its general solution has a very simple form.

20

Differential Equation Solving with DSolve

This is an example of a Clairaut equation. The warning message from Solve can be ignored. It is given because DSolve first tries to find an expression for y @xD from the given ODE.
In[1]:=

sol = DSolve@y@xD x * y '@xD + y '@xD ^ 2 + Exp@y '@xDD , y@xD, xD


Solve::tdep : The equations appear to involve the variables to be solved for in an essentially non-algebraic way.

C@1D + x C@1D + C@1D2 == Out[1]= 99y@xD

The general solution to Clairaut equations is simply a family of straight lines.


This plots the solution for several values of C @1D.
In[2]:=

Plot@Evaluate@Table@y@xD . sol . 8C@1D 1 k<, 8k, - 5, 5, 2<DD, 8x, 1, 5<D


8

Out[2]=
2

2 -2

Abel Equations
An Abel ODE is a first-order equation of the form y HxL ! f HxL + gHxL yHxL + hHxL yHxL2 + kHxL yHxL3 . This equation arose in the context of the studies of Niels Henrik Abel on the theory of elliptic functions, and represents a natural generalization of the Riccati equation. Associated with any Abel ODE is a sequence of expressions that is built from the coefficients of the equation 8 f0 , f1 , f2 , f3 < and invariant under certain coordinate transformations of the independent variable and the dependent variable. These invariants characterize each equation and can be used for identifying integrable classes of Abel ODEs. In particular, Abel ODEs with zero or constant invariants can be integrated easily and constitute an important integrable class of these equations.

Differential Equation Solving with DSolve

21

Here is the construction of a particular invariant with value 0 and the solution of the corresponding Abel ODE.
In[1]:=

f0 = 0; f1 =

1 x

; f2 = - 3; f3 = x; 1 3 2 f23 9

In[2]:=

Invariant = f0 f32 +

- f1 f3 f2 - !x f3 f2 + f3 !x f2

Out[2]= 0

In[3]:=

AbelODE = y @xD f0 + f1 y@xD + f2 y@xD2 + f3 y@xD3


y@xD x - 3 y@xD2 + x y@xD3

Out[3]= y @xD

In[4]:=

sol = DSolve@AbelODE, y, xD
1 x x2 1 x2

Out[4]= ::y FunctionB8x<,

1 + C@1D

F>, :y FunctionB8x<,

1 x

+ x2
1 x2

1 + C@1D

F>>

In[5]:=

AbelODE . sol Simplify

Out[5]= 8True, True<

In[6]:=

Clear@f0, f1, f2, f3D

Another important class of integrable Abel ODEs are those that can be reduced to inverse linear first-order ODEs using a nonlinear coordinate transformation.
This Abel ODE is solved by transforming it to an inverse linear first-order ODE. The ExpIntegralEi term in the solution to this equation comes from solving the linear ODE.
In[7]:=

DSolveBy @xD y@xD3 -

x y@xD2 x-1

, y@xD, xF

InverseFunction::ifun : Inverse functions are being used. Values may be lost for multivalued inverses. InverseFunction::ifun : Inverse functions are being used. Values may be lost for multivalued inverses. Solve::tdep : The equations appear to involve the variables to be solved for in an essentially non-algebraic way.

1-x+
1 y@xD

Out[7]= SolveB

+ C@1D + ExpIntegralEiB1 - x +

1 y@xD

F 0, y@xDF

-1 + x

Another important class of integrable Abel ODEs consists of those that can be transformed to an inverse Riccati equation. Since Riccati equations can be transformed to second-order linear ODEs, the solutions for this class are usually given in terms of special functions such as AiryAi and BesselJ .
This Abel ODE is solved by reducing it to an inverse Riccati equation.

22

Differential Equation Solving with DSolve

This Abel ODE is solved by reducing it to an inverse Riccati equation.


In[8]:=

AbelODE = y @xD ==
y@xD3 8 x2

y@xD3 8 x2

- y@xD2

2 Out[8]= y @xD -y@xD +

In[9]:=

sol = DSolve@AbelODE, y@xD, xD


InverseFunction::ifun : Inverse functions are being used. Values may be lost for multivalued inverses. InverseFunction::ifun : Inverse functions are being used. Values may be lost for multivalued inverses. InverseFunction::ifun : Inverse functions are being used. Values may be lost for multivalued inverses. General::stop : Further output of InverseFunction::ifun will be suppressed during this calculation. Solve::tdep : The equations appear to involve the variables to be solved for in an essentially non-algebraic way.

Out[9]= SolveB

C@1D + AiryAiPrimeB-

H-1L23 2 213 x

+ -H-2L13 x +

H-2L13 y@xD

F + AiryAiB-

H-1L23 2 213 x

+ -H-2L13 x +
2

H-2L13 y@xD

-H-2L13 x +

H-2L13 y@xD

AiryBiPrimeBH-2L13 y@xD
2

H-1L23 2 213 x

+ -H-2L13 x + H-2L13 y@xD

H-2L13 y@xD

F+

AiryBiB-

H-1L23 2 213 x

+ -H-2L13 x +

F -H-2L13 x +

0, y@xDF

This verifies the solution.


In[10]:=

Solve@D@sol@@1DD, xD, y '@xDD FullSimplify


1 8 y@xD2 -8 + y@xD x2 >>

Out[10]= ::y @xD

The Abel ODEs considered so far are said to be of the first kind. Abel ODEs of the second kind are given by the following general formula. y HxL ! f HxL + gHxL yHxL + hHxL yHxL2 + kHxL yHxL3 aHxL + bHxL yHxL

An Abel ODE of the second kind can be converted to an equation of the first kind with a coordinate transformation. Thus, the solution methods for this kind of Abel ODE are identical to the methods for equations of the first kind.

Differential Equation Solving with DSolve

23

Here is the solution for an Abel ODE of the second kind. In[11]:=
2x 9

+ x ^ 3 + y@xD y@xD , y@xD, xF

sol = DSolveBy @xD

Solve::tdep : The equations appear to involve the variables to be solved for in an essentially non-algebraic way. Solve::tdep : The equations appear to involve the variables to be solved for in an essentially non-algebraic way.
2 3x 2 y@xD x2
2 1 2 3 4 3 2 2 3x 2 y@xD x2 2 14 2 3x 2 y@xD x2 2 14

Out[11]= SolveBC@1D -1 +

3x 2

Hypergeometric2F1B , -

, y@xDF 2 12 3x

2 y@xD x2

This verifies the solution.


In[12]:=

Solve@D@sol@@1DD, xD, y '@xDD FullSimplify


2x 9

+ x3 >>

Out[12]= ::y @xD 1 +

y@xD

Chini Equations
Chini equations are a generalization of Abel and Riccati equations.
This solves a Chini equation.
In[1]:=

DSolve@y '@xD 5 * y@xD ^ 4 + 3 * x ^ H- 4 3L, y@xD, xD


Solve::tdep : The equations appear to involve the variables to be solved for in an essentially non-algebraic way. Solve::tdep : The equations appear to involve the variables to be solved for in an essentially non-algebraic way.
LogB-1 + J N
5 3 14

Ix43 M

14

y@xDF &F

14 34 5 1 - 45 14 &, Out[1]= SolveB-45 RootSumB-45 + 3 14

314 534 - 180 13 334 514 Ix43 M C@1D + x


13

Log@xD , y@xDF

Linear Second-Order ODEs

24

Differential Equation Solving with DSolve

Linear Second-Order ODEs


Overview of Linear Second-Order ODEs
Solving linear first-order ODEs is straightforward and only requires the use of a suitable integrating factor. In sharp contrast, there are a large number of methods available for handling linear second-order ODEs, but the solution to the general equation belonging to this class is still not available. Therefore the linear case is discussed in detail before moving on to nonlinear secondorder ODEs. The general linear second-order ODE has the form y" HxL + PHxL y HxL + QHxL yHxL ! RHxL. Here, PHxL, QHxL and RHxL are arbitrary functions of x. The term "linear" refers to the fact that the degree of each term in yHxL, y HxL and y" HxL is 1. (Thus, terms like yHxL2 or yHxL y" HxL would make the equation nonlinear.)

Linear Second-Order Equations with Constant Coefficients


The simplest type of linear second-order ODE is one with constant coefficients.
This linear second-order ODE has constant coefficients.
In[1]:=

sol = DSolve@y ''@xD + 5 * y '@xD - 6 y@xD 0, y, xD

-6 x C@1D + x C@2DE== Out[1]= 99y FunctionA8x<,

Notice that the general solution is a linear combination of two exponential functions. The arbitrary constants C @1D and C @2D can be varied to produce particular solutions.
This is one particular solution to the equation.
In[2]:=

sol1 = y@xD . sol@@1DD . 8C@1D 2, C@2D 3<

-6 x + 3 x Out[2]= 2

The exponents -6 and 1 in the basis 9-6 x , x = are obtained by solving the associated quadratic equation. This quadratic equation is called the auxiliary or characteristic equation.
This solves the auxiliary equation.

Differential Equation Solving with DSolve

25

This solves the auxiliary equation.


In[3]:=

Solve@m ^ 2 + 5 m - 6 0, mD

Out[3]= 88m -6<, 8m 1<<

The roots are real and distinct in this case. There are two other cases of interest: real and equal roots, and imaginary roots.
This example has real and equal roots.
In[4]:=

sol = DSolve@y ''@xD - 6 y '@xD + 9 y@xD 0, y, xD

3x 3x Out[4]= 99y FunctionA8x<, C@1D + x C@2DE==

In[5]:=

sol2 = y@xD . sol@@1DD . 8C@1D 2, C@2D 3<

3x 3x Out[5]= 2 + 3 x

This example has roots with nonzero imaginary parts.


In[6]:=

sol = DSolve@y ''@xD - y '@xD + y@xD 0, y, xD


3 x 2 F + x2 C@2D SinB 3 x 2 FF>>

x2 C@1D CosB Out[6]= ::y FunctionB8x<,

In[7]:=

sol3 = y@xD . sol@@1DD . 8C@1D 2, C@2D 3<


3 x 2 F + 3 x2 SinB 3 x 2 F

x2 CosB Out[7]= 2

Here is a plot of the three solutions.


In[8]:=

Plot@8sol1, sol2, sol3<, 8x, - 0.5, 0.5<D

15

10

Out[8]=

-0.4

-0.2

0.2

0.4

26

Differential Equation Solving with DSolve

Euler and Legendre Equations


An Euler equation has the general form x2 y HxL + a x y HxL + b yHxL ! 0. Euler equations can be solved by transforming them to equations with constant coefficients.
This is an example of an Euler equation.
In[1]:=

DSolve@x ^ 2 * y ''@xD + 5 * x * y '@xD + 6 * y@xD 0, y@xD, xD


C@2D CosB 2 Log@xDF C@1D SinB 2 Log@xDF + x2 x2 >>

Out[1]= ::y@xD

The Legendre linear equation is a generalization of the Euler equation. It is an ODE of the form Hc x + d L2 y HxL + a Hc x + d L y HxL + b yHxL ! 0.
Here is an example of a Legendre linear equation.
In[2]:=

DSolve@H3 x + 1L ^ 2 * y ''@xD + 5 * H3 x + 1L * y '@xD + 6 * y@xD 0, y@xD, xD


C@2D CosB
1 3

5 Log@1 + 3 xDF +

C@1D SinB

1 3

5 Log@1 + 3 xDF >>

Out[2]= ::y@xD

H1 + 3 xL13

H1 + 3 xL13

Exact Linear Second-Order Equations


A linear second-order ordinary differential equation a0 HxL y" HxL + a1 HxL y HxL + a2 HxL yHxL ! 0 is said to be exact if a0 " HxL - a1 HxL + a2 HxL ! 0. An exact linear second-order ODE is solved by reduction to a linear first-order ODE.
Here is an example. The appearance of the unevaluated integral in the solution is explained here.
In[1]:= In[2]:=

a0 = 1; a1 = Log@xD;

Differential Equation Solving with DSolve

27

In[3]:= In[4]:= In[5]:=

a2 = 1 x; eqn = a0 * y ''@xD + a1 * y '@xD + a2 * y@xD 0; conditionforexactness = HD@a0, 8x, 2<D - D@a1, xD + a2 0L

Out[5]= True

In[6]:=

sol = DSolve@eqn, y, xD
x 1

x-x Log@xD C@2D + x-x Log@xD -K@1D+K@1D Log@K@1DD C@1D K@1DF>> Out[6]= ::y FunctionB8x<,

This verifies the solution.


In[7]:=

eqn . sol FullSimplify

Out[7]= 8True<

In[8]:=

Clear@a0, a1, a2D

Linear Second-Order Equations with Solutions Involving Special Functions


DSolve can find solutions for most of the standard linear second-order ODEs that occur in applied mathematics.
Here is the solution for Airys equation.
In[1]:=

DSolve@y ''@xD - x * y@xD 0, y@xD, xD

Out[1]= 88y@xD AiryAi@xD C@1D + AiryBi@xD C@2D<<

Here is a plot that shows the oscillatory behavior of the Airy functions for large negative values of x.
In[2]:=

Plot@8AiryAi@xD, AiryBi@xD<, 8x, - 15, - 12<D


0.3

0.2

0.1

Out[2]=
-0.1

-14.5

-14.0

-13.5

-13.0

-12.5

-12.0

-0.2

-0.3

The solution to this equation is given in terms of the derivatives of the Airy functions, AiryAiPrime and AiryBiPrime .

28

Differential Equation Solving with DSolve

The solution to this equation is given in terms of the derivatives of the Airy functions, AiryAiPrime and AiryBiPrime .
In[3]:=

DSolve@ HHa * x + b LL * y ''@xD - a * y '@xD - Ha * Ha * x + bLL ^ 2 * y@xD == 0, y, xD

Out[3]= 88y Function@8x<, AiryAiPrime@b + a xD C@1D + AiryBiPrime@b + a xD C@2DD<<

Here is the solution for Bessels equation with n = 4. Note that the solution is given in terms of Bessel functions of the first kind, BesselJ , as well as those of the second kind, BesselY .
In[4]:=

DSolve@x ^ 2 * y ''@xD + x * y '@xD + Hx ^ 2 - 16L * y@xD 0, y@xD, xD

Out[4]= 88y@xD BesselJ@4, xD C@1D + BesselY@4, xD C@2D<<

Here is a plot of the BesselJ functions for specific values of n.


In[5]:=

Plot@8BesselJ@1, xD, BesselJ@3, xD, BesselJ@4, xD<, 8x, 0, 10<D


0.6

0.4

0.2

Out[5]=
2 4 6 8 10

-0.2

Here is the general solution for Legendres equation with n = 7.


In[6]:=

DSolve@16 H1 - x ^ 2L * y ''@xD - 32 x * y '@xD + 21 * y@xD 0, y@xD, xD


3 3 , xF + C@2D LegendreQB , xF>> 4 4

Out[6]= ::y@xD C@1D LegendrePB

These special functions can be expressed in terms of elementary functions for certain values of their parameters. Mathematica performs this conversion automatically wherever it is possible.
These are some of these expressions that are automatically converted.
In[7]:=

8BesselJ@1 2, xD, LegendreP@4, xD, HermiteH@5, xD<


2 p

Sin@xD , x

Out[7]= :

1 8

I3 - 30 x2 + 35 x4 M, 120 x - 160 x3 + 32 x5 >

As a result of these conversions, the solutions of certain ODEs can be partially expressed in terms of elementary functions. Hermites equation is one such ODE.
Here is the solution for Hermites equation with arbitrary n.

Differential Equation Solving with DSolve

29

Here is the solution for Hermites equation with arbitrary n.


In[8]:=

DSolve@y ''@xD - 2 x * y '@xD + 2 n * y@xD 0, y@xD, xD


n 2 , 1 2 , x2 F>>

Out[8]= ::y@xD C@1D HermiteH@n, xD + C@2D Hypergeometric1F1B-

With n set to 5, the solution is given in terms of polynomials, exponentials, and Erfi .
In[9]:=

Collect@Simplify@PowerExpand@ y@xD . DSolve@y ''@xD - 2 * x * y '@xD + 10 * y@xD 0, y@xD, xD@@1DDDD, 8C@1D, C@2D<D
1 8 I960 x - 1280 x3 + 256 x5 M C@1D + 1 8 C@2D J8 x - 18 x x2 + 4 x x4 +
2 2 2

Out[9]=

p x I-15 + 20 x2 - 4 x4 M Erfi@xDN

Linear Second-Order ODEs with Rational Coefficients


The hypergeometric functions play a unifying role in mathematical analysis since many important functions, such as the Bessel functions and Legendre functions, are special cases of them. Each hypergeometric function is associated with a linear ODE having rational coefficients.
Here is the ODE for the Hypergeometric2F1 function.
In[1]:=

DSolve@Hx ^ 2 - xL * y ''@xD + HHa + b + 1L * x - cL * y '@xD + b * a * y@xD 0, y@xD, xD


H-1L1-c x1-c C@2D Hypergeometric2F1@1 + a - c, 1 + b - c, 2 - c, xD==

Out[1]= 99y@xD C@1D Hypergeometric2F1@a, b, c, xD +

DSolve can solve a large class of second-order linear ODEs by reducing them to the ODEs for hypergeometric functions. The reduction involves coordinate transformations of both the independent and dependent variables.
This equation is equivalent to the ODE for Hypergeometric2F1.
In[2]:=

sol = DSolveA64 x2 Hx - 1L2 y ' '@xD + 32 x Hx - 1L H3 x - 1L y '@xD + H5 x - 21L y@xD == 0, y, xE


1

4
Out[2]= ::y FunctionB8x<,

H-2 Log@-1+xD-Log@xDL

C@1D Hypergeometric2F1B- , - , - , xF
8 8 4

H-1L14 4

H-2 Log@-1+xD-Log@xDL

3 7 9 x98 C@2D Hypergeometric2F1B , , , xFF>> 8 8 4

18

This verifies the solution using numerical values.


In[3]:=

64 x2 Hx - 1L2 y ' '@xD + 32 x Hx - 1L H3 x - 1L y '@xD + H5 x - 21L y@xD . sol@@1DD . 8x RandomComplex@D< Simplify Chop

Out[3]= 0

Solutions to this equation are returned in terms of HypergeometricU (the confluent hypergeometric function) and LaguerreL. This example appears on (equation 2.16, page 403 of [K59]).

30

Differential Equation Solving with DSolve

Solutions to this equation are returned in terms of HypergeometricU (the confluent hypergeometric function) and LaguerreL. This example appears on (equation 2.16, page 403 of [K59]).
In[4]:=

sol = Simplify@PowerExpand@y@xD . DSolve@ Derivative@2D@yD@xD + Ha * x ^ H2 * cL + b * x ^ Hc - 1LL * y@xD == 0, y, xD@@1DDDD


a x1+c -I1+cM2

Out[4]= 2 2+2 c

-c ,

C@1D HypergeometricUB-

c 1+c

a x1+c
2

-c , -

F + C@2D LaguerreLB

1 1+c

a x1+c
2

2+2c

-H1 + cL

2+2c

-H1 + cL

The ODEs for special functions have been studied since the eighteenth century. During the last thirty years, powerful algorithms have been developed for systematically solving ODEs with rational coefficients. An important algorithm of this type is Kovacics algorithm, a decision procedure that either generates a solution for the given ODE in terms of Liouvillian functions or proves that the given ODE does not have a Liouvillian solution.
This equation is solved using Kovacics algorithm.
In[5]:=

DSolve@x * y ''@xD + H10 x ^ 3 - 1L * y '@xD + 5 x ^ 2 H5 x ^ 3 + 1L * y@xD 0, y@xD, xD


5 x3 3

Out[5]= ::y@xD

C@1D +

1 2

5 x3 3

x2 C@2D>>

The solution returned from Kovacics algorithm may occasionally include functions such as ExpIntegralEi or an unevaluated integral of elementary functions because, while it is easy to find a second solution for a second-order linear ODE once one solution is known, the integral involved in finding the second solution may be hard to evaluate explicitly.
The solution to this equation is obtained using Kovacics algorithm. It includes ExpIntegralEi .
In[6]:=

DSolve@4 x * y ''@xD + H7 x + 12L * y '@xD + 21 y@xD 0, y@xD, xD


-7 x4 C@2D J16 7 x4 + 28 7 x4 x - 49 x2 ExpIntegralEiB
7x 4

FN >>

Out[6]= ::y@xD

-7 x4

C@1D 32 x2

In general, the solutions for linear ODEs with rational coefficients and order greater than one can be given in terms of DifferentialRoot objects. This is similar to the representation for solutions of polynomial equations in terms of Root .

Differential Equation Solving with DSolve

31

The solution to this equation is given in terms of DifferentialRoot .


In[7]:=

sol = DSolveAy ''@xD - x2 y '@xD - y@xD - 1 0 && y@0D 0 && y '@0D - 1, y, xE


DifferentialRootAFunctionA8 ", #<, 9-1 - "@#D - #2 " @#D + " @#D 0, "@0D 0, " @0D -1=EE@xDE==

Out[7]= 99y FunctionA8x<,

The solution may be evaluated and plotted in the usual way.


In[8]:=

Table@y@xD . sol@@1DD, 8x, - 1, 1, 0.4<D

Out[8]= 81.57269, 0.806671, 0.221252, -0.181388, -0.459045, -0.685918<

In[9]:=

Plot@y@xD . sol@@1DD, 8x, - 1, 1<D


1.5

1.0

Out[9]=

0.5

-1.0

-0.5 -0.5

0.5

1.0

Equations with Non-Rational Coefficients


The ODEs that arise in practical applications often have non-rational coefficients. In such cases, DSolve attempts to convert the equation into one with rational coefficients using a suitable coordinate transformation.
Here is an equation that has Exp@xD as a coefficient. It is solved by transforming it to Bessels equation.
In[1]:=

DSolve@y ''@xD - Exp@5 xD * y@xD == 0, y, xD


2 5 x 5 F C@1D + 2 BesselKB0, 2 5 x 5 F C@2DF>>

Out[1]= ::y FunctionB8x<, BesselIB0,

This equation (equation 2.437, page 507 of [K59]) has trigonometric coefficients. The solution is given in terms of elementary functions.
In[2]:=

DSolve@y ''@xD * Sin@xD * Cos@xD ^ 2 y '@xD * H3 * Sin@xD ^ 2 + 1L * Cos@xD - y@xD * Sin@xD ^ 3 == 0, y, xD


- 2 3 13 2

Out[2]= ::y FunctionB8x<, C@2D Cos@xD

+ C@1D Cos@xD

- +
2

13 2

F>>

Here is an equation with a hyperbolic function in the coefficient of y@xD. The solution is given in terms of Legendre functions.

32

Differential Equation Solving with DSolve

Here is an equation with a hyperbolic function in the coefficient of y@xD. The solution is given in terms of Legendre functions.
In[3]:=

DSolve@y ''@xD + Hk ^ 2 + 2 * Sech@xD ^ 2L y@xD == 0, y@xD, xD

Out[3]= 88y@xD C@1D LegendreP@1, k, Tanh@xDD + C@2D LegendreQ@1, k, Tanh@xDD<<

The solution to this equation is given in terms of HypergeometricU and LaguerreL.


In[4]:= In[5]:=

expr = y ''@xD + H- d + d H1 - Exp@- b xDL ^ 2L y@xD - l y@xD; sol = DSolve@expr 0, y, xD

Out[5]= ::y FunctionB8x<,


- d -b x + b l LogA-b x E

C@1D HypergeometricUBl LogA-b x E b

-b + 2

d -2 2b

, 1+ l

2 b

d -b x b

F+

d -b x +

C@2D LaguerreLB

-b + 2

d -2 2b

2 b

d b

-b x

FF>>

This verifies the solution using random values of x, b, d , and l.


In[6]:=

expr . sol@@1DD . 8x RandomComplex@D, b RandomComplex@D, d RandomComplex@D, l RandomComplex@D< Simplify Chop

Out[6]= 0

Inhomogeneous Linear Second-Order Equations


If the given second-order ODE is inhomogeneous, DSolve applies the method of variation of parameters to return a solution for the problem.
This solves an inhomogeneous linear second-order ODE. The solution is composed of two parts: the first part is the general solution to the homogeneous equation, and the second part is a particular solution to the inhomogeneous equation.
In[1]:=

sol = DSolve@x ^ 2 y ''@xD + y@xD x ^ 2, y@xD, xD


x C@1D CosB 1 2 1 2 x C@2D SinB 3 Log@xDF + 1 3 x2 CosB 1 2
2

Out[1]= ::y@xD

3 Log@xDF + 3 Log@xDF + x2 SinB 1 2


2

3 Log@xDF

>>

This solves the homogeneous equation, which is an Euler equation.


In[2]:=

DSolve@x ^ 2 y ''@xD + y@xD 0, y@xD, xD


x C@1D CosB 1 2 3 Log@xDF + x C@2D SinB 1 2 3 Log@xDF>>

Out[2]= ::y@xD

Different particular solutions can be obtained by varying the constants C @1D and C @2D in the solution.

Differential Equation Solving with DSolve

33

Different particular solutions can be obtained by varying the constants C @1D and C @2D in the solution.
In[3]:=

particularsolutions = Flatten@Table@y@xD . sol . 8C@1D i, C@2D j<, 8i, 0, 5, 3<, 8j, 1, 3<DD
x SinB 1 2 2 x SinB 1 2 3 x SinB 1 2 3 3 1 3 3 x SinB x CosB x CosB 1 2 1 2 x2 CosB 1 2 1 2 3 Log@xDF + 1 3
2

Out[3]= :

3 Log@xDF +

1 3

x2 CosB 1 3

1 2

3 Log@xDF + x2 SinB 1 2
2

1 2

3 Log@xDF 1 2

,
2

3 Log@xDF +

x2 CosB x2 CosB 1 2

3 Log@xDF + x2 SinB
2

3 Log@xDF
2

3 Log@xDF +

1 3

1 2

3 Log@xDF + x2 SinB 1 3

1 2

3 Log@xDF
2

, 1 2
2

3 Log@xDF + 3 Log@xDF + 2

x SinB

3 Log@xDF + 1 2

x2 CosB

1 2

3 Log@xDF + x2 SinB

3 Log@xDF

x SinB 1 2

3 Log@xDF +
2

3 Log@xDF + x2 SinB

3 Log@xDF 1 2

, 3
2

x CosB 1 2

1 2

3 Log@xDF +
2

x2 CosB

3 Log@xDF + x2 SinB

3 Log@xDF

>

In[4]:=

Plot@Evaluate@particularsolutionsD, 8x, 0.1, 2< D

Out[4]=
2

1.0

1.5

2.0

Nonlinear Second-Order ODEs


The general form of a nonlinear second-order ODE is FHx, y, y HxL, y HxLL ! 0. For simplicity, assume that the equation can be solved for the highest-order derivative y HxL to give y HxL ! f Hx, yHxL, y HxLL. There are a few classes of nonlinear second-order ODEs for which solutions can be easily found.

34

Differential Equation Solving with DSolve

There are a few classes of nonlinear second-order ODEs for which solutions can be easily found. The first class consists of equations that do not explicitly depend on yHxL; that is, equations of the form y HxL = f Hx, y HxLL. Such equations can be regarded as first-order ODEs in uHxL = y HxL.
Here is an example of this type.
In[1]:=

eqn = y @xD 5 x y @xD + y @xD2 ; sol = DSolve@eqn, y, xD


10 p ErfiB 5 2 xFFF>>

Out[1]= ::y FunctionB8x<, C@2D - LogB-10 C@1D +

As in the case of linear second-order ODEs, the solution depends on two arbitrary parameters C @1D and C @2D.
Here is a plot of the solution for a specific choice of parameters.
In[2]:=

Plot@Evaluate@y@xD . sol . 8C@1D - 1 2, C@2D - 1 8<D, 8x, - 0.4, 1<D

-0.4

-0.2 -1

0.2

0.4

0.6

0.8

1.0

Out[2]=
-2

-3

This verifies the solution.


In[3]:=

eqn . sol Simplify

Out[3]= 8True<

The second class of easily solvable nonlinear second-order equations consists of equations that do not depend explicitly on x or y HxL; that is, equations of the form y HxL ! f HyHxLL. These equations can be reduced to first-order ODEs with independent variable y. Inverse functions are needed to give the final solution for yHxL.

Differential Equation Solving with DSolve

35

Here is an example of this type.


In[4]:=

DSolve@y ''@xD == Exp@3 * y@xDD, y@xD, xD


Solve::ifun : Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.

Out[4]= ::y@xD LogB- -

3 2

13

-C@1D + C@1D TanhB 3 2 3 2


13

3 2

2 13

C@1D Hx + C@2DL2 F
2 13

F>,

:y@xD LogB

3 2

13

-C@1D + C@1D TanhB

C@1D Hx + C@2DL2 F 3 2

F>,
2 13

:y@xD LogBH-1L23

-C@1D + C@1D TanhB

C@1D Hx + C@2DL2 F

F>>

The third class consists of equations that do not depend explicitly on x; that is, equations of the form y HxL = f HyHxL, y HxLL. Once again, these equations can be reduced to first-order ODEs with independent variable y.
This example is based on (equation 6.40, page 550 of [K59]). The underlying first-order ODE is an Abel equation. The hyperbolic functions in the solution result from the automatic simplification of Bessel functions.
In[5]:=

sol = y@xD . DSolve@y ''@xD == 3 * y@xD * y '@xD + H3 y@xD ^ 2 + 4 * y@xD + 1L, y@xD, xD@@1DD Simplify
6 -2 x C@1D - 6 C@2D CoshB 3 2 3 2 3 2 3 2 -2 x C@1D F +

Out[5]=

-3 + 2

-2 x

C@1D C@2D SinhB

-2 x

C@1D F

6 C@2D CoshB

-2 x

C@1D F + 3 SinhB

-2 x

C@1D F

The fourth class consists of equations that are homogeneous in some or all of the variables x, yHxL, and y HxL. There are several possibilities in this case, but here only the following simple example is considered.
In this equation, each term has a total degree of 2 in the variables y@xD, y @ xD, and y @ xD. This equation can be solved by transforming it to a first-order ODE.
In[6]:=

DSolve@7 * y@xD * y ''@xD - 11 * y '@xD ^ 2 0, y@xD, xD


C@2D H4 x + 7 C@1DL74 >>

Out[6]= ::y@xD

The fifth and final class of easily solvable nonlinear second-order ODEs consists of equations that are exact or can be made to be exact using an integrating factor.

36

Differential Equation Solving with DSolve

The fifth and final class of easily solvable nonlinear second-order ODEs consists of equations that are exact or can be made to be exact using an integrating factor.
Here is an example of this type, based on (equation 6.51, page 554 of [K59]).
In[7]:= In[8]:=

eqn = y ''@xD + y@xD * y '@xD ^ 2 - x ^ 2 * y '@xD 0; sol = DSolve@eqn, y@xD, xD


Solve::ifun : Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.
3 2 p C@2D 313 2 p I-x3 M
23

C@1D GammaB ,3

x3 3

x2

Out[8]= ::y@xD -

2 InverseErfB 3p

F>>

It is important to note that the solutions to fairly simple-looking nonlinear ODEs can be complicated. Verifying and applying the solutions in such cases is a difficult problem.

Higher-Order ODEs
Overview of Higher-Order ODEs
The general form of an ODE with order n is FIx, yHxL, y HxL, y" HxL, , yHnL HxLM = 0. As in the case of second-order ODEs, such an ODE can be classified as linear or nonlinear. The general form of a linear ODE of order n is a0 HxL yHnL HxL + a1 HxL yHn-1L HxL + + an HxL yHxL = bHxL. If bHxL is the zero function, the equation is said to be homogeneous. This discussion is primarily restricted to that case. Many methods for solving linear second-order ODEs can be generalized to linear ODEs of order n, where n is greater than 2. If the order of the ODE is not important, it is simply called a linear ODE.

Differential Equation Solving with DSolve

37

Linear Higher-Order Equations with Constant Coefficients


A linear ODE with constant coefficients can be easily solved once the roots of the auxiliary equation (or characteristic equation) are known. Some examples of this type follow.
The characteristic equation of this ODE has real and distinct roots: 4, 1, and 7. Hence the solution is composed entirely of exponential functions.
In[1]:=

DSolve@y '''@xD - 4 * y ''@xD - 25 * y '@xD + 28 * y@xD 0, y@xD, xD

-4 x C@1D + x C@2D + 7 x C@3D== Out[1]= 99y@xD

The characteristic equation of this ODE has two pairs of equal roots: -3 and -5. The repeated roots give rise to the basis of the solutions, 93 x , x 3 x , 5 x , x 5 x =.
In[2]:=

DSolve@y ''''@xD - 16 * y '''@xD + 94 * y ''@xD - 240 * y '@xD + 225 * y@xD 0, y@xD, xD

3x 3x 5x 5x Out[2]= 99y@xD C@1D + x C@2D + C@3D + x C@4D==

The characteristic equation for this ODE has two pairs of roots with nonzero imaginary parts: 3 + 4 , 3 - 4 , 2 + , and 2 - . Hence the solution basis can be expressed with trigonometric and exponential functions.
In[3]:=

DSolve@y ''''@xD - 10 * y '''@xD + 54 * y ''@xD - 130 * y '@xD + 125 * y@xD 0, y@xD, xD

2x 3x 2x 3x Out[3]= 99y@xD C@2D Cos@xD + C@4D Cos@4 xD + C@1D Sin@xD + C@3D Sin@4 xD==

Finally, here is an example that combines all the previous kinds of solutions.
In[4]:=

DSolve@y '''''@xD - 17 * y ''''@xD + 108 * y '''@xD - 330 * y ''@xD + 488 * y '@xD - 280 * y@xD 0, y@xD, xD

2x 2x 7x 3x 3x Out[4]= 99y@xD C@3D + x C@4D + C@5D + C@2D Cos@xD + C@1D Sin@xD==

Higher-Order Euler and Legendre Equations


An Euler equation is an ODE of the form xn yHnL HxL + a1 xn-1 yHn-1L HxL + a2 xn-2 yHn-2L HxL + an yHxL ! 0.
The following is an example of an Euler equation.
In[1]:=

DSolve@ x ^ 4 * y ''''@xD - 2 * x ^ 3 * y '''@xD - x ^ 2 * y ''@xD + 5 * x * y '@xD + y@xD 0, y@xD, xD


2

RootA1-4 1+16 1 Out[1]= ::y@xD x

-8 13 +14 &,1E

C@1D + xRootA1-4 1+16 1

-8 13 +14 &,2E

C@2D +

RootA1-4 1+16 12 -8 13 +14 &,3E

C@3D + x

RootA1-4 1+16 12 -8 13 +14 &,4E

C@4D>>

The Legendre linear equation is a generalization of the Euler equation. It has the form

38

Differential Equation Solving with DSolve

The Legendre linear equation is a generalization of the Euler equation. It has the form Hc x + d Ln yHnL HxL + a1 Hc x + d Ln-1 yHn-1L HxL + a2 Hc x + d Ln-2 yHn-2L HxL + an yHxL ! 0.
This is a Legendre linear equation.
In[2]:=

DSolve@H3 x + 5L ^ 4 * y ''''@xD - 2 * H3 x + 5L ^ 3 * y '''@xD H3 x + 5L ^ 2 * y ''@xD + 5 * H3 x + 5L * y '@xD + y@xD 0, y@xD, xD


2

RootA1-570 1+1044 1 Out[2]= ::y@xD H5 + 3 xL

-540 13 +81 14 &,1E

C@1D + H5 + 3 xLRootA1-570 1+1044 1

-540 13 +81 14 &,2E

C@2D +

H5 + 3 xL

RootA1-570 1+1044 12 -540 13 +81 14 &,3E

C@3D + H5 + 3 xL

RootA1-570 1+1044 12 -540 13 +81 14 &,4E

C@4D>>

Exact Higher-Order Equations


A linear ordinary differential equation of order n a0 HxL yHnL HxM + a1 HxL yHn-1L HxL + + an-1 HxL y HxL + an HxL yHxL ! 0 is said to be exact if H-1Ln a0 HnL HxM + H-1LHn-1L a1 Hn-1L HxL + - an-1 HxL + an HxL ! 0. The condition of exactness can be used to reduce the problem to that of solving an equation of order n - 1.
This is an example of an exact ODE.
In[1]:= In[2]:= In[3]:= In[4]:= In[5]:=

a0 = 1; a1 = - 1 ; a2 = 5 x; a3 = 5; ExactODE = a0 * y '''@xD + a1 * y ''@xD + a2 * y '@xD + a3 * y@xD

H3L Out[5]= 5 y@xD + 5 x y @xD - y @xD + y @xD

This verifies the condition for exactness.


In[6]:=

conditionforexactness = - D@a0, 8x, 3<D + D@a1, 8x, 2<D - D@a2, xD + a3

Out[6]= 0

Differential Equation Solving with DSolve

39

This solves the equation.


In[7]:=

sol = DSolve@ExactODE 0, y, xD
H-1L13 J
1 4

- 5 xN F C@2D + x2 AiryBiBKA2E 2

H-1L13 J

1 4

- 5 xN F C@3D +

x2 AiryAiBOut[7]= ::y FunctionB8x<,

523
1 4

523
H-1L13 K -5 K@2DO

H-1L
x2

13

1 4

- 5 xN

H-1L23

p AiryAiB513

AiryBiB-

523

F 1

523

F C@1D K@2D +

H-1L13 J AiryAiB-

1 4

- 5 xN F

x 1

H-1L23

KA1E 2

H-1L13 K -5 K@1DO

1 4

p AiryBiB513

523

F C@1D K@1D F>>

523

This verifies the solution.


In[8]:=

ExactODE . sol@@1DD . 8x RandomReal@D, C@1D RandomReal@D, C@2D RandomReal@D< N Simplify Chop

Out[8]= 0

In[9]:=

Clear@a0, a1, a2, a3D

Further Examples of Exactly Solvable Higher-Order Equations


The solutions to many second-order ODEs can be expressed in terms of special functions. Solutions to certain higher-order ODEs can also be expressed using AiryAi, BesselJ , and other special functions.
The solution to this third-order ODE is given by products of Airy functions.
In[1]:=

sol1 = DSolve@y '''@xD - 4 * Hx + 2L * y '@xD - 2 * y@xD == 0, y, xD

2 2 Out[1]= 99y FunctionA8x<, AiryAi@2 + xD C@1D + AiryAi@2 + xD AiryBi@2 + xD C@2D + AiryBi@2 + xD C@3DE==

The solution to this third-order ODE is given by Bessel functions.


In[2]:=

sol2 = DSolve@ x ^ 3 * y '''@xD + 3 * x ^ 2 * y ''@xD + H4 x ^ 3 - 11 xL * y '@xD + 4 x ^ 2 * y@xD == 0, y, xD


2 2

Out[2]= ::y FunctionB8x<,

BesselJB

3 , xF C@1D + BesselJB

3 , xF BesselYB

3 , xF C@2D + BesselYB

3 , xF C@3DF>>

40

Differential Equation Solving with DSolve

This plot shows the oscillatory behavior of the solutions on different parts of the real line.
In[3]:=

Show@8Plot@y@xD . sol1 . 8C@1D 2, C@2D 3, C@3D 1<, 8x, - 10, - 4<, PlotStyle 8Red<D, Plot@y@xD . sol2 . 8C@1D 2, C@2D 3, C@3D 1<, 8x, 2, 10<, PlotStyle 8Dashing@80.02<D, Blue<D<, PlotRange 88- 10, 10<, Automatic<D
0.6

0.5

0.4

Out[3]= 0.3
0.2

0.1

-5

10

The solution to this fourth-order linear ODE is expressed in terms of HypergeometricPFQ.


In[4]:= In[5]:=

HypergeometricPFQTypeEquation = 30 * x ^ 3 * y ''''@xD + 193 * x ^ 2 * y '''@xD + H219 * x - 30 x ^ 2L * y ''@xD + H21 - 90 xL * y '@xD - 30 y@xD; sol3 = DSolve@HypergeometricPFQTypeEquation 0, y, xD
H-1L23 C@1D HypergeometricPFQB:- >, :- , 1 3 5 6 11 15

>, xF +

Out[5]= ::y FunctionB8x<,

7 9 41 , >, xF + x C@4D H-1L25 x25 C@3D HypergeometricPFQB: >, : 5 10 15 3 11 17 1 3 7 , >, xF + C@2D HypergeometricPFQB81, 1<, : , , >, xFF>> HypergeometricPFQB: >, : 2 10 6 2 5 3

x43

This verifies that the solution is correct using numerical values.


In[6]:=

HypergeometricPFQTypeEquation . sol3@@1DD . 8x RandomComplex@D< Simplify Chop

Out[6]= 0

As for second-order linear ODEs, there are modern algorithms for solving higher-order ODEs with rational coefficients. These algorithms give "rational-exponential" solutions, which are combinations of rational functions and exponentials of the integrals of rational functions. These algorithms are combined with techniques such as reduction of order to produce a complete solution for the given ODE.

Differential Equation Solving with DSolve

41

The general solution to this equation has a rational term and terms that depend on Airy functions. The Airy functions come from reducing the order of the equation to 2.
In[7]:=

DSolve@HH6 - 24 * x + 4 * x ^ 2 - 10 * x ^ 3 + 9 * x ^ 4 - 4 * x ^ 5 + x ^ 6L * y@xDL HH- 1 + xL ^ 4 * x ^ 2L + HH- 8 + 30 * x - 10 * x ^ 2 + 10 * x ^ 3 - 3 * x ^ 4 - 2 * x ^ 5 + x ^ 6L * Derivative@1D@yD@xDL HH- 1 + xL ^ 3 * x ^ 2L + HH4 - 16 * x + 5 * x ^ 2 - 2 * x ^ 3L * Derivative@2D@yD@xDL HH- 1 + xL ^ 2 * x ^ 2L + HH4 - x ^ 2L * Derivative@3D@yD@xDL HH- 1 + xL * xL == 0, y, xD
H-1 + xL C@1D -4 + x2 + H-1 + xL AiryAi@xD C@2D -4 + x2 + H-1 + xL AiryBi@xD C@3D -4 + x2 F>>

Out[7]= ::y FunctionB8x<,

The equations considered so far have been homogeneous; that is, with no term free of yHxL or its derivatives. If the given ODE is inhomogeneous, DSolve applies the method of variation of parameters to obtain the solution.
Here is an example of this type. The exponential terms in the solution come from the general solution to the homogeneous equation, and the remaining term is a particular solution (or particular integral) to the problem.
In[8]:=

sol = DSolve@y '''@xD - 13 * y ''@xD + 19 * y '@xD + 33 * y@xD Cos@2 xD, y@xD, xD


17 Cos@2 xD + 6 Sin@2 xD 1625 >>

-x 3x 11 x C@3D + Out[8]= ::y@xD C@1D + C@2D +

This is the general solution to the homogeneous equation.


In[9]:=

generalsolution = y@xD . DSolve@y '''@xD - 13 * y ''@xD + 19 * y '@xD + 33 * y@xD 0, y@xD, xD@@1DD

-x 3x 11 x C@3D Out[9]= C@1D + C@2D +

This particular solution is part of the general solution to the inhomogeneous equation.
In[10]:= Out[10]=

particularsolution = Hy@xD . sol@@1DDL - generalsolution


17 Cos@2 xD + 6 Sin@2 xD 1625

Thus, the general solution for the inhomogeneous equation is the sum of the general solution to the homogeneous equation and a particular integral of the ODE. The solution methods for nonlinear ODEs of higher order rely to a great extent on reducing the problem to one of lower order.

42

Differential Equation Solving with DSolve

Here is a nonlinear third-order ODE with no explicit dependence on x or y@xD. It is solved by reducing the order to 2 using a simple integration.
In[11]:=

DSolve@7 * y '@xD * y '''@xD - 11 * y ''@xD ^ 2 0, y@xD, xD


C@2D 3 H4 x + 7 C@1DL34 + C@3D>>

Out[11]= ::y@xD -

Systems of ODEs
Introduction to Systems of ODEs
Systems of ODEs are important in various fields of science, such as the study of electricity and population biology. Like single ODEs, systems of ODEs can classified as linear or nonlinear. A system of linear first-order ODEs can be represented in the form X HtL ! AHtL X HtL +BHtL. Here X HtL is a vector of unknown functions, AHtL is the matrix of the coefficients of the unknown functions, and BHtL is a vector representing the inhomogeneous part of the system. In the two-dimensional case, the system can be written more concretely as x HtL ! pHtL xHtL + qHtL yHtL + uHtL y HtL ! rHtL xHtL + sHtL yHtL + vHtL. If all the entries of the matrix AHtL are constants, then the system is said to be linear with constant coefficients. If BHtL is the zero vector, then the system is said to be homogeneous. The important global features of the solutions to linear systems can be clarified by considering homogeneous systems of ODEs with constant coefficients.

Linear Systems of ODEs


Here is a system of two ODEs whose coefficient matrix has real and distinct eigenvalues.
In[1]:= In[2]:=

A = 884, - 6<, 81, - 1<<; Eigenvalues@AD

Out[2]= 82, 1<

Differential Equation Solving with DSolve

43

In[3]:= In[4]:=

X@t_D = 8x@tD, y@tD<; system = MapThread@1 2 &, 8X '@tD, A.X@tD<D

Out[4]= 8x @tD 4 x@tD - 6 y@tD, y @tD x@tD - y@tD<

This solves the system. Note that the general solution depends on two arbitrary constants C @1D and C @2D.
In[5]:=

sol = DSolve@system, 8x, y<, tD


y FunctionA8t<, t I-1 + t M C@1D - t I-3 + 2 t M C@2DE==

t t t t Out[5]= 99x FunctionA8t<, I-2 + 3 M C@1D - 6 I-1 + M C@2DE,

Here is a plot of some particular solutions obtained by giving specific values to C @1D and C @2D. In this case, the origin is a called a node.
In[6]:=

particularsols = Partition@Flatten@Table@8x@tD, y@tD< . sol . 8C@1D 1 i, C@2D 1 j<, 8i, - 20, 20, 6<, 8j, - 20, 20, 6<DD, 2D; ParametricPlot@Evaluate@particularsolsD, 8t, - 3, 3<, PlotRange -> 8- 2, 2<D
2

In[7]:=

Out[7]=

-2

-1

-1

-2

In this system the eigenvalues of the coefficient matrix are complex conjugates of each other.
In[8]:= In[9]:=

A = 887, - 8<, 85, - 5<<; Eigenvalues@AD

Out[9]= 81 + 2 , 1 - 2 <

In[10]:= In[11]:=

X@t_D = 8x@tD, y@tD<; system = MapThread@1 2 &, 8X '@tD, A.X@tD<D

Out[11]= 8x @tD 7 x@tD - 8 y@tD, y @tD 5 x@tD - 5 y@tD<

This solves the system.

44

Differential Equation Solving with DSolve

This solves the system.


In[12]:=

sol = DSolve@system, 8x, y<, tD


5 2

t t Out[12]= ::x FunctionA8t<, -4 C@2D Sin@2 tD + C@1D HCos@2 tD + 3 Sin@2 tDLE,

y FunctionB8t<, t C@2D HCos@2 tD - 3 Sin@2 tDL +

t C@1D Sin@2 tDF>>

This plots the solution for various values of the arbitrary parameters. The spiraling behavior is typical for systems with complex eigenvalues.
In[13]:=

particularsols = Partition@Flatten@Table@8x@tD, y@tD< . sol . 8C@1D 1 i, C@2D 1 j<, 8i, - 10, 10, 8<, 8j, - 10, 10, 8<DD, 2D; ParametricPlot@Evaluate@particularsolsD, 8t, - 35, 35<, PlotRange All, PlotPoints 70, Method -> 8Compiled False<D

In[14]:=

1 1015

Out[14]=

-3 1015

-2 1015

-1 1015

1 1015

2 1015

3 1015

-1 1015

-2 1015

Solving homogeneous systems of ODEs with constant coefficients and of arbitrary order is a straightforward matter. They are solved by converting them to a system of first-order ODEs.
This solves a homogeneous system of ODEs of order 3, with constant coefficients.
In[15]:=

system = 8x '''@tD + y@tD, y '''@tD - 64 x@tD<;

Differential Equation Solving with DSolve

45

In[16]:=

sol = DSolve@8system@@1DD 0, system@@2DD 0<, 8x, y<, tD


1 3 1 96 1 24 1 3 t

Out[16]= ::x FunctionB8t<,

3 t

C@3D Cos@tD + 2
3 t

3 t

Cos@tD +

3 t

Cos@2 tD + 3 Sin@tD 3 Sin@tD + 3 2 3 2


3 t

C@6D Cos@tD + 2 C@1D Cos@tD + 2

Cos@tD - 2 Cos@tD - 2

3 t

Cos@2 tD + Cos@2 tD -

Sin@tD + Sin@tD +

3 t

3 t

3 t

3 t

- 3 t C@2D - 3 Cos@tD + 3 2 3 t Cos@tD - Sin@tD - 2 3 t Sin@tD - 2 3 t Sin@2 tD 192 1 - 3 t C@5D Sin@tD + 2 3 t Sin@tD - 3 t Sin@2 tD + 24 1 - 3 t C@4D - 3 Cos@tD + 3 2 3 t Cos@tD + Sin@tD + 2 3 t Sin@tD + 2 3 t Sin@2 tD F, 12 1 y FunctionB8t<, - 3 t C@5D Cos@tD + 2 3 t Cos@tD + 3 t Cos@2 tD 3 2 - 3 t C@4D Cos@tD + 2 3 t Cos@tD - 2 3 t Cos@2 tD + 3 Sin@tD - 3 2 3 t Sin@tD + 3 1 - 3 t C@2D Cos@tD + 2 3 t Cos@tD - 2 3 t Cos@2 tD - 3 Sin@tD + 3 2 3 t Sin@tD 24 1 - 3 t C@1D - 3 Cos@tD + 3 2 3 t Cos@tD - Sin@tD - 2 3 t Sin@tD - 2 3 t Sin@2 tD + 3 8 - 3 t C@3D Sin@tD + 2 3 t Sin@tD - 3 t Sin@2 tD + 3 1 - 3 t C@6D - 3 Cos@tD + 3 2 3 t Cos@tD + Sin@tD + 2 3 t Sin@tD + 2 3 t Sin@2 tD F>> 12

This verifies the solution.


In[17]:=

system . sol@@1DD . 8t RandomComplex@D, C@1D RandomComplex@D, C@2D RandomComplex@D, C@3D RandomComplex@D, C@4D RandomComplex@D, C@5D RandomComplex@D, C@6D RandomComplex@D< Chop

Out[17]= 80, 0<

In general, systems of linear ODEs with non-constant coefficients can only be solved in cases where the coefficient matrix has a simple structure, as illustrated in the following examples.
This first-order system has a diagonal coefficient matrix. The system is uncoupled because the first equation involves only x@tD and the second equation depends only on y@tD. Thus, each equation in the system can be integrated independently of the other.
In[18]:=

DSolve@8x '@tD Sin@tD * x@tD, y '@tD t ^ 2 * y@tD<, 8x, y<, tD


t3

-Cos@tD C@1DE, y FunctionB8t<, 3 C@2DF>> Out[18]= ::x FunctionA8t<,

The rows of the coefficient matrix for this system form an orthogonal set of vectors.
In[19]:= In[20]:=

A = 88E ^ t, Tan@tD<, 8- Tan@tD, E ^ t<<; A.Transpose@AD Det@AD

Out[20]= 881, 0<, 80, 1<<

46

Differential Equation Solving with DSolve

In[21]:= In[22]:=

X@t_D = 8x@tD, y@tD<; system = MapThread@1 2 &, 8X '@tD, A.X@tD<D

t t Out[22]= 9x @tD x@tD + Tan@tD y@tD, y @tD -Tan@tD x@tD + y@tD=

In[23]:=

sol = DSolve@system, 8x, y<, tD


t t

Out[23]= ::x FunctionB8t<, C@1D Cos@Log@Cos@tDDD - C@2D Sin@Log@Cos@tDDDF,

y FunctionB8t<, C@2D Cos@Log@Cos@tDDD + C@1D Sin@Log@Cos@tDDDF>>


In[24]:=

system . sol@@1DD Simplify

Out[24]= 8True, True<

Here is a system of three first-order ODEs. The coefficient matrix is upper triangular.
In[25]:= In[26]:=

A = 88E ^ t, 2, 3<, 80, 2, - 1<, 80, 0, 1<<; MatrixForm@AD


t 2 3 0 2 -1 0 0 1

Out[26]//MatrixForm=

In[27]:= In[28]:=

X@t_D = 8x@tD, y@tD, z@tD<; system = MapThread@1 2 &, 8X '@tD, A.X@tD<D

t Out[28]= 9x @tD x@tD + 2 y@tD + 3 z@tD, y @tD 2 y@tD - z@tD, z @tD z@tD=

In[29]:=

sol = DSolve@system, 8x, y, z<, tD


t

t Out[29]= ::x FunctionB8t<, C@1D + 2 I-1 - M C@2D - 5 C@3DF,

y FunctionA8t<, 2 t C@2D + t C@3DE, z FunctionA8t<, t C@3DE>>

As for single ODEs, there are sophisticated modern algorithms for solving systems of ODEs with rational coefficients.
This solves a system of two first-order ODEs with rational coefficients. Note that the solution is composed entirely of rational functions.
In[30]:=

DSolveB:y @xD w @xD

H5 + xL w@xD I- 3 - 2 x + x2 M I- 1 + x3 M -

I6 + 2 x - 3 x3 - x5 M y@xD + x I- 3 - 2 x + x2 M I- 1 + x3 M ,

I1 + 20 x2 + 3 x3 M w@xD H5 + xL I- 1 + x3 M
x C@1D -3 - 2 x + x2 +

4 x I- 3 - 2 x + x2 M y@xD H5 + xL I- 1 + x3 M >, 8y, w<, xF


C@1D 5+x x4 C@2D 5+x

Out[30]= ::y FunctionB8x<,

x2 C@2D -3 - 2 x + x2

F, w FunctionB8x<,

F>>

In the following example, the algorithm finds one rational solution for x@tD and y@tD. (The equation for z@tD is uncoupled from the rest of the system.) Using the rational solution, DSolve is able to find the remaining exponential solution for x@tD and y@tD.

Differential Equation Solving with DSolve

47

In the following example, the algorithm finds one rational solution for x@tD and y@tD. (The equation for z@tD is uncoupled from the rest of the system.) Using the rational solution, DSolve is able to find the remaining exponential solution for x@tD and y@tD.
In[31]:=

system = 8x '@tD H2 * HH- 9 + t + t ^ 2L * x@tD + H- 6 + t ^ 2L * y@tDLL HH- 2 + tL * tL, y '@tD H- 3 * H- 12 + 2 * t + t ^ 2L * x@tD + H24 - 2 * t - 3 * t ^ 2L * y@tDL HH- 2 + tL * tL, z '@tD t * z@tD<; sol = DSolve@system, 8x, y, z<, tD
H-2 - tL C@1D t3 H4 + tL C@1D t3 - 2 -t C@2DF,
t2

In[32]:=

Out[32]= ::x FunctionB8t<,

y FunctionB8t<,

+ 3 -t C@2DF, z FunctionB8t<, 2 C@3DF>>

In[33]:=

system . sol Simplify

Out[33]= 88True, True, True<<

The systems considered so far have all been homogeneous. If the system is inhomogeneous (that is, if there are terms free from any dependent variables and their derivatives), DSolve applies either the method of variation of parameters or the method of undetermined coefficients to find the general solution.
This solves an inhomogeneous system.
In[34]:= In[35]:= In[36]:= In[37]:=

A = 887, - 8<, 85, - 5<<; B = 8E ^ Ht 10L, t<; X@t_D = 8x@tD, y@tD<; system = MapThread@1 2 &, 8X '@tD, A.X@tD + B<D

t10 + 7 x@tD - 8 y@tD, y @tD t + 5 x@tD - 5 y@tD= Out[37]= 9x @tD

48

Differential Equation Solving with DSolve

In[38]:=

sol = DSolve@system, 8x, y<, tD

Out[38]= ::x FunctionB8t<,

-4 t C@2D Sin@2 tD + t C@1D HCos@2 tD + 3 Sin@2 tDL - 4 t Sin@2 tD 1 50 t HCos@2 tD + 3 Sin@2 tDL 510 -t H18 + 70 tL Cos@2 tD + 225 481 -9 t10 Sin@2 tD 1 50

500 481

-9 t10 Cos@2 tD -

-t H-26 + 10 tL Sin@2 tD +

4 -9 t10 Cos@2 tD -t H4 + 10 tL Cos@2 tD + 481 25 470 2 -9 t10 Sin@2 tD -t H-6 + 10 tL Sin@2 tD F, 481 25 5 y FunctionB8t<, t C@2D HCos@2 tD - 3 Sin@2 tDL + t C@1D Sin@2 tD + 2 500 1 t HCos@2 tD - 3 Sin@2 tDL -9 t10 Cos@2 tD -t H18 + 70 tL Cos@2 tD + 481 50 225 1 5 510 -9 t10 Sin@2 tD -t H-26 + 10 tL Sin@2 tD + t Sin@2 tD -9 t10 Cos@2 tD 481 50 2 481 4 470 2 -t H4 + 10 tL Cos@2 tD + -9 t10 Sin@2 tD -t H-6 + 10 tL Sin@2 tD F>> 25 481 25

Particular solutions to the system can be obtained by assigning values to the constants C @1D and C @2D.
Here is a plot of the solution for one choice of parameters.
In[39]:= In[40]:=

particularsol = 8x@tD, y@tD< . sol@@1DD . 8C@1D - 1, C@2D 2<; Plot@Evaluate@particularsolD, 8t, 0, Pi<D
120 100 80

Out[40]=

60 40 20 0.5 -20 1.0 1.5 2.0 2.5 3.0

Nonlinear Systems of ODEs


Following are two examples of nonlinear systems of ODEs that can be solved symbolically using DSolve.
The first three equations in this system of four nonlinear ODEs can be solved independently because none of their right-hand sides depend on p, q, r, or s.
In[1]:=

system = 8p '@xD == 1, q '@xD == x, r '@xD == 0, s '@xD == r@xD Hp@xD + 4 * q@xD * r@xDL<;

Differential Equation Solving with DSolve

49

In[2]:=

sol = DSolve@system, 8p, q, r, s<, xD


+ C@2DF, 2 2 ArcTanB x2

Out[2]= ::p Function@8x<, x + C@1DD, q FunctionB8x<,

1+4 x C@3D

F C@3D + C@4DF>>
2

r Function@8x<, C@3DD, s FunctionB8x<,

-1+8 C@1D C@3D+32 C@2D C@3D2

-1 + 8 C@1D C@3D + 32 C@2D C@3D


In[3]:=

system . sol Simplify

Out[3]= 88True, True, True, True<<

This system of two nonlinear ODEs is autonomous, in the sense that the right-hand sides of the equations do not depend on x.
In[4]:= In[5]:=

system = 8u '@xD 1 Sqrt@v@xDD, v '@xD u@xD<; sol = DSolve@system, 8u, v<, xD@@1DD

Out[5]= :v FunctionB8x<,

1 16

4 C@1D2 + 4 C@1D -324 x +

6 213 C@1D
13

23 328 C@1D3 + H-324 x - 81 C@2DL2 - 81 C@2D


13 2

-324 x +

23 328 C@1D3 + H-324 x - 81 C@2DL2 - 81 C@2D + 3 213

6 213 C@1D
13

-324 x +

23 328 C@1D3 + H-324 x - 81 C@2DL2 - 81 C@2D


13 4

-324 x +

23 328 C@1D3 + H-324 x - 81 C@2DL2 - 81 C@2D F, 3 213 6 213 C@1D


13

u FunctionB8x<, -324 x + -324 x +

23 328 C@1D3 + H-324 x - 81 C@2DL2 - 81 C@2D


13

23 328 C@1D3 + H-324 x - 81 C@2DL2 - 81 C@2D F> 3 213

In[6]:=

system . sol Simplify PowerExpand Simplify

Out[6]= 8True, True<

The previous two examples demonstrate that the solutions to fairly simple systems are usually complicated expressions of the independent variable. In fact, the solution is often available only in implicit form and may thus contain InverseFunction objects or unevaluated Solve objects.

50

Differential Equation Solving with DSolve

The previous two examples demonstrate that the solutions to fairly simple systems are usually complicated expressions of the independent variable. In fact, the solution is often available only in implicit form and may thus contain InverseFunction objects or unevaluated Solve objects.

Lie Symmetry Methods for Solving Nonlinear ODEs


Around 1870, Marius Sophus Lie realized that many of the methods for solving differential equations could be unified using group theory. Lie symmetry methods are central to the modern approach for studying nonlinear ODEs. They use the notion of symmetry to generate solutions in a systematic manner. Here is a brief introduction to Lies approach that provides some examples that are solved in this way by DSolve. A key notion in Lies method is that of an infinitesimal generator for a symmetry group. This concept is illustrated in the following example.
Here is the well-known transformation for rotations in the x-y plane. This is a one-parameter group of transformations with parameter t.
In[1]:= In[2]:=

m = x * Cos@tD + y * Sin@tD; n = - x * Sin@tD + y * Cos@tD;

For a fixed value of t, the point Hm, nL (in blue) can be obtained by rotating the line joining Hx, yL (in red) to the origin through an angle of t in the counterclockwise direction.
In[3]:=

Show@ 8Graphics@88Red, PointSize@0.04D, Point@83 * Cos@1 4D, 3 * Sin@1 4D<D<, 8Blue, PointSize@0.04D, Point@83 * Cos@H1 4L + HPi 3LD, 3 * Sin@H1 4L + HPi 3LD<D<, 8Green, Line@880, 0<, 83 * Cos@1 4D, 3 * Sin@1 4D<<D<, 8Green, Line@880, 0<, 83 * Cos@H1 4L + HPi 3LD, 3 * Sin@H1 4L + HPi 3LD<<D<<D, ParametricPlot@83 * Cos@tD, 3 * Sin@tD<, 8t, 0, 2 Pi<, DisplayFunction Identity D<, AspectRatio 1, ImageSize 200, Axes TrueD
3

Out[3]=

-3

-2

-1 -1 -2 -3

Differential Equation Solving with DSolve

51

A rotation through t can be represented by the matrix Mt = cosHtL sinHtL . -sinHtL cosHtL

This shows that the set of all rotations in the plane satisfies the properties for forming a group.
In[3]:= In[4]:=

M@t_D := 88Cos@tD, Sin@tD<, 8- Sin@tD, Cos@tD<< Simplify@M@a + bD == M@aD.M@bDD

Out[4]= True

In[5]:=

M@aD.M@0D == M@0D.M@aD == M@aD

Out[5]= True

In[6]:=

M@0D == IdentityMatrix@2D

Out[6]= True

In[7]:=

M@aD.M@- aD == M@- aD.M@aD == IdentityMatrix@2D Simplify

Out[7]= True

The Lie symmetry method requires calculating a first-order approximation to the expressions for the group. This approximation is called an infinitesimal generator.
This expands the expressions for m and n in a series with respect to t and around the origin 0 to obtain linear approximations.
In[8]:=

Series@m , 8t, 0, 1<D Normal

Out[8]= x + t y

In[9]:=

Series@n , 8t, 0, 1<D Normal

Out[9]= -t x + y

The coefficients of the linear terms in t are y and -x, respectively. The infinitesimal generator for the rotation group in the plane is defined to be the following differential operator.
In[10]:=

v = Hy * D@, xD - x * D@, yDL &; Starting from the infinitesimal generator, the original group can be recovered by integrating the fundamental system of Lie equations. For the group of rotations, the Lie equations are given by the first argument to DSolve shown here.

In[11]:=

DSolve@8x '@tD y@tD, y '@tD - x@tD<, 8x@tD, y@tD<, tD

Out[11]= 88x@tD C@1D Cos@tD + C@2D Sin@tD, y@tD C@2D Cos@tD - C@1D Sin@tD<<

The rotation group arises in the study of symmetries of geometrical objects; it is an example of a symmetry group. The infinitesimal generator, a differential operator, is a convenient local representation for this symmetric group, which is a set of matrices.

52

Differential Equation Solving with DSolve

The rotation group arises in the study of symmetries of geometrical objects; it is an example of a symmetry group. The infinitesimal generator, a differential operator, is a convenient local representation for this symmetric group, which is a set of matrices. An expression that reduces to 0 under the action of the infinitesimal generator is called an invariant of the group.
Here is an invariant for this group.
In[12]:=

invariant = x ^ 2 + y ^ 2;

This states that the distance from the origin to Hx, yL,
In[13]:=

x2 + y2 , is preserved under rotation.

v@invariantD

Out[13]= 0

In the following examples, these ideas are applied to differential equations.


This is an example of a Riccati equation, from page 103 of [I99].
In[14]:=

Riccatiequation = y '@xD + y@xD ^ 2 - 1 x ^ 2 0; The equation is invariant under the following scaling transformation.

In[15]:= In[16]:=

m = x * E ^ t; n = y * E ^ H- tL; The infinitesimal generator for this one-parameter group of transformations is found as before.

In[17]:=

Series@m, 8t, 0, 1<D Normal

Out[17]= x + t x

In[18]:=

Series@n, 8t, 0, 1<D Normal

Out[18]= y - t y

In[19]:=

v = Hx * D@, xD - y * D@, yDL &;

Now, the Riccati equation depends on three variables: x, y = y@xD, and p = y @xD. Hence, the infinitesimal generator v must be prolonged to act on all three variables in this first-order equation.
It turns out that the required prolongation is as follows.
In[20]:=

prolongedv = Hx * D@, xD - y * D@, yD - 2 p * D@, pD L &;

Differential Equation Solving with DSolve

53

This shows that the expression for the Riccati equation in the Hx, y, pL coordinates is indeed invariant under prolongedv.
In[21]:= In[22]:=

Riccatiexpression = p + y ^ 2 - H1 x ^ 2L; prolongedv@RiccatiexpressionD . 8p H1 x ^ 2L - y ^ 2< Together

Out[22]= 0

Depending on the order of the given equation, the knowledge of a symmetry (in the form of an infinitesimal generator) can be used in three ways. If the order of the equation is 1, it gives an integrating factor for the ODE that makes the equation exact and hence solvable. It gives a set of canonical coordinates in which the equation has a simple (integrable) form. It reduces the problem of solving an ODE of order n to that of solving an ODE of order n - 1, which is typically a simpler problem. The DSolve function checks for certain standard types of symmetries in the given ODE and uses them to return a solution. Following are three examples of ODEs for which DSolve uses such a symmetry method.
Here is a nonlinear first-order ODE (equation 1.120, page 315 of [K59]).
In[23]:=

FirstOrderODE = x * y '@xD y@xD * Hx * Log@x ^ 2 y@xDD + 2L; This ODE has a symmetry with the following infinitesimal generator.

In[24]:=

v = H- 2 * Exp@- xD * yL * D@, yD &; The presence of this symmetry allows DSolve to calculate an integrating factor and return the solution.

In[25]:=

sol = DSolve@FirstOrderODE, y, xD
-x

-2 Out[25]= 99y FunctionA8x<,

C@1D

x2 E==

This verifies the solution.


In[26]:=

FirstOrderODE . sol@@1DD . 8x RandomReal@D, C@1D RandomReal@D< Simplify Chop

Out[26]= True

Here is a second-order nonlinear ODE, based on equation 6.93 on page 213 of [K59].
In[27]:=

SecondOrderODE = x ^ 3 * y ''@xD 6 * Hx * y '@xD - y@xDL ^ 2;

54

Differential Equation Solving with DSolve

This equation is invariant under the following scaling transformation.


In[28]:= In[29]:=

m = x * E ^ t; n = y * E ^ t; The presence of this scaling symmetry allows DSolve to find new coordinates in which the independent variable is not explicitly present. Hence the problem is solved easily.

In[30]:=

sol = DSolve@SecondOrderODE, y, xD
Solve::ifun : Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.

Out[30]= ::y FunctionB8x<, -

1 6

x LogB6 -

C@1D x

- C@2D FF>>

This verifies the solution.


In[31]:=

SecondOrderODE . sol Simplify

Out[31]= 8True<

Finally, here is a system of two nonlinear first-order ODEs that can be solved by using a shift: u@xD u@xD - x. After the shift, the system becomes autonomous (it does not depend explicitly on x) and hence it can be solved by reduction to a first-order ODE for v as a function of u. The Solve::ifun message can be ignored; it is generated while inverting the expression for Exp@vD to give an expression in terms of Log.
In[32]:= In[33]:= In[34]:=

Clear@u, vD NonlinearSystem = 8u '@xD Exp@v@xDD + 1, v '@xD u@xD - x<; sol = DSolve@NonlinearSystem, 8u, v<, xD
Solve::ifun : Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.

Out[34]= ::v FunctionB8x<, LogBC@1D + C@1D TanB

2 x 2 x

C@1D + 2 C@1D + 2

2 2

C@1D C@2D F FF, C@1D C@2D FF>>

u FunctionB8x<, x +

C@1D TanB

2 1 2

In[35]:=

NonlinearSystem . sol Simplify

Out[35]= 88True, True<<

In[36]:=

Clear@m, n, u, vD

This concludes the discussion of ordinary differential equations.

Differential Equation Solving with DSolve

55

Partial Differential Equations (PDEs)


Introduction to Partial Differential Equations (PDEs)
A partial differential equation (PDE) is a relationship between an unknown function uHx1 , x2 , , xn L and its derivatives with respect to the variables x1 , x2 , , xn .
Here is an example of a PDE.
In[1]:=

equation1 =

! uHx, yL !x

+x

! uHx, yL !y

! sinHxL;

PDEs occur naturally in applications; they model the rate of change of a physical quantity with respect to both space variables and time variables. At this stage of development, DSolve typically only works with PDEs having two independent variables. The order of a PDE is the order of the highest derivative that occurs in it. The previous equation is a first-order PDE. A function uHx, yL is a solution to a given PDE if u and its derivatives satisfy the equation.
Here is one solution to the previous equation.
In[2]:=

sol = u . DSolve@equation1, u, 8x, y<D@@1DD . C@1D@t_D t


1 2 I-x2 + 2 yMF

Out[2]= FunctionB8x, y<, -Cos@xD +

This verifies the solution.


In[3]:=

equation1 . 8u sol<

Out[3]= True

Here are some well-known examples of PDEs (clicking a link in the table will bring up the relevant examples). DSolve gives symbolic solutions to equations of all these types, with certain restrictions, particularly for second-order PDEs.

56

Differential Equation Solving with DSolve

name of equation

general form
!u !x !u !t

classification

transport equation Burgers equation eikonal equation Laplaces equation wave equation heat equation

+c +u

!u !y !u !x

! 0 with c constant !0

linear first-order PDE quasilinear first-order PDE nonlinear first-order PDE elliptic linear second-order PDE hyperbolic linear second-order PDE parabolic linear second-order PDE

J !x N + J !y N ! 1
!2 u !x
2

!u 2

!u 2

!2 u ! y2

!0
!2 u !t2

!2 u ! x2 !2 u ! x2

= c2 =k

where c is the speed of light

!u !t

where k is the thermal

diffusivity

Recall that the general solutions to PDEs involve arbitrary functions rather than arbitrary constants. The reason for this can be seen from the following example.
The partial derivative with respect to y does not appear in this example, so an arbitrary function C @1D@yD can be added to the solution, since the partial derivative of C @1D@yD with respect to x is 0.
In[4]:=

DSolve@D@u@x, yD, xD 1, u@x, yD, 8x, y<D

Out[4]= 88u@x, yD x + C@1D@yD<<

If there are several arbitrary functions in the solution, they are labeled as C @1D, C @2D, and so on.

First-Order PDEs
Linear and Quasi-Linear PDEs
First-order PDEs are usually classified as linear, quasi-linear, or nonlinear. The first two types are discussed in this tutorial. A first-order PDE for an unknown function uHx, yL is said to be linear if it can be expressed in the form ! uHx, yL !x ! uHx, yL !y + cHx, yL uHx, yL ! d Hx, yL.

aHx, yL

+ bHx, yL

The PDE is said to be quasilinear if it can be expressed in the form

Differential Equation Solving with DSolve

57

The PDE is said to be quasilinear if it can be expressed in the form ! uHx, yL !x ! uHx, yL !y ! cHx, y, uHx, yLL.

aHx, y, uHx, yLL

+ bHx, y, uHx, yLL

A PDE which is neither linear nor quasi-linear is said to nonlinear. For convenience, the symbols z, p, and q are used throughout this tutorial to denote the unknown function and its partial derivatives. ! uHx, yL !x ! uHx, yL !y

z = uHx, yL; p =

; q =

Here is a linear homogeneous first-order PDE with constant coefficients.


In[1]:= In[2]:= In[3]:= In[4]:=

z := u@x, yD p := D@u@x, yD, xD q := D@u@x, yD, yD eqn = 2 * p + 3 * q + z 0;

The equation is linear because the left-hand side is a linear polynomial in z, p, and q. Since there is no term free of z, p, or q, the PDE is also homogeneous.
As mentioned earlier, the general solution contains an arbitrary function C @1D of the argument
1 2
In[5]:=

H2 y - 3 xL.

sol = DSolve@eqn, u, 8x, y<D


1 2 H-3 x + 2 yLFF>>

-x2 C@1DB Out[5]= ::u FunctionB8x, y<,

This verifies that the solution is correct.


In[6]:=

eqn . sol@@1DD Simplify

Out[6]= True

Particular solutions of the homogeneous PDE are obtained by specifying the function C @1D.
In[7]:=

particularsolution = u@x, yD . sol@@1DD . C@1D@a_D Sin@aD


1 2 H-3 x + 2 yLF

-x2 SinB Out[7]=

58

Differential Equation Solving with DSolve

Here is a plot of the surface for this particular solution.


In[8]:=

Plot3D@particularsolution, 8x, - 2, 2<, 8y, - 7, 7<, PlotPoints 30D

Out[8]=

The transport equation is a good example of a linear first-order homogeneous PDE with constant coefficients.
In this transport equation, c = 1 for convenience.
In[9]:=

DSolve@D@u@x, yD, xD + D@u@x, yD, yD ! 0, u@x, yD, 8x, y<D

Out[9]= 88u@x, yD C@1D@-x + yD<<

Note that the solution to the transport equation is constant on any straight line of the form y ! x + a in the plane. These straight lines are called the base characteristic curves. The equation y ! x + a defines a plane in three dimensions. The intersections of these planes with the solution surface are called characteristic curves. Since the characteristic curves are solutions to a system of ODEs, the problem of solving the PDE is reduced to that of solving a system of ODEs for xHtL, yHtL, and uHtL, where t is a parameter along the characteristic curves. These ODEs are called characteristic ODEs. The solution to an inhomogeneous PDE has two components: the general solution to the homogeneous PDE and a particular solution to the inhomogeneous PDE.
This is a linear inhomogeneous PDE of the first order.
In[10]:=

eqn = 7 * p + 3 * q + z x + y;

Differential Equation Solving with DSolve

59

The first part of the solution, -10 + x + y, is the particular solution to the inhomogeneous PDE. The rest of the solution is the general solution to the homogenous equation.
In[11]:=

sol = u@x, yD . DSolve@eqn, u@x, yD, 8x, y<D@@1DD Expand


1 7 H-3 x + 7 yLF

-x7 C@1DB Out[11]= -10 + x + y +

Here is a linear homogeneous PDE with variable coefficients.


In[12]:= In[13]:=

eqn = Sin@xD * p + E ^ x * q 0; sol = DSolve@eqn, u, 8x, y<D


1 2 , 1, 2 3 2 2 , 2 x FFF>>

H1+L x Hypergeometric2F1B Out[13]= ::u FunctionB8x, y<, C@1DBy + H1 + L

This verifies the solution.


In[14]:=

eqn . sol@@1DD Simplify

Out[14]= True

Here is a linear inhomogeneous PDE with variable coefficients.


In[15]:=

eqn = p + x * q Cos@xD; The solution is once again composed of the general solution to the homogeneous PDE and a particular solution, Sin@ xD, to the inhomogeneous PDE.

In[16]:=

sol = DSolve@eqn, u, 8x, y<D


1 2 I-x2 + 2 yMFF>>

Out[16]= ::u FunctionB8x, y<, Sin@xD + C@1DB

Now consider some examples of first-order quasi-linear PDEs.


This PDE is quasi-linear because of the term z2 on the right-hand side.
In[17]:= In[18]:=

eqn = p + x * q z ^ 2 + 5; sol = DSolve@eqn, u, 8x, y<D


Solve::ifun : Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.

Out[18]= ::u FunctionB8x, y<,

5 TanB

5 x+

5 C@1DB

1 2

I-x2 + 2 yMFFF>>

This verifies the solution.


In[19]:=

eqn . sol@@1DD Simplify

Out[19]= True

Burgers equation is an important example of a quasi-linear PDE.

60

Differential Equation Solving with DSolve

Burgers equation is an important example of a quasi-linear PDE.

! uHx, yL !x

+ uHx, yL

! uHx, yL !y

!0

It can be written using the notation introduced earlier.


In[20]:=

BurgersEquation = p + z q 0;

The term z q makes this equation quasi-linear.


This solves the equation.
In[21]:=

sol = DSolve@BurgersEquation, u, 8x, y<D

Out[21]= Solve@C@1D@u@x, yD, y - x u@x, yDD 0, u@x, yDD

This verifies the solution to Burgers' equation.


In[22]:= In[23]:= In[24]:=

p1 = p . Solve@D@sol@@1DD, xD, pD@@1DD; q1 = q . Solve@D@sol@@1DD, yD, qD@@1DD; p1 + z * q1

Out[24]= 0

A practical consequence of quasi-linearity is the appearance of shocks and steepening and breaking of solutions. Thus, although the procedures for finding general solutions to linear and quasi-linear PDEs are quite similar, there are sharp differences in the nature of the solutions.

Nonlinear PDEs
The general first-order nonlinear PDE for an unknown function uHx, yL is given by FHu, p, qL ! 0. Here F is a function of u = uHx, yL, p =
!uHx,yL !x

, and q =

!uHx,yL !y

The term nonlinear refers to the fact that F is a nonlinear function of p and q. For instance, the eikonal equation involves a quadratic expression in p and q. The general solution to a first-order linear or quasi-linear PDE involves an arbitrary function. If the PDE is nonlinear, a very useful solution is given by the complete integral. This is a function of uHx, y, C @1D, C @2DL, where C @1D and C @2D are independent parameters and u satisfies the PDE for all values of HC @1D, C @2DL in an open subset of the plane. The complete integral can be used to find a general solution for the PDE as well as to solve initial value problems for it.

Differential Equation Solving with DSolve

61

The general solution to a first-order linear or quasi-linear PDE involves an arbitrary function. If the PDE is nonlinear, a very useful solution is given by the complete integral. This is a function of uHx, y, C @1D, C @2DL, where C @1D and C @2D are independent parameters and u satisfies the PDE for all values of HC @1D, C @2DL in an open subset of the plane. The complete integral can be used to find a general solution for the PDE as well as to solve initial value problems for it.
Here is a simple nonlinear PDE.
In[1]:= In[2]:= In[3]:= In[4]:=

z := u@x, yD p := D@u@x, yD, xD q := D@u@x, yD, yD eqn = p * q 1; The complete integral depends on the parameters C @1D and C @2D. Since DSolve returns a general solution for linear and quasi-linear PDEs, a warning message appears before a complete integral is returned.

In[5]:=

sol = DSolve@eqn, u, 8x, y<D


DSolve::nlpde : Solution requested to nonlinear partial differential equation. Trying to build a special solution.

Out[5]= ::u FunctionB8x, y<, C@1D +

x C@2D

+ y C@2DF>>

This verifies the solution.


In[6]:=

eqn . sol

Out[6]= 8True<

If the values of C @1D and C @2D are fixed, the previous solution represents a plane in three dimensions. Thus, the complete integral for this PDE is a two-parameter family of planes, each of which is a solution surface for the equation. Next, the envelope of a one-parameter family of surfaces is a surface that touches each member of the family. If the complete integral is restricted to a one-parameter family of planes, for example by setting C @2D = 5 C @1D, the envelope of this family is also a solution to the PDE called a general integral.

62

Differential Equation Solving with DSolve

This finds the envelope of the one-parameter family given by setting C @2D = 5 C @1D in the complete integral for the preceding PDE p * q == 1.
In[7]:=

oneparametersol = u@x, yD Hu@x, yD . sol@@1DD . C@2D 5 * C@1DL


x 5 C@1D + C@1D + 5 y C@1D

Out[7]= u@x, yD

In[8]:=

oneparameterenvelope = Eliminate@8oneparametersol, D@oneparametersol, C@1DD<, 8C@1D<D

2 Out[8]= 5 u@x, yD x H4 + 20 yL

This verifies that the envelope surface is a solution to the PDE.


In[9]:= Out[9]=

p1 = D@u@x, yD, xD . Solve@D@oneparameterenvelope, xD, D@u@x, yD, xDD@@1DD


2 H1 + 5 yL 5 u@x, yD

In[10]:= Out[10]=

q1 = D@u@x, yD, yD . Solve@D@oneparameterenvelope, yD, D@u@x, yD, yDD@@1DD


2x u@x, yD

In[11]:=

FullSimplify@p1 * q1, 8oneparameterenvelope<D

Out[11]= 1

Like nonlinear ODEs, some nonlinear PDEs also have a singular solution (or singular integral) that is obtained by constructing the envelope of the entire two-parameter family of surfaces represented by the complete integral.
Here is an example of such a construction, (equation 6.4.13, page 429 of [K00]).
In[12]:=

sol = DSolve@4 z + p ^ 2 + q ^ 2 4, u, 8x, y<D


DSolve::nlpde : Solution requested to nonlinear partial differential equation. Trying to build a special solution.

Out[12]= ::u FunctionB8x, y<,

1 - y2 - 2 x y C@1D + C@1D2 - x2 C@1D2 - 2 y C@2D - 2 x C@1D C@2D - C@2D2 1 + C@1D2

F>>

In[13]:=

twoparameterfamily = u@x, yD Hu@x, yD . sol@@1DDL


1 - y2 - 2 x y C@1D + C@1D2 - x2 C@1D2 - 2 y C@2D - 2 x C@1D C@2D - C@2D2 1 + C@1D2

Out[13]= u@x, yD

In[14]:=

envelopeoftwoparameterfamily = Eliminate@8twoparameterfamily, D@twoparameterfamily, C@1DD, D@twoparameterfamily, C@2DD<, 8C@1D, C@2D<D

Out[14]= u@x, yD 1

Thus, the singular integral for this PDE is a plane parallel to the x-y plane.

Differential Equation Solving with DSolve

63

Thus, the singular integral for this PDE is a plane parallel to the x-y plane. To summarize, the complete integral for a nonlinear PDE includes a rich variety of solutions. Every member of the two-parameter family gives a particular solution to the PDE. The envelope of any one-parameter family is a solution called a general integral of the PDE. The envelope of the entire two-parameter family is a solution called the singular integral of the PDE. The complete integral is not unique, but any other complete integral for the PDE can be obtained from it by the process of envelope formation. These remarkable properties account for the usefulness of the complete integral in geometrical optics, dynamics, and other areas of application. Following are various examples of nonlinear PDEs that show different kinds of complete integrals.
Here is the complete integral for the eikonal equation.
In[15]:= In[16]:=

Eikonal = D@u@x, yD, xD ^ 2 + D@u@x, yD, yD ^ 2 == 1; sol = DSolve@Eikonal, u, 8x, y<D


DSolve::nlpde : Solution requested to nonlinear partial differential equation. Trying to build a special solution.

Out[16]= ::u FunctionB8x, y<, C@1D + y C@2D - x

1 - C@2D2 F>, 1 - C@2D2 F>>

:u FunctionB8x, y<, C@1D + y C@2D + x

This complete integral is a two-parameter family of planes. This type of solution arises whenever the PDE depends explicitly only on p and q, but not on u@x, yD, x, or y. For a fixed value of u@x, yD, it is a line in the plane at a distance of C @1D units from the origin that makes an angle of ArcCos@C @2DD with the x axis. This is the familiar picture of wave-front propagation from geometrical optics.
This verifies the solution for the eikonal equation.
In[17]:=

Eikonal . sol

Out[17]= 8True, True<

This is an example of a Clairaut equation (z = p x + q y + f H p, qL).


In[18]:=

Clairaut = z x * p + y * q + 2 p * q * Sqrt@1 - p ^ 2D;

64

Differential Equation Solving with DSolve

Once again, the complete integral is a family of planes.


In[19]:=

sol = DSolve@Clairaut, u, 8x, y<D


DSolve::nlpde : Solution requested to nonlinear partial differential equation. Trying to build a special solution.

Out[19]= ::u FunctionB8x, y<, x C@1D + y C@2D + 2 C@1D

1 - C@1D2 C@2DF>>

This verifies the solution.


In[20]:=

Clairaut . sol

Out[20]= 8True<

In the following equation, the variables can be separated; that is, the PDE can be written in the form f Hx, pL ! gHy, qL. Hence, the equation can be integrated easily.
In[21]:= In[22]:=

Separable = p ^ 2 + a * q x + 3 y; sol = DSolve@Separable, u, 8x, y<D


DSolve::nlpde : Solution requested to nonlinear partial differential equation. Trying to build a special solution.

Out[22]= ::u FunctionB8x, y<,

3 y2 2a 3 y2 2a

2 3 2 3

Hx - C@1DL32 + Hx - C@1DL32 +

y C@1D a y C@1D a

+ C@2DF>, + C@2DF>>

:u FunctionB8x, y<,

This verifies the solution.


In[23]:=

Separable . sol Simplify

Out[23]= 8True, True<

In this example (equation 6.49, page 202 of [K74]), the independent variables x and y are not explicitly present.
In[24]:= In[25]:=

MissingIndependentVariables = a * p ^ 2 + b * p * q c * z ^ 2; sol = DSolve@MissingIndependentVariables, u, 8x, y<D


DSolve::nlpde : Solution requested to nonlinear partial differential equation. Trying to build a special solution.
c y CA1E2

c x CA1E CA1E2

c CA2E

Out[25]= ::u FunctionB8x, y<,

-b CA1E-a

-b CA1E-a

-b CA1E-a CA1E2

F>>

Differential Equation Solving with DSolve

65

This verifies the solution.


In[26]:=

MissingIndependentVariables . sol Simplify

Out[26]= 8True<

Often a coordinate transformation can be used to cast a given PDE into one of the previous types. The expression for the complete integral will then have the same form as for the standard types. Here are some examples of nonlinear PDEs for which DSolve applies a coordinate transformation to find the complete integral.
This PDE (equation 6.47, page 201 of [K74]) can be reduced to the form f H p, qL ! 0 using the transformation X = logHxL and Y = logHyL.
In[27]:=

DSolve@x * y * p * q 1, u@x, yD, 8x, y<D


DSolve::nlpde : Solution requested to nonlinear partial differential equation. Trying to build a special solution.

Out[27]= ::u@x, yD C@2D + C@1D Log@xD +

Log@yD C@1D

>>

This PDE (equation 6.93, page 213 of [K74]) can be solved easily in a polar coordinate system, in which the variables are separable.
In[28]:=

DSolve@Hy * p - x * qL ^ 2 + a * Hx * p + y * qL b, z, 8x, y<D


DSolve::nlpde : Solution requested to nonlinear partial differential equation. Trying to build a special solution.
y x b LogB F C@1D + C@2D + a x2 + y2 F a C@1D LogB x2 + y2 F >>

Out[28]= ::u@x, yD -ArcTanB

This equation (equation 6.36, page 196 of [K74]) can be transformed into a linear PDE using a Legendre transformation.
In[29]:= In[30]:=

LegendreTransformable = y * p * q - z * p + a * q 0; sol = DSolve@LegendreTransformable, u, 8x, y<D


DSolve::nlpde : Solution requested to nonlinear partial differential equation. Trying to build a special solution.

Out[30]= ::u FunctionB8x, y<,

1 4 C@1D

-y H-2 x + 2 C@2DL 1 4 C@1D

y2 H-2 x + 2 C@2DL2 + 8 a C@1D Ix2 - 2 x C@2D + C@2D2 M

F>, :u

FunctionB8x, y<,

-y H-2 x + 2 C@2DL +

y2 H-2 x + 2 C@2DL2 + 8 a C@1D Ix2 - 2 x C@2D + C@2D2 M

F>>

66

Differential Equation Solving with DSolve

This verifies the solution.


In[31]:=

LegendreTransformable . sol Simplify

Out[31]= 8True, True<

It should be noted that there is no general practical algorithm for finding complete integrals, and that the answers are often available only in implicit form.
The solution to this example (problem 2, page 66 of [S57]) is in implicit form.
In[32]:=

sol = DSolve@H1 + q ^ 2L * z p * x, u, 8x, y<D


DSolve::nlpde : Solution requested to nonlinear partial differential equation. Trying to build a special solution. Solve::tdep : The equations appear to involve the variables to be solved for in an essentially non-algebraic way. Solve::tdep : The equations appear to involve the variables to be solved for in an essentially non-algebraic way.

Out[32]= SolveB

1 2

C@1D LogB-C@1D +

C@1D2 - 4 u@x, yD2 F +

C@1D2 - 4 u@x, yD2

y + C@2D + C@1D Log@xD, u@x, yDF

The solution can be verified as follows.


In[33]:=

p = D@u@x, yD, xD . Solve@D@sol@@1DD, xD, D@u@x, yD, xDD@@1DD


C@1D C@1D C@1D2 - 4 u@x, yD2

Out[33]=

2 x u@x, yD
In[34]:=

q = D@u@x, yD, yD . Solve@D@sol@@1DD, yD, D@u@x, yD, yDD@@1DD


C@1D C@1D2 - 4 u@x, yD2 2 u@x, yD

Out[34]=

In[35]:=

H1 + q ^ 2L * z - p * x Simplify

Out[35]= 0

Second-Order PDEs
The general form of a linear second-order PDE is !2 u ! x2 !2 u !x!y !2 u ! y2 !u !x !u !y

+b

+ c

+ d

+e

+ f u ! g.

Here u = uHx, yL, and a, b, c, d , e, f , and g are functions of x and y only~they do not depend on u. If g = 0, the equation is said to be homogeneous.

Differential Equation Solving with DSolve

67

Here u = uHx, yL, and a, b, c, d , e, f , and g are functions of x and y only~they do not depend on u. If g = 0, the equation is said to be homogeneous. The first three terms containing the second derivatives are called the principal part of the PDE. They determine the nature of the general solution to the equation. In fact, the coefficients of the principal part can be used to classify the PDE as follows. The PDE is said to be elliptic if b2 - 4 a c < 0. The Laplace equation has a = 1, b = 0, and c = 1 and is therefore an elliptic PDE. The PDE is said to be hyperbolic if b2 - 4 a c > 0. The wave equation has a = 1, b = 0, and c = -1 and is therefore a hyperbolic PDE. The PDE is said to be parabolic if b2 - 4 a c = 0. The heat equation has a = 1, b = 0, and c = 0 and is therefore a parabolic PDE. DSolve can find the general solution for a restricted type of homogeneous linear second-order PDEs; namely, equations of the form !2 u ! x2 !2 u !x!y !2 u ! y2

+b

+c

= 0.

Here a, b, and c are constants. Thus, DSolve assumes that the equation has constant coefficients and a vanishing non-principal part. Following are some examples of the three basic types (elliptic, hyperbolic, and parabolic) and an explanation of their significance.
Here is the general solution for Laplaces equation, an elliptic PDE.
In[1]:= In[2]:=

LaplaceEquation = D@u@x, yD, 8x, 2<D + D@u@x, yD, 8y, 2<D 0; DSolve@LaplaceEquation, u@x, yD, 8x, y<D

Out[2]= 88u@x, yD C@1D@ x + yD + C@2D@- x + yD<<

This general solution contains two arbitrary functions, C @1D and C @2D. The arguments of these functions, y + x and y - x, indicate that the solution is constant along the imaginary straight line y = - x + a when C @2D 0 and along y = x + a when C @1D 0 . These straight lines are called characteristic curves of the PDE. In general, elliptic PDEs have imaginary characteristic curves.

68

Differential Equation Solving with DSolve

Here is another elliptic PDE.


In[3]:=

a = 3; b = 1; c = 5; b ^ 2 - 4 a * c

Out[3]= -59

In[4]:=

eqn = a * D@u@x, yD, 8x, 2<D + b * D@u@x, yD, x, yD + c * D@u@x, yD, 8y, 2<D 0; Note the imaginary characteristic curves for the equation.

In[5]:=

sol = DSolve@eqn, u, 8x, y<D


1 6 -1 + 59 x + yF + C@2DB 1 6 -1 - 59 x + yFF>>

Out[5]= ::u FunctionB8x, y<, C@1DB

The solution is verified as follows.


In[6]:=

eqn . sol Simplify

Out[6]= 8True<

This finds the general solution of the wave equation, a hyperbolic PDE. The constant c in the wave equation represents the speed of light and is set to 1 here for convenience.
In[7]:= In[8]:=

WaveEquation = D@u@x, tD, 8x, 2<D - D@u@x, tD, 8t, 2<D 0; DSolve@WaveEquation , u@x, tD, 8t, x<D

Out[8]= 88u@x, tD C@1D@-t + xD + C@2D@t + xD<<

The characteristic lines for the wave equation are x = k + t and x = k - t where k is an arbitrary constant. Hence the wave equation (or any hyperbolic PDE) has two families of real characteristic curves. If initial conditions are specified for the wave equation, the solution propagates along the characteristic lines. Also, any fixed pair of characteristic lines determine the null cone of an observer sitting at their intersection.
Here is another example of a hyperbolic PDE.
In[9]:=

a = 2; b = 7; c = - 1; b ^ 2 - 4 a * c

Out[9]= 57

In[10]:=

eqn = a * D@u@x, yD, 8x, 2<D + b * D@u@x, yD, x, yD + c * D@u@x, yD, 8y, 2<D 0; Notice that the equation has two families of real characteristics.

In[11]:=

sol = DSolve@eqn, u, 8x, y<D


1 4 7+ 57 x + yF + C@2DB1 4 757 x + yFF>>

Out[11]= ::u FunctionB8x, y<, C@1DB-

The solution can be verified as follows.

Differential Equation Solving with DSolve

69

The solution can be verified as follows.


In[12]:=

eqn . sol Simplify

Out[12]= 8True<

Finally, here is an example of a parabolic PDE.


In[13]:=

a = 3; b = 30; c = 75; b ^ 2 - 4 a * c

Out[13]= 0

In[14]:= In[15]:=

eqn = a * D@u@x, yD, 8x, 2<D + b * D@u@x, yD, x, yD + c * D@u@x, yD, 8y, 2<D 0; sol = DSolve@eqn, u, 8x, y<D

Out[15]= 88u Function@8x, y<, C@1D@-5 x + yD + x C@2D@-5 x + yDD<<

The equation has only one family of real characteristics, the lines y = 5 x + a. In fact, any parabolic PDE has only a single family of real characteristics.
The solution can be verified as follows.
In[16]:=

eqn . sol Simplify

Out[16]= 8True<

The heat equation is parabolic, but it is not considered here because it has a nonvanishing nonprincipal part, and the algorithm used by DSolve is not applicable in this case.

70

Differential Equation Solving with DSolve

Differential-Algebraic Equations (DAEs)


Introduction to Differential-Algebraic Equations (DAEs)
The systems of equations that govern certain phenomena (in electrical circuits, chemical kinetics, etc.) contain a combination of differential equations and algebraic equations. The differential equations are responsible for the dynamical evolution of the system, while the algebraic equations serve to constrain the solutions to certain manifolds. It is therefore of some interest to study the solutions of such differential-algebraic equations (DAEs).
Here is a simple example of a DAE. The first equation is an ODE for the function x@tD, while the second equation constrains the functions x@tD and y@tD to lie in a submanifold (a straight line) in 8x, y< space.
In[1]:=

dae = 8x '@tD y@tD, x@tD + y@tD 1<;

These tutorials are restricted to linear DAEs, which are defined as systems of equations of the following type. A.x HtL + B.xHtL ! F Here A and B are matrix functions of the independent variable t, F is a vector function of t, and xHtL is the vector of unknowns. If the matrix A is nonsingular (that is, invertible) then this is a system of ODEs. Thus, the system is a DAE if the matrix A is singular. If F ! 0, then the system is said to be homogeneous. As for ODEs, the general solution to a DAE is composed of the general solution to the corresponding homogeneous problem and a particular solution to the inhomogeneous system. DSolve can find the solutions to all DAEs in which the entries of the matrices A and B are constants. Such DAEs are said to have constant coefficients. The algorithm used by DSolve is based on decomposing both A and B into a nonsingular and nilpotent part. This decomposition is used to calculate a generalized inverse for A and B, which effectively reduces the problem to solving a system of ODEs. It is important to realize that the initial values for a DAE must be prescribed carefully to guarantee a solution for the problem. This can be seen by considering the following system of equations.

Differential Equation Solving with DSolve

71

It is important to realize that the initial values for a DAE must be prescribed carefully to guarantee a solution for the problem. This can be seen by considering the following system of equations. 8x1 HtL + x2 HtL ! 0, x2 HtL ! 0, x1 H0L ! 1, x2 H0L ! 0< This gives x2 HtL ! 0 x2 HtL ! 0 x1 HtL ! 0. Hence the only solution is x1 HtL ! 0 and x2 HtL ! 0. But this solution is inconsistent with the initial condition x1 H0L ! 1. DSolve can solve DAEs with constant coefficients; see "Examples of DAEs".

Examples of DAEs
This is a simple homogeneous DAE with constant coefficients.
In[1]:=

eqns =

8x '@tD - y@tD 0, x@tD + y@tD == 0<;

This finds the general solution. It has only one arbitrary constant because the second equation in the system specifies the relationship between x@tD and y@tD.
In[2]:=

sol = DSolve@eqns, 8x, y<, tD


1 4 -t C@1DF, y FunctionB8t<, 1 4 -t C@1DF>>

Out[2]= ::x FunctionB8t<,

This verifies the solution.


In[3]:=

eqns . sol Simplify

Out[3]= 88True, True<<

Here is an inhomogeneous system derived from the previous example.


In[4]:=

eqns = 8x '@tD - y@tD Sin@tD, x@tD + y@tD == 1<;

72

Differential Equation Solving with DSolve

The general solution is composed of the general solution to the corresponding homogeneous system and a particular solution to the inhomogeneous equation.
In[5]:=

sol = 8x@tD, y@tD< . DSolve@eqns, 8x@tD, y@tD<, tD@@1DD Expand


1 4 -t C@1D Cos@tD 2 + Sin@tD 2 , 1 4 -t C@1D + Cos@tD 2 Sin@tD 2 >

Out[5]= :1 +

This solves an initial value problem for the previous equation.


In[6]:= In[7]:=

eqns = 8x '@tD - y@tD Sin@tD, x@tD + y@tD == 1, x@PiD == 1 2<; sol = DSolve@eqns, 8x, y<, tD
-t I2 p - 2 t + t Cos@tD - t Sin@tDMF, 2 1 -t I2 p + t Cos@tD - t Sin@tDMF>> y FunctionB8t<, 2 1

Out[7]= ::x FunctionB8t<, -

Here is a plot of the solution and the constraint (algebraic) condition.


In[8]:=

Plot@8x@tD . sol, y@tD . sol, Hx@tD + y@tDL . sol<, 8t, 3, 8<D


1.5

1.0

Out[8]=

0.5

-0.5

In this DAE, the inhomogeneous part is quite general.


In[9]:= In[10]:=

Clear@x, y, z, f, g, h, tD eqns = 8x@tD + y '@tD f@tD, 2 y@tD + z '@tD g@tD, 5 z@tD h@tD<; Note that there are no degrees of freedom in the solution (that is, there are no arbitrary constants) because z@tD is given algebraically, and thus x@tD and y@tD can be determined uniquely from z@tD using differentiation.

In[11]:=

sol = DSolve@eqns, 8x, y, z<, tD


g @tD 2 + h @tD 10 F, y FunctionB8t<, g@tD 2 h @tD 10 F, z FunctionB8t<, h@tD 5 F>>

Out[11]= ::x FunctionB8t<, f@tD -

In[12]:=

eqns . sol Simplify

Out[12]= 88True, True, True<<

In this example, the algebraic constraint is present only implicitly: all three equations contain derivatives of the unknown functions.

Differential Equation Solving with DSolve

73

In this example, the algebraic constraint is present only implicitly: all three equations contain derivatives of the unknown functions.
In[13]:= In[14]:=

Clear@x1, x2, x3, t, eqnsD eqns = 8x2@tD + 2 x3@tD + x1 @tD - 2 x3 @tD == 0, - 27 x1@tD - 22 x2@tD - 17 x3@tD - x1 @tD + 2 x3 @tD == 0, 18 x1@tD + 14 x2@tD + 10 x3@tD + 2 x1 @tD + 3 x2 @tD + 2 x3 @tD == 0<; The Jacobian with respect to the derivatives of the unknown functions is singular, so that it is not possible to solve for them.

In[15]:=

A = D@eqns@@All, 1DD, 88x1 '@tD, x2 '@tD, x3 '@tD<<D

Out[15]= 881, 0, -2<, 8-1, 0, 2<, 82, 3, 2<<

In[16]:=

Det@AD

Out[16]= 0

The differential-algebraic character of this problem is clear from the smaller number of arbitrary constants (two rather than three) in the general solution.
In[17]:=

sol = DSolve@eqns, 8x1, x2, x3<, tD


3 2 x2 FunctionB8t<, -9 2 t3 C@2D + 2 C@1D x3 FunctionB8t<, -C@1D + 18 2 t3 C@2D + 3 2 I-1 + 2 t3 M C@2DF, 3 2 I-1 + 2 t3 M C@2DF>> I-1 + 2 t3 M C@2D F,

2 t3 C@2D + Out[17]= ::x1 FunctionB8t<, -C@1D - 3

Systems of equations with higher-order derivatives are solved by reducing them to first-order systems.
Here is the general solution to a homogeneous DAE of order two with constant coefficients.
In[18]:= In[19]:=

eqns = 8x ''@tD == y@tD, x@tD + 4 y@tD == 0<; sol = DSolve@eqns, 8x, y<, tD
t 1 t 16 t t C@2D CosB F C@1D CosB F + 2 C@2D SinB F F, C@1D SinB F + 125 2 2 2 125 2 2 44 t 1 t 4 t t C@2D CosB F C@1D CosB F + 2 C@2D SinB F F>> C@1D SinB F y FunctionB8t<, 125 2 2 2 125 2 2 176

Out[19]= ::x FunctionB8t<,

In[20]:=

eqns . sol Simplify

Out[20]= 88True, True<<

This inhomogeneous system of ODEs is based on the previous example.


In[21]:=

eqns = 8x ''@tD == y@tD, x@tD + 4 y@tD == 6 Sin@tD<;

74

Differential Equation Solving with DSolve

In[22]:=

sol = DSolve@eqns, 8x, y<, tD


t 1 t 1 C@2D CosB F C@1D SinB F + H-8 Cos@tD - 22 Sin@tDL + 125 2 2 2 16 16 t t 1 C@1D CosB F + 2 C@2D SinB F + H44 Cos@tD - 4 Sin@tDL F, 125 2 2 8 44 t 1 t 1 C@2D CosB F C@1D SinB F + H-8 Cos@tD - 22 Sin@tDL y FunctionB8t<, 125 2 2 2 16 4 t t 1 3 Sin@tD C@1D CosB F + 2 C@2D SinB F + H44 Cos@tD - 4 Sin@tDL + F>> 125 2 2 8 2 176

Out[22]= ::x FunctionB8t<,

In[23]:=

eqns . sol Simplify

Out[23]= 88True, True<<

Here is an initial value problem for the previous system of equations.


In[24]:= In[25]:=

eqns = 8x ''@tD == y@tD, x@tD + 4 y@tD == Sin@tD, x@PiD == 1, x '@PiD == 0<; sol = DSolve@eqns, 8x, y<, tD
t t 2 CosB F + 3 SinB F - Sin@tD F, 3 2 2 1 t t -2 CosB F - 3 SinB F + 4 Sin@tD F>> y FunctionB8t<, 12 2 2 1

Out[25]= ::x FunctionB8t<,

Here is a plot of the solution.


In[26]:=

Plot@8x@tD . sol, y@tD . sol<, 8t, - 7, 7<D


1.0

0.5

-6

-4

-2

Out[26]=
-0.5

-1.0

-1.5

Finally, here is a system with a third-order ODE. Since the coefficients are exact quantities, the computation takes some time.
In[27]:= In[28]:=

Clear @p, q, rD eqns = 8p '''@tD - q@tD + r@tD - Sin@tD, p ''@tD - r@tD - Cos@tD, p '@tD - q@tD + 4, p@0D - 1, p '@0D - 1, p ''@0D - 1<;

Differential Equation Solving with DSolve

75

In[29]:=

Timing@sol = DSolve@H1 == 0 &L eqns, 8p, q, r<, tDD

Out[29]= :9.156,

::p FunctionB8t<, 5 J-1 +


1

1 5 N J1 +
t

4 -410 - 17 2 5 N
+
1 2 5 t 2

-1-

+9

5 2

-1-

- 17 2

-1+

5 2
t

-1+
1 2

+ 440 2
t

-1-

+ 20 t - 34 Cos@tD +
t

33 2

5 t 2

-1-

Cos@tD - 118 Sin@tD + 121 2


1

5 t 2

1 2

-1-

Sin@tD F,
t
1

q FunctionB8t<,
t

1 5

20 + 14 2
5 t
t

-1-

-4
5

5 2
t

-1-

+ 14 2
5 t 2

-1+

+4

5 2

-1+

20 2

5 t 2

1 2

-1-

- 3 2
-15

5 t 2

1 2

-1-

Cos@tD - 2
5 t

1 2

-1-

Sin@tD F,
1

r FunctionB8t<,
t

1 5

3 2
5 t 2

-5

5 2

-1-

+ 3 2
-15

-1+

+5

5 2

-1+

5 Cos@tD - 2

1 2

-1-

Cos@tD + 3 2

5 t 2

1 2

Sin@tD F>>>

In[30]:=

eqns . sol Simplify

Out[30]= 880, 0, 0, 0, 0, 0<<

The symbolic solution of DAEs that are nonlinear or have non-constant coefficients is a difficult problem. Such systems can often be solved numerically with the Mathematica function NDSolve .

76

Differential Equation Solving with DSolve

Initial and Boundary Value Problems


Introduction to Initial and Boundary Value Problems
DSolve can be used for finding the general solution to a differential equation or system of differential equations. The general solution gives information about the structure of the complete solution space for the problem. However, in practice, one is often interested only in particular solutions that satisfy some conditions related to the area of application. These conditions are usually of two types. The solution xHtL and/or its derivatives are required to have specific values at a single point, for example, xH0L ! 1 and x H0L ! 2. Such problems are traditionally called initial value problems (IVPs) because the system is assumed to start evolving from the fixed initial point (in this case, 0). The solution xHtL is required to have specific values at a pair of points, for example, xH0L ! 3 and xH1L ! 5. These problems are known as boundary value problems (BVPs) because the points 0 and 1 are regarded as boundary points (or edges) of the domain of interest in the application. The symbolic solution of both IVPs and BVPs requires knowledge of the general solution for the problem. The final step, in which the particular solution is obtained using the initial or boundary values, involves mostly algebraic operations, and is similar for IVPs and for BVPs. IVPs and BVPs for linear differential equations are solved rather easily since the final algebraic step involves the solution of linear equations. However, if the underlying equations are nonlinear, the solution could have several branches, or the arbitrary constants from the general solution could occur in different arguments of transcendental functions. As a result, it is not always possible to complete the final algebraic step for nonlinear problems. Finally, if the underlying equations have piecewise (that is, discontinuous) coefficients, an IVP naturally breaks up into simpler IVPs over the regions in which the coefficients are continuous.

Differential Equation Solving with DSolve

77

Linear IVPs and BVPs


To begin, consider an initial value problem for a linear first-order ODE.
This is a linear first-order ODE.
In[1]:=

linearequation = y '@tD - 3 * t * y@tD 1; Notice that the general solution is a linear function of the arbitrary constant C @1D.

In[2]:=

generalsolution = DSolve@linearequation, y@tD, tD


3 t2 3 t2

Out[2]= ::y@tD

C@1D +

p 6

ErfB

3 2

tF>>

This finds a particular solution for the initial condition y@0D == 4.


In[3]:=

particularsolution = DSolve@8linearequation, y@0D 4<, y, tD


1 6
3 t2

Out[3]= ::y FunctionB8t<,

24 +

6 p ErfB

3 2

tF F>>

This verifies that the solution satisfies both the equation and the initial condition.
In[4]:=

linearequation . particularsolution@@1DD

Out[4]= True

In[5]:=

y@0D . particularsolution@@1DD

Out[5]= 4

Here is the solution to the same problem with the general initial condition y@0D == a.
In[6]:=

particularsolution = DSolve@8linearequation, y@0D a<, y, tD


1 6
3 t2

Out[6]= ::y FunctionB8t<,

6a+

6 p ErfB

3 2

tF F>>

78

Differential Equation Solving with DSolve

This plots several integral curves of the equation for different values of a. The plot shows that the solutions have an inflection point if the parameter a lies between -1 and 1, while a global maximum or minimum arises for other values of a.
In[7]:=

Plot@Evaluate@Table@y@tD . particularsolution@@1DD . a i, 8i, - 2, 2, 0.6<DD, 8t, - 1.8, 1.8<, PlotRange 8- 4, 4<D


4

Out[7]=

-1.5

-1.0

-0.5

0.5

1.0

1.5

-2

-4

Here is the solution to a linear second-order equation with initial values prescribed for x@tD and x @tD at t == 0.
In[8]:= In[9]:=

linearsecondorderODE = x ''@tD + 5 * x '@tD + 6 * x@tD 0; generalsolution = DSolve@linearsecondorderODE, x, tD

-3 t C@1D + -2 t C@2DE== Out[9]= 99x FunctionA8t<,

In[10]:=

particularsolution = DSolve@8linearsecondorderODE, x@0D 1, x '@0D 1<, x, tD

-3 t I-3 + 4 t ME== Out[10]= 99x FunctionA8t<,

This verifies that the solution satisfies the equation and the initial conditions.
In[11]:=

linearsecondorderODE . particularsolution@@1DD Simplify

Out[11]= True

In[12]:=

x@0D . particularsolution@@1DD

Out[12]= 1

In[13]:=

x '@0D . particularsolution@@1DD

Out[13]= 1

Differential Equation Solving with DSolve

79

Here is a plot of the solution.


In[14]:=

Plot@x@tD . particularsolution, 8t, - 1 3, 2<D


1.0 0.8 0.6 0.4 0.2

Out[14]=

0.5 -0.2

1.0

1.5

2.0

To get more information about the solutions for the problem, set x @0D == x0.
In[15]:=

particularsolution = DSolve@8linearsecondorderODE, x@0D 1, x '@0D x0<, x, tD

-3 t I-2 + 3 t - x0 + t x0ME== Out[15]= 99x FunctionA8t<,

Here is a plot of the solutions for different initial directions. The solution approaches - or as t - according to whether the value of x0 is less than or greater than -2, which is the largest root of the auxiliary equation for the ODE.
In[16]:=

Show@GraphicsArray@Partition@ Table@Plot@Evaluate@x@tD . particularsolution@@1DD . x0 iD, 8t, - 1, 3<, PlotStyle 8Red<, PlotLabel StringJoin@"x0= ", ToString@iDD, Ticks NoneD, 8i, - 4, 1<D, 83<D, ImageSize 400DD
x0= -4 x0= -3 x0= -2

Out[16]=

x0= -1

x0= 0

x0= 1

Here is a BVP for an inhomogeneous linear second-order equation.


In[17]:= In[18]:=

inhomogeneousequation = y ''@xD + y@xD E ^ x; generalsolution = DSolve@inhomogeneousequation, y, xD


1 2 x ICos@xD2 + Sin@xD2 MF>>

Out[18]= ::y FunctionB8x<, C@1D Cos@xD + C@2D Sin@xD +

80

Differential Equation Solving with DSolve

In[19]:=

DSolve@8inhomogeneousequation, y@0D 1, y@1D 1 2<, y, xD


ICos@xD + x Cos@xD2 - Cot@1D Sin@xD 2 Cos@1D Cot@1D Sin@xD + Csc@1D Sin@xD - Sin@1D Sin@xD + x Sin@xD2 MF>> 1

Out[19]= ::y FunctionB8x<,

It should be noted that, in contrast to initial value problems, there are no general existence or uniqueness theorems when boundary values are prescribed, and there may be no solution in some cases.
This problem has no solution because the term with C @2D in the general solution vanishes at both x ! 0 and x ! p. Hence there are two inconsistent conditions for the parameter C @1D and the solution is an empty set.
In[20]:=

DSolve@8inhomogeneousequation, y@0D 1, y@PiD 6<, y, xD


DSolve::bvnul : For some branches of the general solution, the given boundary conditions lead to an empty solution.

Out[20]= 8<

The previous discussion of linear equations generalizes to the case of higher-order linear ODEs and linear systems of ODEs.
Here is the solution to an Initial Value Problem (IVP) for a linear ODE of order four.
In[21]:= In[22]:=

fourthorderODE = y ''''@xD + 2 * y ''@xD + y@xD Cos@xD; sol = DSolve@8fourthorderODE, y@0D 1, y '@0D 6, y ''@0D 3, y '''@0D - 1<, y, xD
I11 Cos@xD - 40 x Cos@xD - 2 x2 Cos@xD + 16 4 Cos@xD3 + Cos@xD Cos@2 xD + 136 Sin@xD + 34 x Sin@xD + 3 Sin@xD Sin@2 xDMF>> 1

Out[22]= ::y FunctionB8x<,

This verifies the solution and the initial conditions.


In[23]:=

8fourthorderODE, y@0D, y '@0D, y ''@0D, y '''@0D< . sol Simplify

Out[23]= 88True, 1, 6, 3, -1<<

Since this is a fourth-order ODE, four independent conditions must be specified to find a particular solution for an IVP. If there is an insufficient number of conditions, the solution returned by DSolve may contain some of the arbitrary parameters, as follows.
In[24]:=

DSolve@8fourthorderODE, y@0D 1, y '@0D 6<, y, xD


I11 Cos@xD + 96 x Cos@xD - 2 x2 Cos@xD - 16 x C@3D Cos@xD + 4 Cos@xD3 + 16 Cos@xD Cos@2 xD + 4 x Sin@xD + 16 C@3D Sin@xD + 16 x C@4D Sin@xD + 3 Sin@xD Sin@2 xDMF>> 1

Out[24]= ::y FunctionB8x<,

Differential Equation Solving with DSolve

81

Finally, here is the solution of an IVP for a linear system of ODEs.


In[25]:= In[26]:= In[27]:= In[28]:=

Clear@x, y, z, tD linearsystem = 8x '@tD x@tD - 4 * y@tD + 1, y '@tD 4 * x@tD + y@tD, z '@tD z@tD<; initialvalues = 8x@0D 2, y@0D - 1, z@0D 1<; sol = DSolve@Join@linearsystem, initialvaluesD, 8x, y, z<, tD
1 17 1 I35 t Cos@4 tD - Cos@4 tD2 + 21 t Sin@4 tD - Sin@4 tD2 MF,

Out[28]= ::x FunctionB8t<,

I-21 t Cos@4 tD + 4 Cos@4 tD2 + 35 t Sin@4 tD + 4 Sin@4 tD2 MF, 17 z FunctionA8t<, t E>> y FunctionB8t<,

This verifies that the solution satisfies the system and the initial conditions.
In[29]:=

8linearsystem, initialvalues< . sol@@1DD Simplify

Out[29]= 88True, True, True<, 8True, True, True<<

The solutions x@tD, y@tD, and z@tD are parametrized by the variable t and can be plotted separately in the plane or as a curve in space.
In[30]:=

Plot@Evaluate@8x@tD, y@tD, z@tD< . solD, 8t, - 2, 1<D


4

Out[30]=
-2.0 -1.5 -1.0 -0.5 0.5 1.0

-2

-4

82

Differential Equation Solving with DSolve

In[31]:=

ParametricPlot3D@Evaluate@8x@tD, y@tD, z@tD< . solD, 8t, - 7, - 3<, PlotRange AllD

0.04

Out[31]= 0.02
0.00 0.10 0.05 0.00 0.05 0.15 0.20 0.25

Nonlinear IVPs and BVPs


Many real-world applications require the solution of IVPs and BVPs for nonlinear ODEs. For example, consider the logistic equation, which occurs in population dynamics.
This is the logistic equation.
In[1]:=

LogisticEquation = y '@tD r H1 - Hy@tD KLL * y@tD; The right-hand side of the equation can be expanded to a quadratic polynomial in y@tD. Hence, the logistic equation is simply a Riccati equation, and its general solution can be easily found.

In[2]:=

DSolve@LogisticEquation, y, tD
r t+K C@1D K -1 + r t+K C@1D F>>

Out[2]= ::y FunctionB8t<,

This sets the intrinsic growth rate r to 1 2 and the saturation level K to 4 and solves the initial value problem. The warning message from Solve is issued while solving for the arbitrary constant C @1D from the general solution.
In[3]:=

DSolve@8LogisticEquation . 8r H1 2L, K 4<, y@0D 1<, y, tD


Solve::ifun : Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.

Out[3]= ::y FunctionB8t<,

4 t2 3 + t2

F>>

Differential Equation Solving with DSolve

83

This solves the initial value problem for the logistic equation with symbolic parameters r and K.
In[4]:=

sol = DSolve@8LogisticEquation, y@0D a * K<, y, tD


Solve::ifun : Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.

Out[4]= ::y FunctionB8t<,

a r t K 1 - a + a r t

F>>

This verifies that the solution satisfies the equation and the initial condition.
In[5]:=

8LogisticEquation, y@0D< . sol@@1DD Simplify

Out[5]= 8True, a K<

Here is a plot of the solution for different values of r and K.


In[6]:=

Plot@Evaluate@Table@y@tD . sol@@1DD . 8K 4, a i, r H1 3L<, 8i, 2, 1 10, - 1 3<DD, 8t, 0, 8<, PlotRange AllD
8 7 6 5 4 3

Out[6]=

Here is an example of an IVP for a second-order nonlinear ODE whose general solution can be obtained in explicit form.
In[7]:= In[8]:=

eqn = y ''@xD - H1 2L * Hy '@xD ^ 2 y@xDL + 1 H2 * y@xDL 0; sol = DSolve@8eqn, y@0D 1, y '@0D 2<, y, xD
1 4 I4 + 8 x + 3 x2 MF>>

Out[8]= ::y FunctionB8x<,

This verifies that the solution satisfies the equation and the initial conditions.
In[9]:=

8eqn, y@0D, y '@0D< . sol@@1DD Simplify

Out[9]= 8True, 1, 2<

Finally, here is a boundary value problem for a nonlinear second-order ODE. The solution is required to satisfy boundary conditions at 0 and infinity. The Solve::ifun message is generated while finding the general solution in terms of JacobiSN , the inverse of EllipticF. The DSolve::bvlim messages are given because the limit required for satisfying the condition y @Infinity D 0 cannot be calculated for either branch of the general solution. However, the solution for the boundary value problem is found using an alternative method to determine the

84

Differential Equation Solving with DSolve

Finally, here is a boundary value problem for a nonlinear second-order ODE. The solution is required to satisfy boundary conditions at 0 and infinity. The Solve::ifun message is generated while finding the general solution in terms of JacobiSN , the inverse of EllipticF. The DSolve::bvlim messages are given because the limit required for satisfying the condition y @Infinity D 0 cannot be calculated for either branch of the general solution. However, the solution for the boundary value problem is found using an alternative method to determine the values of the constants C @1D and C @2D in the general solution.
In[10]:=

generalsolution = DSolve@8y ''@xD 2 y@xD ^ 3 - y@xD<, y@xD, xD


Solve::ifun : Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.
1 1JacobiSNB 11+ 1 - C@1D x2 + x2 1 - C@1D + 2 x C@2D + 2 x 1 11 - C@1D 1 - C@1D C@2D + C@2D2 + 1 - C@1D C@2D2 , 1 - C@1D C@2D + C@2D2 + 1 - C@1D C@2D2 ,

Out[10]= ::y@xD

1 - C@1D 1 - C@1D

F-

1 - C@1D

JacobiSNB 11+

x2 + x2

1 - C@1D + 2 x C@2D + 2 x 1 1-

1 - C@1D 1 - C@1D

F>, :y@xD -

1 - C@1D 1 - C@1D C@2D + C@2D2 + 1 - C@1D C@2D2 ,

JacobiSNB 11+

x2 + x2

1 - C@1D + 2 x C@2D + 2 x 1 11 - C@1D

1 - C@1D 1 - C@1D

F+

1 - C@1D JacobiSNB

x2 + x2

1 - C@1D + 2 x C@2D + 2 x

1 - C@1D C@2D + C@2D2 +

1 - C@1D C@2D2 ,

11+

1 - C@1D 1 - C@1D

F>>

In[11]:=

sol = DSolve@8y ''@xD 2 == y@xD ^ 3 - y@xD, y@0D == 0, y '@InfinityD == 0<, y@xD, xD


Solve::ifun : Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information. DSolve::bvlim : For some branches of the general solution, unable to compute the limit at the given points. Some of the solutions may be lost. DSolve::bvlim : For some branches of the general solution, unable to compute the limit at the given points. Some of the solutions may be lost.

Out[11]= ::y@xD -TanhB

x2 F>, :y@xD TanhB

x2 F>>

Differential Equation Solving with DSolve

85

In[12]:=

Plot@8y@xD . sol@@2DD, 1<, 8x, - 2, 2<, PlotRange AllD


1.0 0.8 0.6

Out[12]=

0.4 0.2 -2 -1 1 2

It may not always be possible to obtain a symbolic solution to an IVP or BVP for a nonlinear equation. Numerical methods may be necessary in such cases.

IVPs with Piecewise Coefficients


The differential equations that arise in modern applications often have discontinuous coefficients. DSolve can handle a wide variety of such ODEs with piecewise coefficients. Some of the functions used in these equations are UnitStep , Max, Min, Sign , and Abs. These functions and combinations of them can be converted into Piecewise objects.
This converts the given expression into a Piecewise expression.
In[1]:=

PiecewiseExpand@UnitStep@xD + Max@x, x ^ 2DD


x2 1+x x<0 0x1

Out[1]=

1 + x2 True

Here is the general solution to a first-order ODE that contains UnitStep .


In[2]:=

DSolve@y '@xD UnitStep@xD, y, xD

Out[2]= 88y Function@8x<, C@1D + x UnitStep@xDD<<

Here is the solution to the same ODE with an initial condition.


In[3]:= In[4]:=

eqn = 8y '@xD UnitStep@xD, y@0D 1<; sol = DSolve@eqn, y, xD

Out[4]= 88y Function@8x<, 1 + x UnitStep@xDD<<

86

Differential Equation Solving with DSolve

The solution can be plotted in the usual way. Note that the solution is continuous but not differentiable at x = 0.
In[5]:=

Plot@y@xD . sol, 8x, - 3, 3<D


4.0 3.5 3.0

Out[5]=

2.5 2.0 1.5

-3

-2

-1

This verifies the solution.


In[6]:=

Simplify@eqn . sol@@1DD, x > 0 x < 0D

Out[6]= 8True, True<

Here is a piecewise ODE that has Max in its coefficients.


In[7]:=

sol = DSolve@ 8y '@xD + Max@x, 1D y@xD 0, y@0D 1<, y@xD, x D


-x
- 2 1 x2 2

Out[7]= ::y@xD

x1 >> True

In[8]:=

Plot@y@xD . sol, 8x, - 3, 3<D


20

15

Out[8]=

10

-3

-2

-1

A piecewise ODE can be thought of as a collection of ODEs over disjoint intervals such that the expressions for the coefficients and the boundary conditions change from one interval to another. Thus, different intervals have different solutions, and the final solution for the ODE is obtained by patching together the solutions over the different intervals.
For this piecewise ODE, the expression for FinalSol is obtained by patching together SolFromMinusInfinityToTwo and SolFromTwoToInfinity. The boundary condition for the interval H- Infinity, 2D is simply y@0D = 1, while the initial condition for the interval @2, Infinity L is y@2D ! 2 (given by the final value for the solution over the first interval).

Differential Equation Solving with DSolve

87

For this piecewise ODE, the expression for FinalSol is obtained by patching together SolFromMinusInfinityToTwo and SolFromTwoToInfinity. The boundary condition for the interval H- Infinity, 2D is simply y@0D = 1, while the initial condition for the interval @2, Infinity L is y@2D ! 2 (given by the final value for the solution over the first interval).
In[9]:=

FinalSol = DSolve@ 8y '@tD If@ t 2, y@tD, - y@tD 2D , y@0D 1<, y, tD


t
3t 2

Out[9]= ::y FunctionB8t<,

t2 True

F>>

In[10]:=

SolFromMinusInfinityToTwo = DSolve@8y '@tD y@tD, y@0D 1<, y, tD

t Out[10]= 99y FunctionA8t<, E==

In[11]:=

SolFromTwoToInfinity = DSolve@8y '@tD - y@tD 2, y@2D E ^ 2<, y, tD


3t 2

Out[11]= ::y FunctionB8t<,

F>>

If there are a large number of discontinuities in a problem, it is convenient to use Piecewise directly in the formulation of the problem.
This second-order ODE contains a Piecewise term.
In[12]:= In[13]:=

eqn = 8y ''@tD + y@tD Piecewise@88- 1, t < 0<, 81, t < 1<, 8Sin@tD, t < 2<<D, y@0D 1, y '@0D 1<; sol = DSolve@ eqn, y, t D

Out[13]= ::y FunctionB8t<,

-1 + 2 Cos@tD + Sin@tD 1 + Sin@tD


1 4 ICos@1D2 +Sin@1D2 M

t 0< 1<
2 2

I4 Cos@1D Cos@tD + 2 Cos@1D Cos@tD - 2 t Cos@1D Cos@tD - 2 Cos@1D Cos@tD Sin@1D + 2 Cos@tD Sin@1D2 - 2 t Cos@tD Sin@1D2 + 6 Cos@1D2 Sin@tD - 2 Cos@1D2 Cos@tD2 Sin@tD + 4 Sin@1D Sin@tD + 4 Sin@1D2 Sin@tD - 2 Cos@tD2 Sin@1D2 Sin@tD + Cos@1D2 Cos@tD Sin@2 tD + Cos@tD Sin@1D2 Sin@2 tDM
1 4 ICos@2D2 +Sin@2D2 M

True
2

I4 Cos@1D Cos@2D Cos@tD - 2 Cos@2D Cos@tD - Cos@tD Sin@2D + 2 Cos@2D Cos@tD Sin@2D + 4 Cos@tD Sin@1D Sin@2D - 2 Cos@tD Sin@2D2 + Cos@2D Sin@tD + 3 Cos@2D2 Sin@tD 4 Cos@2D Sin@1D Sin@tD + 4 Cos@1D Sin@2D Sin@tD + 5 Sin@2D2 Sin@tDM F>>

This ODE contains the Clip function. The solutions are given in terms of Airy functions.
In[14]:=

eqn = 8y ''@xD - Clip@xD * y@xD 0, y@0D 0, y '@0D - 1<;

88

Differential Equation Solving with DSolve

In[15]:=

DSolve@eqn, y, xD

Out[15]= ::y FunctionB8x<,


1 6 ICos@1D2 +Sin@1D2 M 1 1 3

x
56 3 1 3

J3 3

13

AiryAi@-1D Cos@1D Cos@xD GammaB F - 3

AiryBi@-1D Cos@1D Cos@xD GammaB F +

33

13

AiryAiPrime@-1D Cos@xD GammaB F Sin@1D - 356 AiryBiPrime@-1D


1 3 1 3

Cos@xD GammaB F Sin@1D + 3 313 AiryAiPrime@-1D Cos@1D GammaB F Sin@xD 356 AiryBiPrime@-1D Cos@1D GammaB F Sin@xD - 3 313 AiryAi@-1D GammaB F Sin@1D Sin@xD +
3 3 1 1

356 AiryBi@-1D GammaB F Sin@1D Sin@xDN


3 1 6

J3 313 AiryAi@xD GammaB F - 356 AiryBi@xD GammaB FN


3 3 1 4 323

-1 < True

-1-x 2

J-3 AiryAi@1D - 3
2x

2x

AiryAi@1D + 3 AiryBi@1D + 3 2 x AiryBiPrime@1DN GammaB F


3 1 2

3 AiryAiPrime@1D - 3 3 2 x AiryBi@1D F>>

AiryAiPrime@1D +

3 2 AiryBiPrime@1D +

Differential Equation Solving with DSolve

89

Working with DSolve~A Users Guide


Introduction to Working with DSolve
The aim of these tutorials is to provide a self-contained working guide for solving different types of problems with DSolve. The first step in using DSolve is to set up the problem correctly. The next step is to use DSolve to get an expression for the solution. Once the solution has been found, it can be verified using symbolic or numerical techniques, or it can be plotted using a Mathematica function such as Plot , Plot3D, or ContourPlot . Plots often reveal information about the solution that might not be evident from its closed-form expression. If no boundary conditions are specified for a problem, the output from DSolve is some form of a general solution containing arbitrary parameters. The GeneratedParameters option can be used to label these arbitrary parameters. In many applications, differential equations contain symbolic parameters, such as the rate of growth in the logistic equation. A differential equation can also contain inexact quantities, such as machine numbers arising from previous calculations. Both symbolic parameters and inexact quantities are allowed by DSolve, but it is good to be aware of their presence and interpret the solution correctly. When DSolve makes any assumptions or encounters difficulty during a calculation, it issues a warning message outlining the problem. These messages can usually be ignored, but sometimes they point to serious limitations in the answer given for the problem. It is helpful to analyze the statement of the problem for possible ambiguities~in other words, to make sure that the problem is well posed~so that meaningful answers can be obtained from DSolve.

90

Differential Equation Solving with DSolve

Setting Up the Problem


The first argument given to DSolve is the differential equation, the second argument is the unknown function, and the last argument identifies the independent variable.
Here is the input for solving for a first-order linear ODE using DSolve. The variable sol identifies the solution for use in further work.
In[1]:=

sol = DSolve@y '@xD + 5 y@xD 1, y@xD, xD


1 5 + -5 x C@1D>>

Out[1]= ::y@xD

The output of DSolve is a list of solutions for the differential equation. The extra list is required since some equations have multiple solutions. Here, since the equation is of order 1 and is linear, there is only one solution: y@xD
1 5

+ -5 x C @1D. The solution has an undetermined

constant C @1D because no initial condition was specified. The solution can be extracted from the list of solutions using a part specification.
This extracts the solution.
In[2]:=

m = sol@@1DD
1 5 + -5 x C@1D>

Out[2]= :y@xD

This form of the solution is useful for finding y@xD itself, but not for finding derivatives of y@xD or the value of y@xD at a point.
This shows the value of y@xD given by the solution.
In[3]:= Out[3]=

y@xD . m
1 5 + -5 x C@1D

The solution does not apply to y @ xD or y@1D because the solution is a rule for y@xD only.
In[4]:=

y '@xD . m

Out[4]= y @xD

In[5]:=

y@1D . m

Out[5]= y@1D

If the solution will be used in further work, it is best to specify the unknown function using y rather than y@xD. This gives the solution using pure functions of the type Function @x, exprD.

Differential Equation Solving with DSolve

91

If the solution will be used in further work, it is best to specify the unknown function using y rather than y@xD. This gives the solution using pure functions of the type Function @x, exprD.
Here, the unknown function is specified as y. The solution is a pure function.
In[6]:=

sol = DSolve@y '@xD + 5 y@xD 1, y, xD


1 5 + -5 x C@1DF>>

Out[6]= ::y FunctionB8x<,

When the solution is in the form of pure functions, expressions can be found for derivatives of y and for the values of y at specific points.
This gives expressions for y@xD, y @ xD, and y@1D.
In[7]:=

m = sol@@1DD
1 5 + -5 x C@1DF>

Out[7]= :y FunctionB8x<,

In[8]:= Out[8]=

y@xD . m
1 5 + -5 x C@1D

In[9]:=

y '@xD . m

-5 x C@1D Out[9]= -5

In[10]:= Out[10]=

y@1D . m
1 5 + C@1D 5

When a problem has multiple solutions, you can pick out individual solutions from the solution list or you can work directly with the list.
This solves a nonlinear first-order equation. There are two solutions.
In[11]:=

sol = DSolve@y '@xD ^ 2 x + 11, y, xD


2 3 H11 + xL32 + C@1DF>, :y FunctionB8x<, 2 3 H11 + xL32 + C@1DF>>

Out[11]= ::y FunctionB8x<, -

The solutions can be extracted using part specifications.


In[12]:=

y@xD . sol@@1DD
2 3 H11 + xL32 + C@1D

Out[12]= -

92

Differential Equation Solving with DSolve

In[13]:= Out[13]=

y@xD . sol@@2DD
2 3 H11 + xL32 + C@1D

This returns a list of both expressions.


In[14]:=

y@xD . sol
2 3 H11 + xL32 + C@1D, 2 3 H11 + xL32 + C@1D>

Out[14]= :-

To solve a system of equations, the first argument to DSolve must be a list of the equations and the second argument must be a list of the unknown functions.
Here is an example of a system of first-order linear equations with three unknowns. Because this system is linear, there is only one solution.
In[15]:=

sol = DSolve@ 8x '@tD y@tD + z@tD, y '@tD + z@tD - x@tD 0, z '@tD + y@tD x@tD<, 8x, y, z<, tD
1 3 1 3 1 3 -2 t I1 + 2 3 t M C@1D + -2 t I-1 + 3 t M C@1D + -2 t I-1 + 3 t M C@1D 1 3 1 3 1 3 -2 t I-1 + 3 t M C@2D + -2 t I1 + 2 3 t M C@2D -2 t I-1 + 3 t M C@2D + 1 3 1 3 1 3 -2 t I-1 + 3 t M C@3DF, -2 t I-1 + 3 t M C@3DF, -2 t I1 + 2 3 t M C@3DF>>

Out[15]= ::x FunctionB8t<,

y FunctionB8t<, z FunctionB8t<,

Each solution to the system is a list of replacement rules for the unknown functions. The expressions for the unknown functions can be extracted as in previous examples.
This gives a list of the expressions for the unknown functions. Simplify is used to return the expressions in a compact form.
In[16]:=

8x@tD, y@tD, z@tD< . sol@@1DD Simplify


1 3 1 3 1 3 -2 t II1 + 2 3 t M C@1D + I-1 + 3 t M HC@2D + C@3DLM, -2 t II-1 + 3 t M C@1D + C@2D + 2 3 t C@2D + C@3D - 3 t C@3DM, -2 t II-1 + 3 t M C@1D + C@2D - 3 t C@2D + C@3D + 2 3 t C@3DM>

Out[16]= :

If initial conditions are prescribed for the problem, some or all of the undetermined constants can be eliminated.
Here the value of the unknown function and its derivative are both prescribed at the initial point.
In[17]:=

DSolve@8y ''@xD + y@xD 5, y@0D 1, y '@0D 7<, y@xD, xD

Out[17]= 88y@xD 5 - 4 Cos@xD + 7 Sin@xD<<

If only the initial value is specified, then the solution still contains an arbitrary constant.

Differential Equation Solving with DSolve

93

If only the initial value is specified, then the solution still contains an arbitrary constant.
In[18]:=

DSolve@8y ''@xD + y@xD 5, y@0D 1<, y@xD, xD

Out[18]= 88y@xD 5 - 4 Cos@xD + C@2D Sin@xD<<

For a partial differential equation, the third argument to DSolve is a list of the independent variables for the equation.
This solves a PDE with independent variables x and y. C @1D represents an arbitrary function of y + Cos@y@xDD.
In[19]:=

DSolve@D@u@x, yD, xD + Sin@xD * D@u@x, yD, yD 8, u, 8x, y<D

Out[19]= 88u Function@8x, y<, 8 x + C@1D@y + Cos@xDDD<<

A differential-algebraic equation is specified in the same way as a system of ordinary differential equations.
Here is an example of a DAE with an initial condition.
In[20]:=

DSolve@8x '@tD + y@tD Sin@tD, x@tD + y@tD 1, x@0D 4<, 8x, y<, tD
1 2 I2 + 7 t - Cos@tD - Sin@tDMF, y FunctionB8t<, 1 2 I-7 t + Cos@tD + Sin@tDMF>>

Out[20]= ::x FunctionB8t<,

Note that it is not always possible to give the solutions for a problem in explicit form. In this case, the solution is given using an unevaluated Solve object or using InverseFunction .
The solution to this equation is not available explicitly. The output represents an implicit solution.
In[21]:=

sol = DSolve@y '@xD + y@xD ^ 3 + y@xD ^ 2 1, y@xD, xD


Solve::tdep : The equations appear to involve the variables to be solved for in an essentially non-algebraic way. Solve::tdep : The equations appear to involve the variables to be solved for in an essentially non-algebraic way.

2 3 Out[21]= SolveBRootSumB-1 + 1 + 1 &,

Log@-1 + y@xDD 2 1 + 3 12

&F -x + C@1D, y@xDF

The solution can be extracted as usual with a part specification.


In[22]:=

sol@@1DD
Log@-1 + y@xDD 2 1 + 3 12 &F -x + C@1D

2 3 Out[22]= RootSumB-1 + 1 + 1 &,

94

Differential Equation Solving with DSolve

The solutions to this equation are given as InverseFunction objects.


In[23]:=

sol = DSolve@Derivative@2D@yD@xD + y@xD * Derivative@1D@yD@xD ^ 4 == 0, y, xD


Solve::tdep : The equations appear to involve the variables to be solved for in an essentially non-algebraic way. Solve::tdep : The equations appear to involve the variables to be solved for in an essentially non-algebraic way.

Out[23]= ::y FunctionB8x<,

InverseFunctionBC@1D LogB1 +

-2 C@1D + 12 F -

1 2

-2 C@1D + 12 &F@x + C@2DDF>, :y 1 2 1 -2 C@1D + 12 &F@x + C@2DDF>>

FunctionB8x<, InverseFunctionB-C@1D LogB1 +

-2 C@1D + 12 F +

Each solution can be rewritten as an implicit equation by eliminating the InverseFunction object as follows.
In[24]:=

soly = y@xD . sol@@1DD


-2 C@1D + 12 F 1 2 1 -2 C@1D + 12 &F@x + C@2DD

Out[24]= InverseFunctionBC@1D LogB1 +

In[25]:=

implicitequation = H Head@solyD@@1DD@y@xDD == soly@@1DD L


-2 C@1D + y@xD2 F 1 2 y@xD -2 C@1D + y@xD2 x + C@2D

Out[25]= C@1D LogBy@xD +

Verification of the Solution


The solution given by DSolve can be verified using various methods. The easiest method involves substituting the solution back into the equation. If the result is True , the solution is valid.
In this simple example, the solution is verified by substitution. Note that the first argument to DSolve is assigned to eqn for convenience in later work.
In[1]:= In[2]:=

eqn = y '@xD x; sol = DSolve@eqn, y, xD


x2 2 + C@1DF>>

Out[2]= ::y FunctionB8x<,

In[3]:=

eqn . sol

Out[3]= 8True<

Differential Equation Solving with DSolve

95

In this example, the equation and an initial condition are verified by substitution.
In[4]:= In[5]:=

eqn = 8y '@xD x, y@0D 1<; sol = DSolve@eqn, y, xD


1 2 I2 + x2 MF>>

Out[5]= ::y FunctionB8x<,

In[6]:=

eqn . sol

Out[6]= 88True, True<<

Sometimes the result of the substitution is more complicated than True or False . Such examples can be verified by using Simplify to simplify the result of the substitution. If the simplified result is True , the solution is valid.
Here is the general solution for a second-order inhomogeneous equation.
In[7]:= In[8]:=

eqn = y ''@xD + 5 * y '@xD + 6 y@xD 1; sol = DSolve@eqn, y, xD


1 6 + -3 x C@1D + -2 x C@2DF>>

Out[8]= ::y FunctionB8x<,

This substitutes the solution back into the equation.


In[9]:=

eqn . sol
1 6 + -3 x C@1D + -2 x C@2D 1>

-3 x C@1D + 4 -2 x C@2D + 5 I-3 -3 x C@1D - 2 -2 x C@2DM + 6 Out[9]= :9

The solution can be verified using Simplify .


In[10]:=

Simplify@eqn . solD

Out[10]= 8True<

Here is a linear PDE whose solution can be verified using Simplify .


In[11]:= In[12]:=

PDE = D@u@x, yD, xD + Sin@xD * D@u@x, yD, yD x ^ 2; sol = DSolve@PDE, u, 8x, y<D
1 3 Ix3 + 3 C@1D@y + Cos@xDDMF>>

Out[12]= ::u FunctionB8x, y<,

In[13]:=

Simplify@PDE . solD

Out[13]= 8True<

If the equation involves special functions, it may be necessary to use FullSimplify to verify the solution.

96

Differential Equation Solving with DSolve

If the equation involves special functions, it may be necessary to use FullSimplify to verify the solution.
Here is an example of this type involving Bessels functions.
In[14]:= In[15]:=

eqn = x * y ''@xD + y '@xD - y@xD 1; sol = DSolve@eqn, y, xD


x F C@1D + 2 BesselKB0, 2 x F C@2DF>>

Out[15]= ::y FunctionB8x<, -1 + BesselIB0, 2

In[16]:=

FullSimplify@eqn . solD

Out[16]= 8True<

If the solution is large or if Simplify and FullSimplify do not succeed in verifying the solution, a numerical check can be made by using RandomReal or RandomComplex to generate values for all the variables and parameters in the problem. It is advisable in such cases to repeat the check with several sets of random values.
Here is an example where numerical verification is useful.
In[17]:= In[18]:= In[19]:=

Clear@a, y, x, rD eqn = y ''@xD - Ha * x ^ 6 + x ^ 2L * y@xD; sol = DSolve@eqn 0, y, xD


a x4

238
Out[19]= ::y FunctionB8x<,

Ix4 M

38

C@1D HypergeometricUB x32

-1+3 8 a

3 4

, -

1 2

a x4 F +

a x4

238

Ix4 M

38

C@2D LaguerreLBx32

-1+3 8 a

, - , 4

1 2

a x4 F F>>

In[20]:=

Union@Flatten@Table@Chop@eqn . sol . 8x RandomReal@D, a RandomReal@D, C@1D RandomReal@D, C@2D RandomReal@D<D, 8i, 1, 10<DDD

Out[20]= 80<

Although numerical checks cannot verify a solution with certainty, more rigorous checks can be made by using higher precision or by allowing the variables to take complex values.
This verifies the previous solution with higher precision.
In[21]:=

Chop@eqn . sol . 8x RandomReal@ 81, 2<, WorkingPrecision -> 20D, a RandomReal@ 81, 2<, WorkingPrecision -> 20D, C@1D RandomReal@ 81, 2<, WorkingPrecision -> 20D , C@2D RandomReal@ 81, 2<, WorkingPrecision -> 20D<D

Out[21]= 80<

This uses complex random values to verify the previous solution.

Differential Equation Solving with DSolve

97

This uses complex random values to verify the previous solution.


In[22]:= In[23]:=

r := RandomComplex@D Chop@N@eqn . sol . 8x r, a r , C@1D r , C@2D r<DD

Out[23]= 80<

The previous methods are of use only when the solution is available in explicit form. The final example shows how to verify the solution of a first-order ODE when it is given in implicit form.
This solves a first-order ODE.
In[24]:= In[25]:=

eqn = y @xD + 2 * x y@xD2 + y@xD3 ; sol = DSolve@eqn 0, y, xD


InverseFunction::ifun : Inverse functions are being used. Values may be lost for multivalued inverses. InverseFunction::ifun : Inverse functions are being used. Values may be lost for multivalued inverses. InverseFunction::ifun : Inverse functions are being used. Values may be lost for multivalued inverses. General::stop : Further output of InverseFunction::ifun will be suppressed during this calculation. Solve::tdep : The equations appear to involve the variables to be solved for in an essentially non-algebraic way.
-x AiryAiBx2 1 y@xD 1 y@xD

F + AiryAiPrimeBx2 F + AiryBiPrimeBx2 -

1 y@xD 1 y@xD

F + C@1D 0, y@xDF F

Out[25]= SolveB

-x AiryBiBx2 In[26]:=

sol@@1DD
-x AiryAiBx2 1 y@xD 1 y@xD

F + AiryAiPrimeBx2 F + AiryBiPrimeBx2 -

1 y@xD 1 y@xD

F + C@1D 0 F

Out[26]=

-x AiryBiBx2 -

This verifies the solution by simplifying its derivative.


In[27]:=

Simplify@Solve@D@sol@@1DD, xD, y '@xDDD

2 Out[27]= 99y @xD -y@xD H2 x + y@xDL==

98

Differential Equation Solving with DSolve

Plotting the Solution


A plot of the solution given by DSolve can give useful information about the nature of the solution, for instance, whether it is oscillatory in nature. It can also serve as a means of solution verification if the shape of the graph is known from theory or from plotting the vector field associated with the differential equation. A few examples that use different Mathematica graphics functions follow.
Here is the general solution to a linear first-order equation.
In[1]:=

sol = DSolve@y '@xD + x * y@xD Cos@x ^ 2D, y, xD


x2 2

Out[1]= ::y FunctionB8x<,

C@1D +

1 2

x2 2

p 10

1 + 2 ErfiB

1 2

- xF +

1 - 2 ErfiB

1 2

+ xF F>>

The solution can be plotted for specific values of the constant C @1D using Plot . The use of Evaluate reduces the time taken by Plot and can also help in cases where the solution has discontinuities.
In[2]:=

Plot@Evaluate@y@xD . sol . 8C@1D 1<D, 8x, - 7, 7<, PlotRange AllD

1.0

Out[2]=

0.5

-6

-4

-2

Here is the plot for a linear second-order ODE with initial values prescribed at 0.
In[3]:=

sol = DSolve@8y ''@xD y@xD - 4 * Exp@- x 4D, y@0D 1, y '@0D 1 2<, y, xD


BesselJB0, 16 -x4 F BesselY@0, 16D - BesselJ@0, 16D BesselYB0, 16 -x4 F - 4 BesselJB0, 16 -x4 F BesselY@1, 16D -x4 F +

Out[3]= ::y FunctionB8x<,

4 BesselJ@1, 16D BesselYB0, 16

H4 HBesselJ@1, 16D BesselY@0, 16D - BesselJ@0, 16D BesselY@1, 16DLLF>>


In[4]:=

Plot@Evaluate@y@xD . solD, 8x, 0, 30<D


2

10

15

20

25

30

Out[4]= -2
-4 -6

This nonlinear equation has two solutions that can be plotted on the same graph.

Differential Equation Solving with DSolve

99

This nonlinear equation has two solutions that can be plotted on the same graph.
In[5]:=

sol = DSolve@8y '@xD ^ 2 x - x ^ 3, y@0D 1<, y, xD


1 5 4 x 1-x
2

Out[5]= ::y FunctionB8x<,

1 - x2 + 2 x32

1 - x2

-x I-1 + x2 M +

-x I-1 + x2 M EllipticEBArcSinB x F, -1F - 4 1 5 x 1 - x2

-x I-1 + x2 M EllipticFBArcSinB x F, -1F F>,

:y FunctionB8x<,

1 - x2 - 2 x32

1 - x2

-x I-1 + x2 M -

-x I-1 + x2 M EllipticEBArcSinB x F, -1F + 4

-x I-1 + x2 M EllipticFBArcSinB x F, -1F F>>

In[6]:=

Plot@Evaluate@y@xD . solD, 8x, 1 100, 9 10<D


1.4

1.2

Out[6]= 1.0

0.8

0.2

0.4

0.6

0.8

The solution to this Abel ODE is given in implicit form.


In[7]:=

sol = DSolveBy @xD - 5 y@xD2 -

y@xD3 x

, y@xD, xF

Solve::tdep : The equations appear to involve the variables to be solved for in an essentially non-algebraic way.
1

Out[7]= SolveB-5 x

2 2 2 C@1D +

K-5 x+

1 y@xD

, y@xDF
-5 x+
1 y@xD

2 p ErfiB

A contour plot can be used to study the nature of the solution. Each contour line corresponds to a solution to the ODE for a fixed value of C @1D.
In[8]:=

expr = C@1D . Solve@sol@@1DD, C@1DD@@1DD . 8y@xD y<


1

2 2
Out[8]= -

K-5 x+ O
y

-5 x+

1 y

+5

2 p x ErfiB
2

10 x

100

Differential Equation Solving with DSolve

In[9]:=

ContourPlot@expr, 8x, - 0.4, - 0.1<, 8y, 1., 1.8<D

Out[9]=

Here is the plot of the solutions to a system of two linear ODEs. The WorkingPrecision option in Plot is required because the solution is fairly complicated.
In[10]:=

sol = DSolve@8x '@tD + t * y@tD 0, 2 y '@tD - 3 x@tD 0, x@0D 1, y@0D 3<, 8x, y<, tD
1 6 AiryAiPrimeB 1 4 1 3 GammaB F + 6 323 AiryAiB 3 2
13

Out[10]= ::x FunctionB8t<,

-3 313 AiryAiPrimeB 3 2
13

3 2

13

1 3 tF GammaB F + 356 AiryBiPrimeB 3 2

13

1 tF GammaB F + 9 H-1L13 223 3 3 2


13

2 tF GammaB F + 3 H-1L13 223 3 3 2


13

3 AiryBiPrimeB -

2 tF GammaB F F, 3 3 2
13

y FunctionB8t<,

3 H-1L23 213 AiryAiB -

1 tF GammaB F - H-1L23 213 3

3 AiryBiB 13

tF

2 3 tF GammaB F + 6 316 AiryBiB 3 2

2 tF GammaB F F>> 3

In[11]:=

Plot@Evaluate@8x@tD, y@tD< . solD, 8t, - 1, 10<, WorkingPrecision 20D

Out[11]=

10

-2

-4

Differential Equation Solving with DSolve

101

The ParametricPlot function can be used to trace the solution curve 8 x@tD, y@tD< in the plane.
In[12]:=

ParametricPlot@Evaluate@8x@tD, y@tD< . solD, 8t, - 1, 7<, WorkingPrecision 20D

Out[12]=
-4 -2 -1 2 4

-2

-3

Here is the plot for the solution to a DAE.


In[13]:=

sol = DSolve@8x ''@tD + 3 * y@tD UnitStep@tD, x@tD - 5 * y@tD t ^ 2, x@0D 1, x '@0D 1<, 8x, y<, tD
1 96 3 5 1 480 3 5 -430 - 90 t + 81 t2 + 526 CosB 3 5 -430 - 90 t + 177 t2 + 526 CosB 3 5 3 5 3 5 tF +

Out[13]= ::x FunctionB8t<,

62

15 SinB

tF - 160 UnitStep@-tD + 160 CosB

tF UnitStep@-tD F,

y FunctionB8t<,

tF + 62

15 SinB

tF -

160 UnitStep@-tD + 160 CosB

tF UnitStep@-tD F>>

In[14]:=

Plot@Evaluate@8x@tD, y@tD, x@tD - 5 * y@tD< . solD, 8t, - 2, 2<D


4

Out[14]=
1

-2

-1

102

Differential Equation Solving with DSolve

Here is the general solution to a linear PDE.


In[15]:=

sol = DSolve@D@u@x, yD, xD + x ^ 2 * D@u@x, yD, yD Exp@xD, u, 8x, y<D


1 3 I-x3 + 3 yMFF>>

x Out[15]= ::u FunctionB8x, y<, + C@1DB

Here is a plot of the solution surface for a particular choice of the arbitrary function C @1D.
In[16]:=

Plot3D@Evaluate@u@x, yD . sol . 8C@1D@t_D Sin@3 * tD<@@1DDD, 8x, - 2, 2<, 8y, - 2, 2<, Mesh FalseD

Out[16]=

The GeneratedParameters Option


The general solution to a differential equation contains undetermined coefficients that are labeled C @1D, C @2D, and so on.
This example has one undetermined parameter, C @1D.
In[1]:=

DSolve@y @xD + y@xD 1, y@xD, xD

-x Out[1]= 99y@xD 1 + C@1D==

To change the name of the undetermined parameter, use the GeneratedParameters option.
This changes the name of the undetermined coefficient to P@1D.
In[2]:=

DSolve@y @xD + y@xD 1, y@xD, x, GeneratedParameters PD

-x Out[2]= 99y@xD 1 + P@1D==

The parameter C should be thought of as a pure function that acts on a set of indices to generate different constants C @iD.
This shows the behavior of C .

Differential Equation Solving with DSolve

103

This shows the behavior of C .


In[3]:= In[4]:= In[5]:=

parameter = C@D &; indexset = 81, 2, 3, 4<; parameter@indexset@@1DDD

Out[5]= C@1D

In[6]:=

parameter@indexset@@3DDD

Out[6]= C@3D

Internally, the use of a pure function allows DSolve to increment the argument i in C @iD correctly for higher-order ODEs and systems of ODEs. GeneratedParameters can be specified using a pure function.
In[7]:=

DSolve@y ''@xD + y@xD 1, y@xD, x, GeneratedParameters Hconst@D &LD

Out[7]= 88y@xD 1 + const@1D Cos@xD + const@2D Sin@xD<<

Using a pure function is particularly useful if you want to begin indexing the parameters at any value other than 1 (the default).
This uses a pure function to label the parameters in the previous example const@2D and const@3D.
In[8]:=

DSolve@y ''@xD + y@xD 1, y@xD, x, GeneratedParameters Hconst@1 + D &LD

Out[8]= 88y@xD 1 + const@2D Cos@xD + const@3D Sin@xD<<

It is sometimes useful to display the solution using subscripts or other styles for the parameter indices.
Here, the parameters are named using subscripted variables.
In[9]:=

DSolve@y ''@xD + y@xD 1, y@xD, x, GeneratedParameters Hc1 &LD

Out[9]= 88y@xD 1 + Cos@xD c1 + Sin@xD c2 <<

Finally, with Module variables, you can get names for the parameters that are unique across different invocations of DSolve.
Here the same DSolve call generates different parameter names.
In[10]:=

DSolve@y ''@xD + y@xD 1, y@xD, x, GeneratedParameters Module@8C<, C@D &DD

Out[10]= 88y@xD 1 + Cos@xD C$102@1D + C$102@2D Sin@xD<<

104

Differential Equation Solving with DSolve

In[11]:=

DSolve@y ''@xD + y@xD 1, y@xD, x, GeneratedParameters Module@8C<, C@D &DD

Out[11]= 88y@xD 1 + Cos@xD C$106@1D + C$106@2D Sin@xD<<

Symbolic Parameters and Inexact Quantities


The differential equations that arise in practice are of two types. Equations in which the only variables are the independent and dependent variables. Thus, all the variables that appear in the first argument to DSolve are also in the second or third arguments. Equations in which there are other symbolic quantities, such as mass or the spring constant. The solution in this case depends on the independent variables, the dependent variables, and the additional symbolic parameters.
Here is an example of the first type.
In[1]:=

DSolve@y ''@xD - 8 * x * y@xD 0, y, xD

Out[1]= 88y Function@8x<, AiryAi@2 xD C@1D + AiryBi@2 xD C@2DD<<

Here is an example of the second type. This equation has a symbolic parameter k.
In[2]:=

sol = DSolve@8y ''@xD + k ^ 2 * y@xD x ^ 2, y@0D 3 k + 1, y '@0D k<, y, xD


-2 + k2 x2 + 2 Cos@k xD + k4 Cos@k xD + 3 k5 Cos@k xD + k4 Sin@k xD k4 F>>

Out[2]= ::y FunctionB8x<,

DSolve is equipped to deal with both types of equations. It is extremely useful to have the solution available for all possible values of the parameters in the second type of equation.
Here is a plot of the previous solution for different values of the parameter k.
In[3]:=

Plot@Evaluate@Table@y@xD . sol . 8k i<, 8i, 1, 5, 2<DD, 8x, - 7, 7<D


50 40 30 20 10

Out[3]=

-6

-4

-2 -10

It should be noted that the presence of symbolic parameters can lead to fairly complicated output.

Differential Equation Solving with DSolve

105

It should be noted that the presence of symbolic parameters can lead to fairly complicated output.
This is seen in the following example (equation 2.14, page 401 of [K59]).
In[4]:= In[5]:=

eqn = y ''@xD - c * x ^ a * y@xD ; sol = DSolve@eqn 0, y, xD


1

Out[5]= ::y FunctionB8x<, H-1L


1 2+a 1 1+
a 2

2+a

H2 + aL

1 2+a

1+

a 2

2+a

c 1

2 I2+aM

x 2

1-

2+a

BesselIB
2+a 2

1 2+a

c x 2+a 1 +

F C@2D GammaB1 + a 2+a

1 2+a

F+

H2 + aL

c 2 I2+aM x 2+a BesselIB

c x 2+a

F C@1D GammaB

FF>>

-2 - a

2+a

However, for some special values of the parameters, the solution might be significantly simpler.
For these values of a and c, the solution is much more simple.
In[6]:=

sol1 = y@xD . sol@@1DD . 8a 0, c 4<


1 2 C@2D Sinh@2 xD

Out[6]= C@1D Cosh@2 xD +

Occasionally, a solution is valid for most, but not all, values of the parameters.
Since the input in this example is not valid at a = 0, the solution has the same limitation.
In[7]:=

sol = DSolve@8y '@xD x, y@0D 1 a<, y, xD


2 + a x2 2a F>>

Out[7]= ::y FunctionB8x<,

Of course, there is a simple remedy in this case: setting k = .


In[8]:=

1 a

sol = DSolve@8y '@xD x, y@0D k<, y, xD


1 2 I2 k + x2 MF>>

Out[8]= ::y FunctionB8x<,

In summary, the ability to solve differential equations with symbolic parameters is a powerful and essential feature of any symbolic solver such as DSolve. However, the following points should be noted. The solution might be complicated, and such calculations often require significant time and memory. The answer might not be valid for certain exceptional values of the parameters. The solution might be easy to verify symbolically for some special values of the parameters, but in the general case a numerical verification method is preferable.

106

Differential Equation Solving with DSolve

The solution might be easy to verify symbolically for some special values of the parameters, but in the general case a numerical verification method is preferable. Numerical quantities in Mathematica can be of three types: infinite precision, machine precision, or arbitrary precision. The first type of number is referred to as exact, while the remaining two types represent incomplete information and are therefore called inexact.
Here is a simple example showing all three kinds of numbers.
In[9]:= In[10]:=

exactpi = Pi; Precision@exactpiD

Out[10]=

In[11]:=

Hmachinepi = N@PiDL InputForm

Out[11]//InputForm= 3.141592653589793

In[12]:=

Precision@machinepiD

Out[12]= MachinePrecision

In[13]:=

highprecisionpi = N@Pi, 30D

Out[13]= 3.14159265358979323846264338328

In[14]:=

Precision@highprecisionpiD

Out[14]= 30.

Since DSolve is a symbolic solver, the algorithms used by it are primarily based on the assumption of exact input. However, equations that contain inexact quantities are handled by DSolve in the usual way.
These equations contain the inexact number 3. and 3.`40, respectively.
In[15]:=

DSolve@x '@tD 3. x@tD, x, tD

3. t C@1DE== Out[15]= 99x FunctionA8t<,

In[16]:=

DSolve@x '@tD 3.`40 * x@tD, x, tD

3.00000000000000000000000000000000000000 t C@1DE== Out[16]= 99x FunctionA8t<,

Inexact input could arise, for example, when the coefficients in the equations are derived from a previous calculation and are known only approximately. In such cases, it might not be practical to convert the equations to exact form, as this could slow down the calculation significantly.

Differential Equation Solving with DSolve

107

Here is a system of linear ODEs that all have exact coefficients. Note that even with a fairly small value of n, the calculation takes a long time to finish.
In[17]:=

n = 8; x0 @t_D := 0; xn @t_D := 1; eqns = Table@8xi '@tD - H xi+1 @tD - 2 xi @tD + xi-1 @tDL, xi @0D - H1 nL<, 8i, n - 1<D; vars = Table@xi , 8i, n - 1<D; sol = DSolve@Map@ 0 &, Flatten@eqnsDD, vars, tD; Timing

Out[17]= 835.703, Null<

In[18]:=

LeafCount@solD

Out[18]= 212 851

This verifies the solution. Since the solution is complicated, a numerical verification method is used.
In[19]:=

eqns . sol . 8t RandomReal@ 80, 1<, WorkingPrecision 200D< N Chop Flatten Union

Out[19]= 80<

If a single inexact quantity is introduced (in the function x0 @tD), the solution is returned more quickly.
In[20]:=

n = 8; x0 @t_D := 0.; xn @t_D := 1; eqns = Table@8xi '@tD - H xi+1 @tD - 2 xi @tD + xi-1 @tDL, xi @0D - H1 nL<, 8i, n - 1<D; vars = Table@xi , 8i, n - 1<D; sol = DSolve@Map@ 0 &, Flatten@eqnsDD, vars, tD; Timing

Out[20]= 80.75, Null<

In[21]:=

LeafCount@solD

Out[21]= 1563

In[22]:=

eqns . sol . 8t RandomReal@ 80, 1<D < N@D & Chop Flatten Union

Out[22]= 80<

Thus, it is often desirable to continue working with inexact quantities even within a symbolic function such as DSolve. However, it should be noted that the solution obtained in such cases could have a certain amount of numerical error and should be checked carefully. It is therefore recommended that if the problem size is not too large (for instance, if there are fewer than five equations), the input should be converted to exact form using the Rationalize function.
This equation contains inexact quantities.
In[23]:=

DSolve@8x '@tD 0.0001 * x@tD, x@0D 3.07<, x@tD, tD

0.0001 t == Out[23]= 99x@tD 3.07

Here the equation is converted to exact form before being solved.

108

Differential Equation Solving with DSolve

Here the equation is converted to exact form before being solved.


In[24]:=

DSolve@Rationalize@8x '@tD 0.0001 * x@tD, x@0D 3.07<, 0D, x@tD, tD


307 t10 000 100 >>

Out[24]= ::x@tD

Is the Problem Well-Posed?


DSolve returns a general solution for a problem if no initial or boundary conditions are specified.
The general solution to this equation is returned.
In[1]:=

DSolve@y '@xD 1 - y@xD, y, xD

-x Out[1]= 99y FunctionA8x<, 1 + C@1DE==

However, if initial or boundary conditions are specified, the output from DSolve must satisfy both the underlying differential equation as well as the given conditions.
Here is an example with a boundary condition.
In[2]:= In[3]:=

eqns = 8y '@xD 1 - y@xD, y@3D 5<; sol = DSolve@eqns, y, xD

-x 3 x Out[3]= 99y FunctionA8x<, I4 + ME==

In[4]:=

eqns . sol

Out[4]= 88True, True<<

In such cases, it is useful to check whether DSolve has been asked a reasonable question~in other words, to check whether the problem is well-posed. An initial or boundary value problem is said to be well-posed if a solution for it is guaranteed to exist in some well-known class of functions (for example, analytic functions), if the solution is unique, and if the solution depends continuously on the data. Given an ODE of order n (or a system of n first-order equations) and n initial conditions, there are standard existence and uniqueness theorems that show that the problem is well-posed under a specified set of conditions. The right-hand side of the first-order linear ODE in the previous example is a polynomial in y@xD and hence infinitely differentiable. This is sufficient to apply Picards existence and uniqueness theorem, which only requires that the right-hand side be Lipschitz-continuous. Most problems that arise in practice are well-posed since they are derived from sound theoretical principles. However, as a note of caution, the following are examples where DSolve might have difficulty finding a satisfactory solution to the problem.

Differential Equation Solving with DSolve

109

Most problems that arise in practice are well-posed since they are derived from sound theoretical principles. However, as a note of caution, the following are examples where DSolve might have difficulty finding a satisfactory solution to the problem.
Here is the solution to a first-order ODE in which the right-hand side fails to satisfy the Lipschitz condition around 0.
In[5]:=

generalsol = DSolve@8y '@xD 1 y@xD<, y, xD


2 x + C@1D F>, :y FunctionB8x<, 2 x + C@1D F>>

Out[5]= ::y FunctionB8x<, -

The general solution has two branches.


In[6]:=

Plot@Evaluate@y@xD . generalsol . 8C@1D 1<D, 8x, - 1, 3<D

2 1

Out[6]=

-1 -1 -2

This initial value problem is well-posed in a region around the initial condition and hence DSolve succeeds in picking out the correct branch for the given initial condition.
In[7]:=

DSolve@8y '@xD 1 y@xD, y@0D 1<, y, xD


DSolve::bvnul : For some branches of the general solution, the given boundary conditions lead to an empty solution.

Out[7]= ::y FunctionB8x<,

1 + 2 x F>>

Here is a second-order ODE. The boundary conditions do not allow any solution to this problem.
In[8]:=

DSolve@8y ''@xD + y@xD 0, y@0D 1, y@PiD 3<, y@xD, xD


DSolve::bvnul : For some branches of the general solution, the given boundary conditions lead to an empty solution.

Out[8]= 8<

In this example, DSolve returns a pair of solutions. As the table shows, the first solution is only valid for values of x greater than or equal to 2.
In[9]:=

eqn = y '@xD y@xD ^ H1 2L;

110

Differential Equation Solving with DSolve

In[10]:=

sol = DSolve@8eqn, y@0D 1<, y, xD


1 4 I4 - 4 x + x2 MF>, :y FunctionB8x<, 1 4 I4 + 4 x + x2 MF>>

Out[10]= ::y FunctionB8x<,

In[11]:=

Table@eqn . sol . 8x i<, 8i, 0, 5<D

Out[11]= 88False, True<, 8False, True<, 8True, True<, 8True, True<, 8True, True<, 8True, True<<

Finally, it is possible that a problem has a solution, but that DSolve fails to find it because the general solution is in implicit form or involves higher transcendental functions.
In this example, a solution is available only after inverting the roles of the dependent and independent variables.
In[12]:=

DSolve@y '@xD 1 Hx - y@xDL && y@0D 1, y, xD


InverseFunction::ifun : Inverse functions are being used. Values may be lost for multivalued inverses. Solve::ifun : Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information. DSolve::bvnul : For some branches of the general solution, the given boundary conditions lead to an empty solution.

Out[12]= 8<

In[13]:=

DSolve@x '@yD Hx@yD - yL && x@1D 0, x, yD


- 2 y + y F>>

Out[13]= ::x FunctionB8y<,

This concludes the discussion of the basic principles for effectively working with DSolve. See the list of "references" that were found to be useful either during the development of DSolve or during the preparation of this documentation.

Differential Equation Solving with DSolve

111

References
[AB04] Abell, M. L. and J. P. Braselton. Differential Equations with Mathematica, 3rd ed. Elsevier Academic Press, 2004. [A89] Abramov, S. A. "Rational Solutions of Linear Differential and Difference Equations with Polynomial Coefficients." USSR Comput. Maths. Math. Phys. 29 (1989): 7|12. [A96] Abramov, S. A. "Symbolic Search Algorithms for Partial d'Alembertian Solutions of Linear Equations." Programming and Computer Software 22, no. 1 (1996): 26. [AB01] Abramov, S. A. and M. Bronstein. "On Solutions of Linear Functional Systems." In Proc. ISSAC'01, 1|6, 2001. [AK91] Abramov, S. A. and K. Yu. Kvansenko. "Fast Algorithms to Search for the Rational Solutions of Linear Differential Equations with Polynomial Coefficients." In Proc. ISSAC'91, 267|270, 1991. [AP94] Abramov, S. A. and M. Petkovsek. "D'Alembertian Solutions of Linear Differential and Difference Equations." In Proc. ISSAC'94, 169|174, 1994. [ABP95] Abramov, S. A., M. Bronstein, and M. Petkovsek. "On Polynomial Solutions of Linear Operator Equations." In Proc. ISSAC'95, 290|296, 1995. [B93] Bocharov, A. "Symbolic Solvers for Nonlinear Differential Equations." The Mathematica Journal 3, no. 2 (1993): 63|69. [BD97] Boyce, W. F. and R. C. DiPrima, Elementary Differential Equations. John Wiley and Sons, 1997. [BM91] Boyer, C. B. and U. C. Merzbach, A History of Mathematics, 2nd ed. John Wiley, 1991. [B91] Bronstein, M. "The Risch Differential Equation on an Algebraic Curve." In Proc. ISSAC'91, 241|246, 1991. [B92] Bronstein, M. "On Solutions of Linear Ordinary Differential Equations in Their Coefficient Field." J. Symbolic Computation 13 (1992): 413|439. [B92a] Bronstein, M. "Integration and Differential Equations in Computer Algebra." Programming and Computer Software 18, no.5 (1992): 201|217. [B92b] Bronstein, M. "Linear Ordinary Differential Equations: Breaking Through the Order 2 Barrier." In Proc. ISSAC'92, 42|48, 1992.

112

Differential Equation Solving with DSolve

[B92b] Bronstein, M. "Linear Ordinary Differential Equations: Breaking through the Order 2 Barrier." In Proc. ISSAC'92, 42|48, 1992. [C80] Campbell, S. L. Singular Systems of Differential Equations I. Pitman, 1980. [C82] Campbell, S. L. Singular Systems of Differential Equations II. Pitman, 1982. [CC04] Chan, L. and E. S. Cheb-Terrab. "Non-Liouvillian Solutions for Second Order Linear ODEs." In Proc. ISSAC'04, 80|86, 2004. [CDM97] Cheb-Terrab, E. S., L. G. S. Duarte, and L. A. C. P. da Mota. "Computer Algebra Solving of First Order ODEs Using Symmetry Methods." Comp. Phys. Comm. 101 (1997): 254. [CR99] Cheb-Terrab, E. S. and A. D. Roche. "Integrating Factors for Second Order ODEs." J. Symbolic Computation 27 (1999): 501. [CR00] Cheb-Terrab, E. S. and A. D. Roche. "Abel ODEs: Equivalence and Integrable Classes." Comp. Phys. Comm. 130 (2000): 204. [D58] Drazin, M. P. "Pseudo Inverses in Associative Rays and Semigroups" American Mathematical Monthly 65 (1958): 506|514. [F59] Forsyth, A. R. Theory of Differential Equations. Dover, 1959. [I99] Ibragimov, N. H. Elementary Lie Group Analysis and Ordinary Differential Equations. John Wiley & Sons, 1999. [I44] Ince, E. L. Ordinary Differential Equations. Dover, 1944. [K59] Kamke, E. Differentialgleichungen: Losungsmethoden und Losungen. Akademische Verlagsgesellschaft, 1959. [K74] Kamke, E. Differentialgleichungen Losungsmethoden und Losungen, Bd. II: Partielle differentialgleichungen. Chelsea Publishing Co., 1974. [K00] Kevorkian, J. Partial Differential Equations: Analytical Solution Techniques. SpringerVerlag, 2000. [K72] Kline, M. Mathematical Thought from Ancient to Modern Times, Vol. 2. Oxford University Press, 1972. [K86] Kovacic, J. J. "An Algorithm for Solving Second Order Linear Homogeneous Differential Equations." J. Symbolic Computation 2 (1986): 3|43. [L01] Kovacic, J. J. "An Algorithm for Solving Second Order Linear Homogeneous Differential Equations." Lecture, City College of New York, 2001.

Differential Equation Solving with DSolve

113

[L01] Kovacic, J. J. "An Algorithm for Solving Second Order Linear Homogeneous Differential Equations." Lecture, City College of New York, 2001. [KPS03] Kythe, P. K., P. Puri, and M. R. Schferkotter, Partial Differential Equations and Boundary Value Problems with Mathematica, 2nd ed. Chapman and Hall/CRC, 2003. [L65] Lebedev, N. N. Special Functions and Their Applications. Prentice-Hall, 1965. [M00] Meyer, C. D. Matrix Analysis and Applied Linear Algebra. SIAM, 2000. [M60] Murphy, G. M. Ordinary Differential Equations and Their Solutions. Van Nostrand, 1960. [M47] McLachlan, N. W. Theory and Application of Mathieu Functions. Oxford University Press, 1947. [O95] Olver, P. J. Equivalence, Invariants and Symmetry. Cambridge University Press, 1995. [PZ95] Polynanin, A. D. and V. F. Zaitsev, Handbook of Exact Solutions for Ordinary Differential Equations. CRC Press, 1995. [S81] Saunders, B. D. "An Implementation of Kovacic's Algorithm for Solving Second Order Linear Homogeneous Differential Equations." In Proc. SYMSAC'81 (P. Wang, ed.), 105, 1981. [S85] Schlesinger, L. Handbuch der Theorie der Linearen Differentialgleichungen. Teubner, 1985. [SS98] Shirvani, M. and J. W.-H. So. "Solutions of Linear Differential Algebraic Equations." SIAM Review 40, no. 2 (1998): 344|346. [S57] Sneddon, I. Elements of Partial Differential Equations. McGraw-Hill, 1957. [T05] Trott, M. The Mathematica GuideBook for Symbolics. Springer-Verlag, 2005. [UW96] Ulmer, F. and J-A. Weil. "Note on Kovacic's Algorithm." J. Symbolic Computation 22 (1996): 179|200. [WW27] Whittaker, E. T. and G. N. Watson. A Course of Modern Analysis, 4th ed. Cambridge University Press, 1927. [W02] Wolfram, S. A New Kind of Science. Wolfram Media, Inc., 2002. [W04] Wolfram, S. The Mathematica Book, 5th ed. Wolfram Media, Inc., 2004. [Z89] Zwillinger, D. Handbook of Differential Equations. Academic Press, 1989

You might also like