({{, (RefLink[DSolve, paclet:ref/DSolve])[eqn,u,x]
solves a differential equation for the function u, with independent variable x. }, {, (RefLink[DSolve, paclet:ref/DSolve])[eqn,u,{x,(Subscript[x, min]),(Subscript[x, max])}]
solves a differential equation for x between (Subscript[x, min]) and (Subscript[x, max]).}, {, (RefLink[DSolve, paclet:ref/DSolve])[{(Subscript[eqn, 1]),(Subscript[eqn, 2]),…},{(Subscript[u, 1]),(Subscript[u, 2]),…},…]
solves a list of differential equations. }, {, (RefLink[DSolve, paclet:ref/DSolve])[eqn,u,{(Subscript[x, 1]),(Subscript[x, 2]),…}]
solves a partial differential equation. }, {, (RefLink[DSolve, paclet:ref/DSolve])[eqn,u,{(Subscript[x, 1]),(Subscript[x, 2]),…}∈Ω]
solves the partial differential equation eqn over the region Ω.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[DSolve, paclet:ref/DSolve]) can solve ordinary differential equations (ODEs), partial differential equations (PDEs), differential algebraic equations (DAEs), delay differential equations (DDEs), integral equations, integro-differential equations, and hybrid differential equations.

The output from (RefLink[DSolve, paclet:ref/DSolve]) is controlled by the form of the dependent function u or u[x]:

With a pure function output, eqn/.{{u->f},…} can be used to verify the solution.  »

(RefLink[DSolve, paclet:ref/DSolve]) can give implicit solutions in terms of (RefLink[Solve, paclet:ref/Solve]).  »

(RefLink[DSolve, paclet:ref/DSolve]) can give solutions that include (RefLink[Inactive, paclet:ref/Inactive]) sums and integrals that cannot be carried out explicitly. Variables K[1], K[2], … are used in such cases.

Different classes of equations solvable by (RefLink[DSolve, paclet:ref/DSolve]) include:

Boundary conditions for ODEs and DAEs can be specified by giving equations at specific points such as u[(Subscript[x, 1])]==a, u'[(Subscript[x, 2])]==b, etc.

Boundary conditions for PDEs can be given as equations u[x,(Subscript[y, 1])]==a, (RefLink[Derivative, paclet:ref/Derivative])[1,0][u][x,(Subscript[y, 1])]==b, etc. or as (RefLink[DirichletCondition, paclet:ref/DirichletCondition])[u[x,y]==g[x,y],cond].

Initial conditions for DDEs can be given as a history function g[x] in the form u[x/;x<(Subscript[x, 0])]==g[x].

(RefLink[WhenEvent, paclet:ref/WhenEvent])[event,action] may be included in the equations eqn to specify an action that occurs when event becomes (RefLink[True, paclet:ref/True]).

The region Ω can be anything for which (RefLink[RegionQ, paclet:ref/RegionQ])[Ω] is (RefLink[True, paclet:ref/True]).

(RefLink[N, paclet:ref/N])[DSolve[…]] calls (RefLink[NDSolve, paclet:ref/NDSolve]) or (RefLink[ParametricNDSolve, paclet:ref/ParametricNDSolve]) for differential equations that cannot be solved symbolically.

The following options can be given:

(RefLink[GeneratedParameters, paclet:ref/GeneratedParameters]) controls the form of generated parameters; for ODEs and DAEs these are by default constants (RefLink[C, paclet:ref/C])[n] and for PDEs they are arbitrary functions (RefLink[C, paclet:ref/C])[n][…].  »

OpenersPrimaryExamplesSection(Spacer1)Examples  (157)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Solve a differential equation:

DSolve[y'[x]+y[x]==a Sin[x],y[x],x]

Include a boundary condition:

DSolve[{y'[x]+y[x]==a Sin[x],y[0]==0},y[x],x]

Get a "pure function" solution for y:

DSolve[{y'[x]+y[x]==a Sin[x],y[0]==0},y,x]

Substitute the solution into an expression:

FullSimplify[y''[x]+y[x]^2/.%]

OpenersExampleSection1(Spacer1)Scope  (102)

OpenersExampleSubsection0(Spacer1)Basic Uses  (13)

Compute the general solution of a first-order differential equation:

DSolve[y'[x]==3y[x],y[x],x]

Obtain a particular solution by adding an initial condition:

DSolve[{y'[x]==3y[x],y[0]==5},y[x],x]

Plot the general solution of a differential equation:

sol=DSolve[{y'[x]==-y[x]},y[x],x]

Plot the solution curves for two different values of the arbitrary constant (RefLink[C, paclet:ref/C])[1]:

Plot[{y[x]/.sol/.(C[1])->2,y[x]/.sol/.(C[1])-> 3},{x,1,4}]

Plot the solution of a boundary value problem:

sol=DSolve[{y'[x]==-3y[x]^2,y[1]==2},y[x],x]

Plot[y[x]/.sol,{x,1,4}]

Verify the solution of a first-order differential equation by using y in the second argument:

eqns={y'[x]==y[x]+a Cos[x],y[0]==3};

sol=DSolve[eqns,y,x]

eqns/.sol//Simplify

Obtain the general solution of a higher-order differential equation:

DSolve[{y''[x]+4 y[x]==7},y[x],x]

Particular solution:

DSolve[{y''[x]+4 y[x]==7,y[0]==1,y'[0]==2},y[x],x]

Solve a system of differential equations:

eqns={y'[x]==y[x]-a z[x],z'[x]==y[x]-z[x],y[0]==1,z[0]==4};

sol=DSolve[eqns,{y,z},x]

Plot the solution:

ParametricPlot[Evaluate[Table[{y[x],z[x]}/.sol,{a,3,8}]],{x,0,10}]

Verify the solution:

eqns/.sol//Simplify

Solve a system of differential-algebraic equations:

sol=DSolve[{y'[x]-3z[x]==Sin[x], y[x]+z[x]==1/5, y[Pi/2]==1/2},{y,z},x]

Plot[Evaluate[{y[x],z[x],y[x]+z[x]}/.sol], {x,2,16},PlotLegends->{y[x],z[x],y[x]+z[x]}]

Solve a partial differential equation:

eqn=D[u[x,y],x]+3D[u[x,y],y]+u[x,y]==1;

sol=DSolve[eqn, u, {x,y}]

Obtain a particular solution:

sol/.(C[1])->Sin

Plot the solution:

Plot3D[u[x,y]/.%,{x,-3,3},{y,-3,3},PlotRange->All]

Use different names for the arbitrary constants in the general solution:

DSolve[y''[x]-4y[x]==0,y[x],x]

DSolve[y''[x]-4y[x]==0,y[x],x,GeneratedParameters->f]

Solve a delay differential equation:

sol=DSolve[{x'[t]==x[t-1]^2, x[t/;t≤0]==a t},x[t],{t,0,2}]

Plot the solution for different values of the parameter:

Plot[Evaluate[Table[x[t]/.sol,{a,1,5}]],{t,-1,2}]

Solve a hybrid differential equation:

sol=DSolve[{y''[t]==-981/100,y[0]==5,y'[0]==0,WhenEvent[y[t]==0,y'[t]->-(7/10)y'[t]]},y[t],{t,0,4}]

This system models a bouncing ball:

Plot[y[t]/.sol,{t,0,4}]

Apply (RefLink[N, paclet:ref/N])[DSolve[...]] to invoke (RefLink[NDSolve, paclet:ref/NDSolve]) if symbolic solution fails:

DSolve[{y''[x]+x^2 y'[x]+Sin[y[x]]==1,y[0]==1,y'[0]==1},y,{x,0,1}]

N[%]

Table[y[x]/.%[[1]],{x,0,1,0.2}]

Find the general solution of an ODE with quantities:

DSolve[(QuantityVariable["x", "Length"])''[(QuantityVariable["t", "Time"])]==(QuantityUnit[5]),(QuantityVariable["x", "Length"])[(QuantityVariable["t", "Time"])],(QuantityVariable["t", "Time"])]

Solve an initial-value problem:

DSolve[{(QuantityVariable["x", "Length"])''[(QuantityVariable["t", "Time"])]==(QuantityUnit[5]),(QuantityVariable["x", "Length"])[(QuantityUnit[0])]==(QuantityUnit[3]),(QuantityVariable["x", "Length"])'[(QuantityUnit[0])]==(QuantityUnit[7])},(QuantityVariable["x", "Length"])[(QuantityVariable["t", "Time"])],(QuantityVariable["t", "Time"])]

OpenersExampleSubsection1(Spacer1)Linear Differential Equations  (4)

Exponential equation:

DSolve[{y'[x]==ay[x],y[0]==1},y[x],x]

Inhomogeneous first-order equation:

DSolve[y'[x]+x y[x]==Cos[x],y[x],x]

Solve a boundary value problem:

DSolve[{y''[x]-x y[x]==0,y[0]==1,y[9]==1},y,x]

Plot the solution:

Plot[y[x]/.%,{x,-10,10}]

Second-order equation with constant coefficients:

DSolve[y''[x]+4y'[x]+5y[x]==0,y[x],x]

Cauchy–Euler equation:

DSolve[x^2y''[x] +4x y'[x]+7y[x]==0,y[x],x]

Second-order equation with variable coefficients, solved in terms of elementary functions:

DSolve[x y''[x]+2 y'[x]-x y[x]==Sin[x],y,x]

Airy's equation:

DSolve[y''[x]-x y[x] ==0,y,x]

Spheroidal equation:

DSolve[(1 - x^2)y''[x]-2x y'[x]+ 
    (49-49x^2-16/(1-x^2)+SpheroidalEigenvalue[5,4,7])y[x] == 
   0,y,x]

Equations with nonrational coefficients:

DSolve[y''[x]+(8+3Cos[x]^2)y[x]==0,y,x]

DSolve[y''[x]+(9+Sech[x]^2)y[x]==0,y,x]

DSolve[y''[x]== Exp[-x] y[x],y,x]

Higher-order equations:

DSolve[y'''[x]+4y'[x]==5y[x],y,x]

Solution in terms of hypergeometric functions:

DSolve[3x^3y''''[x]+19x^2 y'''[x]+(2x-3x^2)y''[x]+(2-9x)y'[x]-3y[x]==0,y,x]

Fourth-order equation solved in terms of Kelvin functions:

DSolve[(525+x^4)y[x]-51(-x y'[x]+x^2 y''[x])+ 2x^3y'''[x]+x^4 y''''[x]==0,y,x]

OpenersExampleSubsection2(Spacer1)Nonlinear Differential Equations  (6)

Solve a Riccati equation:

DSolve[y'[x]+x y'[x]^2==1,y,x]

Implicit solution for an Abel equation:

DSolve[y'[x]==y[x]^3-((x+1)y[x]^2)/x,y[x],x]//Quiet

Homogeneous equation:

DSolve[y'[x]-Sqrt[(y[x]/x)]==y[x]/x,y,x]

Solution in terms of (RefLink[WeierstrassP, paclet:ref/WeierstrassP]):

DSolve[y''[x]==y[x]^2+1,y,x]

Solution in terms of hyperbolic functions:

DSolve[y''[x] ==3y[x] y'[x]+(3y[x]^2+4y[x]+1),y[x],x][[1]]//Simplify

Solve a nonlinear boundary value problem:

DSolve[{y''[x]==y[x]^3,y[0]==5,y'[0]==25/Sqrt[2]},y[x],x]

OpenersExampleSubsection3(Spacer1)Systems of Differential Equations  (4)

Diagonal linear system:

DSolve[{y'[x]==x^2y[x],z'[x]==5z[x]}, {y,z},x]

Inhomogeneous linear system with constant coefficients:

With[{θ=Pi/3},DSolve[{y'[x]==Cos[θ]y[x]-Sin[θ]z[x]+1,z'[x]==Sin[θ]y[x]+Cos[θ]z[x],y[0]==1,z[0]==1},{y, z},x]]

Plot[Evaluate[{y[x],z[x]}/.First[%]],{x,0,9}]

Nonlinear system:

DSolve[ {y'[x]==Exp[z[x]]+1,z'[x]==y[x]-x},{y,z},x]//Quiet

Solve a system of ODEs given in vector format:

A={{4,-6},{1,-1}};

X[t_]={x[t],y[t]};

sol=DSolve[X'[t]==A.X[t],X[t],t]

OpenersExampleSubsection4(Spacer1)Differential-Algebraic Equations  (3)

Solve a system of linear differential-algebraic equations:

DSolve[{2 y'[x]+z'[x]==4y[x]+x,y[x]-z[x]==1},{y[x],z[x]},x]

Solve a boundary value problem:

DSolve[{y'[x]-4z[x]==Cos[x], y[x]+z[x]==1/2, y[Pi/2]==1/2},{y,z},x]

Plot[Evaluate[{y[x],z[x],y[x]+z[x]}/.%], {x,2,16}]

An index-2 differential-algebraic equation:

DSolve[{x'[t]==x[t]+2y[t],y[t]==x[t]+2^t,x[t]+z[t]==0},{x[t],y[t],z[t]},t]

OpenersExampleSubsection5(Spacer1)Delay Differential Equations  (2)

Solve a delay differential equation:

sol=DSolve[{x'[t]==x[t-1]^2,x[t/;t≤0]==a t},x[t],{t,0,2}]

Plot the solution for different values of the parameter a:

Plot[Evaluate[Table[x[t]/.sol[[1]],{a,1,5}]],{t,-1,2}]

Solve a system of delay differential equations:

eqns={x'[t]==a y[t-1]+y[t-3],y'[t]==x[t-1], x[t/;t≤0]==t, y[t/;t≤0]==t^2};

sol=DSolve[eqns,{x[t],y[t]},{t,0,5}]

Plot the solution for different values of the parameter a:

ParametricPlot[Evaluate[Table[{x[t],y[t]}/.sol,{a,-1,2,1/3}]],{t,-2,5},Exclusions->None]

OpenersExampleSubsection6(Spacer1)Piecewise Differential Equations  (4)

Using a piecewise forcing function:

DSolve[{y''[x]-y[x]==Max[x,x^2],y[0]==1,y'[0]==2},y[x],x]//Simplify

A differential equation with a piecewise coefficient:

DSolve[y'[x]+Clip[x]^2y[x]==0,y[x],x]

A nonlinear piecewise-defined differential equation:

sol = DSolve[{y'[x]==Piecewise[{{Cos[x]^2,x >2}}, y[x]^2/3],y[0] == 1},y,x]

Plot[y[x]/.sol, {x,0,7}]

Differential equations involving generalized functions:

DSolve[y''[x]-y[x]==HeavisideTheta[x],y[x],x]

A simple impulse response or Green's function:

DSolve[y'[x]+7y[x]==DiracDelta[x],y[x],x]

Solve a piecewise differential equation on the interval {0,1}:

DSolve[y'[x]==UnitStep[x],y,{x,0,1}]

Solutions on other intervals:

DSolve[y'[x]==UnitStep[x],y,{x,-1,0}]

DSolve[y'[x]==UnitStep[x],y,{x,-1,1}]

OpenersExampleSubsection7(Spacer1)Hybrid Differential Equations  (8)

Solve a first-order differential equation with a time-dependent event:

sol=DSolve[{x'[t]==x[t],x[0]==1,WhenEvent[Mod[t,1]==0,x[t]->x[t]+10]},x,{t,0,3}]

Plot the solution:

Plot[x[t]/.sol[[1]],{t,0,4},Exclusions->None]

Solve a second-order differential equation with a time-dependent event:

sol=DSolve[{x''[t]==x[t]+t,x[0]==1,x'[0]==3,WhenEvent[Mod[2t,1]==0,{x[t]->x[t]+t,x'[t]->-x'[t]}]},x[t],{t,0,4}]

Plot the solution:

Plot[x[t]/.sol[[1]],{t,0,4},Exclusions->None]

Solve a system of differential equations with a state-dependent event:

eqns={y'[t]==z[t],z'[t]==-10, y[0]==1, z[0]==0};
events={WhenEvent[y[t]==0,{y[t]->0,z[t]->-(70/100)z[t]}]};
sol=DSolve[Join[eqns,events],{y[t],z[t]}, {t,0,2}]

Plot the solution for y:

Plot[y[t]/.sol[[1]], {t,0,2}]

Stop the integration when an event occurs:

DSolve[{x'[t]==x[t],x[0]==1,WhenEvent[t==2,"StopIntegration"]},x,{t,0,3}]

Remove an event after it has occurred once:

sol=DSolve[{x''[t]+x[t]==0,x[0]==0,x'[0]==1,WhenEvent[x[t]==0,{x'[t]->-x'[t],"RemoveEvent"}]},x,{t,0,10}]

Plot[x[t]/.sol,{t,0,10}]

Specify that a variable maintains its value between events:

sol=DSolve[{x'[t] ==a[t],x[0]==0, a[0]==1,WhenEvent[Mod[x[t],1]==0,a[t]->- a[t]]},{x,a},{t,0,4},DiscreteVariables->a]

Plot[x[t]/.sol,{t,0,4}]

Prescribe a different action at each event:

sol=DSolve[{x'[t]==y[t],y'[t]==1,x[0]==0,y[0]==0,WhenEvent[t==1,x[t]->x[t]+1],WhenEvent[t==2,y[t]->y[t]+2]},{x,y},{t,0,3}]

ParametricPlot[{x[t],y[t]}/.sol,{t,0,3}]

Several events with the same action:

sol=DSolve[{x'[t]==1,x[0]==0,WhenEvent[{t==1,t==2},x[t]->x[t]+1]},x,{t,0,3}]

Plot[x[t]/.sol,{t,0,3}]

OpenersExampleSubsection8(Spacer1)Sturm-Liouville Problems  (6)

Solve an eigenvalue problem with Dirichlet conditions:

sol=DSolve[{y''[x]+λ y[x]==0,y[0]==0,y[π]==0},y[x],x]

Make a table of the first 5 eigenfunctions:

eigfuns=Table[y[x]/.sol[[1]]//.{\[FormalN]->i,λ->(\[FormalN]^2)}/.{(C[1])-> 1},{i,5}]

Plot the eigenfunctions:

Plot[Evaluate[eigfuns],{x,0,Pi}]

Solve an eigenvalue problem with Neumann conditions:

sol=DSolve[{y''[x]+λ y[x]==0,y'[0]==0,y'[π]==0},y[x],x]

Make a table of the first 5 eigenfunctions:

eigfuns=Table[y[x]/.sol[[1]]//.{\[FormalN]->i,λ->(\[FormalN]^2)}/.{(C[1])-> 1},{i,0,4}]

Plot the eigenfunctions:

Plot[Evaluate[eigfuns],{x,0,Pi}]

Solve an eigenvalue problem with mixed boundary conditions:

sol=DSolve[{y''[x]+λ y[x]==0,y[0]==0,y'[π]==0},y[x],x]

Make a table of the first 5 eigenfunctions:

eigfuns=Table[y[x]/.sol[[1]]//.{\[FormalN]->i,λ->(((-(1/2)+\[FormalN]))^2)}/.{(C[1])-> 1},{i,5}]

Plot the eigenfunctions:

Plot[Evaluate[eigfuns],{x,0,Pi}]

Solve an eigenvalue problem with a Robin condition at the left end of the interval:

sol=DSolve[{y''[x]+λ y[x]==0,y[0]+y'[0]==0,y[1]==0},y[x],x]

Locate the roots of the transcendental eigenvalue equation in the range 10<λ<80:

roots=λ/.Solve[(Sqrt[λ]) Cos[(Sqrt[λ])]==Sin[(Sqrt[λ])]&&10<λ<80,λ];data=Table[{λ,0},{λ,roots}];

Plot[(Sqrt[λ]) Cos[(Sqrt[λ])]-Sin[(Sqrt[λ])],{λ,10,80},Epilog->{PointSize[Large],Red,Point[data]}]

Obtain the eigenfunctions within this range by using (RefLink[Assumptions, paclet:ref/Assumptions]):

DSolve[{y''[x]+λ y[x]==0,y[0]+y'[0]==0,y[1]==0},y[x],x,Assumptions->1<λ<80]

Solve an eigenvalue problem with Robin boundary conditions at both ends:

DSolve[{y''[x]+2λ y'[x]+λ^2 y[x]==0,y[1]+y'[1]==0,3y[2]+2y'[2]==0},y[x],x]

Solve an eigenvalue problem for the Airy operator:

eqns={-y''[x]+x y[x]==λ y[x],y[0]==0,y[1]==0};

sol=y[x]/.DSolve[eqns,y[x],x,Assumptions->1<λ<300][[1]];

Eigenvalues for the problem:

eigvals={ToRules[sol[[1,1,2]]]}

Eigenfunctions for this problem are given by the following:

eigfuns=(sol[[1,1,1]]/.{(C[1])-> 1})

Plot the eigenfunctions for the range 1<λ<300:

Plot[Evaluate[eigfuns/.eigvals],{x,0,1}]

OpenersExampleSubsection9(Spacer1)Integral Equations  (6)

Solve a Volterra integral equation:

eqn=y[x]==(x^3)+λ(∫_0^x)(t- x)y[t]\[DifferentialD]t;

sol=DSolve[eqn,y[x],x]

Plot the solution:

Plot[Table[y[x]/.sol[[1]],{λ,1,3,0.5}]//Evaluate,{x,0,20}]

Solve a Fredholm integral equation:

eqn=y[x]==Sin[7 x]-(x/a)+(∫_0^(π/2))x y[t]\[DifferentialD]t;

sol=DSolve[eqn,y[x],x]

Plot the solution:

Plot[Table[y[x]/.sol[[1]],{a,-1,4,0.7}]//Evaluate,{x,0,Pi/2}]

Solve an integro-differential equation:

eqn=y'[x]==1+Sin[a x]+(∫_0^x)y[t]\[DifferentialD]t;

Obtain the general solution:

sol1=DSolve[eqn,y[x],x]

Specify an initial condition to obtain a particular solution:

init=y[0]==-1;

sol2=DSolve[{eqn,init},y[x],x]

Plot the solution:

Plot[Table[y[x]/.sol2[[1]],{a,-1,4,0.7}]//Evaluate,{x,0,3}]

Solve a singular Abel integral equation:

eqn=Sin[a x]==(∫_0^x)((y[t])/(Sqrt[x-t]))\[DifferentialD]t;

sol=DSolve[eqn,y[x],x]

Plot the solution:

Plot[Table[y[x]/.sol[[1]],{a,1,3,0.7}]//Evaluate,{x,0,9}]

Solve a weakly singular Volterra integral equation:

eqn=y[x]==(x^a)-(∫_0^x)((y[t])/(Sqrt[x-t]))\[DifferentialD]t;

sol=DSolve[eqn,y[x],x]

Plot the solution:

Plot[Table[y[x]/.sol[[1]],{a,1,4,0.7}]//Evaluate,{x,0,2}]

Solve a homogeneous Fredholm equation of the second kind:

eqn=y[x]==λ (∫_0^π)Cos[x+t]y[t]\[DifferentialD]t;

sol=DSolve[eqn,y[x],x]

Plot the solution:

Plot[Table[y[x]/.sol[[1]]/.{ (C[1])-> 1, (C[2])->1},{λ,{-2/Pi,2/Pi}}]//Evaluate,{x,0,3π}]

OpenersExampleSubsection10(Spacer1)First-Order Partial Differential Equations  (7)

General solution for a linear first-order partial differential equation:

DSolve[3D[u[x,y],x]+5D[u[x,y],y]==x ,u,{x,y}]

The solution with a particular choice of the arbitrary function (RefLink[C, paclet:ref/C])[1]:

(u[x,y]/.%[[1]])/.{(C[1])[e_]:>Sin[e]+Cos[e]}

Plot3D[%,{x,-5,5},{y,-5,5}]

Initial value problem for a linear first-order partial differential equation:

DSolve[{x D[u[x,y],y]+y D[u[x,y],x] == 
    -4x y u[x,y], u[x,0] == E^(-x^2)}, u,{x,y}]

Plot3D[u[x,y]/.%[[1]], {x,-2,2}, {y,-2, 2},ColorFunction->"TemperatureMap"]

Initial-boundary value problem for a linear first-order partial differential equation:

DSolve[{D[u[t,x],t]+D[u[t,x],x]==0,u[t,0]==0,u[0,x]==Sin[x]},u,{t,x}]

Plot3D[u[t,x]/.%[[1]]//Evaluate,{t,0,3},{x,0,3},Exclusions->None]

General solution for the transport equation:

DSolve[D[u[t,x],t]+c D[u[t,x],x]==0,u,{t,x}]

Initial value problem:

DSolve[{D[u[t,x],t]+c D[u[t,x],x]==0,u[0,x]==E^(-x^2)},u,{t,x}]

Plot the traveling wave with speed c==1:

Plot[u[t,x]/.%[[1]]/.{c-> 1,t-> 3}//Evaluate,{x,0,10},PlotRange->All,Ticks->False,Filling-> Axis,Epilog->Arrow[{{4,4/5},{7,4/5}}]]

General solution for a quasilinear first-order partial differential equation:

DSolve[2D[u[x,y],x]+5D[u[x,y],y]==u[x,y]^2+1,u,{x,y}]//Quiet

Initial value problem for a scalar conservation law:

DSolve[{D[u[x,y],x]+u[x,y] D[u[x,y],y] == 0, 
   u[x,0] == 1/(x+1)},u,{x,y}]

Plot3D[u[x,y]/.%[[1]],{x,0,3},{y,0,2}]

Complete integral for a nonlinear first-order Clairaut equation:

DSolve[u[x,y]==x  D[u[x,y],x]+y D[u[x,y],y]+Sin[D[u[x,y],x]+D[u[x,y],y]] ,u,{x,y}]//Quiet

OpenersExampleSubsection11(Spacer1)Hyperbolic Partial Differential Equations  (11)

Initial value problem for the wave equation:

weqn=D[u[x,t],{t,2}]==D[u[x,t],{x,2}];

ic={u[x,0]== E^(-x^2), Derivative[0,1][u][x,0]==1};

DSolve[{weqn,ic},u,{x,t}]

The wave propagates along a pair of characteristic directions:

Plot3D[Evaluate[u[x,t]/.%[[1]]],{x,-7,7},{t,0,4},PlotRange->All]

Initial value problem for the wave equation with piecewise initial data:

weqn=D[u[x,t],{t,2}]==D[u[x,t],{x,2}];

ic={u[x,0]==UnitBox[x]+UnitTriangle[x/3], Derivative[0,1][u][x,0]==0};

DSolve[ {weqn,ic},u[x,t],{x,t}]//Simplify//TraditionalForm

Discontinuities in the initial data are propagated along the characteristic directions:

Plot3D[Evaluate[u[x,t]/.%[[1]]],{x,-7,7},{t,0,4},PlotRange->All,PlotPoints->250]

Initial value problem with a pair of decaying exponential functions as initial data:

weqn=D[u[x,t],{t,2}]==D[u[x,t],{x,2}];

ic={u[x,0]==E^(-(x-6)^2)+E^(-(x+6)^2), 
    Derivative[0, 1][u][x,0] == 1/2};

sol=DSolve[ {weqn,ic},u[x,t],{x,t}]

Visualize the solution:

Plot3D[Evaluate[u[x,t]/.sol[[1]]],{x,-30,30},{t,0,20},PlotRange->All,Exclusions->All,PlotPoints->30]

Initial value problem for an inhomogeneous wave equation:

weqn={D[u[x, t],{t,2}]==D[u[x,t], {x,2}]+m};

ic= {u[x, 0] == Sin[x]-Cos[3*x]/E^(Abs[x]/6), 
    Derivative[0, 1][u][x,0] == 0};

sol = DSolve[{weqn,ic}, u[x,t], {x, t}]

Visualize the solution for different values of m:

Table[Plot3D[Evaluate[u[x,t]/.sol[[1]]],{x,-7,7},{t,0,4},PlotRange->All,Ticks->False],{m,{-1,0,1}}]

Initial value problem for the wave equation with a Dirichlet condition on the half-line:

weqn=D[u[x,t],{t,2}]==D[u[x,t],{x,2}];

ic={u[x, 0]==Piecewise[{{Sin[x]^2,Pi<x<2Pi}}], Derivative[0,1][u][x,0]==0};

bc=u[0,t]==0;

sol=DSolve[{weqn,ic,bc},u,{x,t}];

Visualize the solution:

Plot3D[Evaluate[u[x,t]/.sol[[1]]],{x,0,12},{t,0,10},Exclusions->None,PlotRange->All,PlotPoints->120]

The wave bifurcates starting from the initial data:

Grid[Partition[Table[Plot[Evaluate[u[x,t]/.sol[[1]]],{x,0,20}, 
Exclusions->None,PlotRange->All],{t,0,12}],3],ItemSize-> 10]

Initial value problem for the wave equation with a Neumann condition on the half-line:

weqn=D[u[x,t],{t,2}]==D[u[x,t],{x,2}];

ic={u[x,0]==Sin[x]^3,Derivative[0,1][u][x,0]==1-E^(-x/10)};

bc=Derivative[1,0][u][0,t]==1;

sol=DSolve[{weqn,ic ,bc },u,{x,t}];

Visualize the solution:

Plot3D[Evaluate[u[x,t]/.sol[[1]]],{x,0,20},{t,0,2},Exclusions->None,PlotRange->All]

In this example, the wave evolves to a non-oscillating function:

Grid[Partition[Table[Plot[Evaluate[u[x,t]/.sol[[1]]],{x,0,20}, 
Exclusions->None],{t,0,12}],3],ItemSize-> 8]

Dirichlet problem for the wave equation on a finite interval:

weqn=D[u[x,t],{t,2}]== D[u[x, t], {x, 2}];

ic={u[x,0]==x^2(Pi-x),Derivative[0,1][u][x, 0]==0};

bc={u[0,t]==0,u[Pi,t]==0};

The solution is an infinite trigonometric series:

sol=DSolve[{weqn,ic,bc}, u[x,t], {x, t}]

Extract the first three terms from the (RefLink[Inactive, paclet:ref/Inactive]) sum:

asol=u[x,t]/.sol[[1]]/.{∞->3}//Activate

Plot3D[asol,{x,0,Pi},{t,0,4Pi},ColorFunction->Hue]

The wave executes periodic motion in the vertical direction:

Plot[Evaluate[Table[asol,{t,0,7}]],{x,0,Pi}]

Dirichlet problem for the wave equation in a rectangle:

weqn=D[u[x,y,t],{t,2}]==Laplacian[u[x,y,t],{x,y}];

ic={u[x,y,0]==(1/10)(x-x^2)(2y-y^2),Derivative[0,0,1][u][x,y,0]==0};

bc={u[x,0,t]==0,
 u[0,y,t]==0,u[1,y,t]==0,u[x,2,t]==0};

The solution is a doubly infinite trigonometric series:

(sol=FullSimplify[u[x,y,t]/.DSolve[{weqn,ic, bc},u,{x,y,t}][[1]],K[1]∈Integers && K[2]∈Integers])//TraditionalForm

Extract a few terms from the (RefLink[Inactive, paclet:ref/Inactive]) sum:

h[x_,y_,t_]=sol/.{∞->3}//Activate

The two-dimensional wave executes periodic motion in the vertical direction:

Animate[Plot3D[h[x,y,t],{x,0,1},{y,0,2},Ticks->False,PlotRange->{-1/36,1/36},MeshStyle->Red,PerformanceGoal->"Quality"],{t,0,8},SaveDefinitions->True,DefaultDuration->12]

Dirichlet problem for the wave equation in a circular disk:

reqn=r D[u[r,t],{t,2}]==D[r D[u[r,t],r],r];

ic={u[r,0]==1,Derivative[0,1][u][r,0]==r/3};

bc=u[1,t]==0;

The solution is an infinite Bessel series:

(sol=u[r,t]/.DSolve[{reqn,ic,bc},u[r,t], {r,t}][[1]]//FullSimplify)//TraditionalForm

Extract the first three terms from the (RefLink[Inactive, paclet:ref/Inactive]) sum:

h[r_, t_]=sol/.{Infinity->3}//Activate//N;

Plot3D[h[r,0.7]/.{r->Sqrt[x^2+y^2]},{x,y}∈Disk[],PlotRange->All,Ticks->None]

General solution for a second-order hyperbolic partial differential equation:

DSolve[12 D[u[x,t],{x,2}]==D[u[x,t],{t,2}]+D[u[x,t],x,t], u,{x,t}]

Hyperbolic partial differential equation with non-rational coefficients:

DSolve[D[u[x,y],{x,2}]-2Sin[x] D[u[x,y],x,y]-Cos[x]^2 D[u[x,y],{y,2}]-Cos[x]D[u[x,y],y]==0, u, {x,y} ]

Inhomogeneous hyperbolic partial differential equation with constant coefficients:

DSolve[3D[u[x,t],{x,2}]-D[u[x,t],{t,2}]+D[u[x,t],x,t]==1,u,{x,t}]

Initial value problem for an inhomogeneous linear hyperbolic system with constant coefficients:

eqns={D[u[x,t],t]==D[v[x,t],x]+1,D[v[x,t],t]==-D[u[x,t],x]-1};

ic={u[x,0]==Cos[x]^2,v[x,0]==Sin[x]};

sol=DSolve[{eqns,ic},{u[x,t],v[x,t]},{x,t}]//FullSimplify

Plot3D[({u[x,t],v[x,t]}/.sol[[1]])//Evaluate,{x,0,4},{t,0,3},PlotRange->{-70,120}]

OpenersExampleSubsection12(Spacer1)Parabolic Partial Differential Equations  (10)

Initial value problem for the heat equation:

heqn=D[u[x,t],t]==D[u[x,t],{x,2}];

ic=u[x, 0] == E^(-x^2);

sol=DSolve[{heqn,ic },u[x,t],{x,t}]

Plot3D[Evaluate[u[x,t]/.sol[[1]]],{x,-5,5},{t,0,4},PlotRange->All]

Visualize the diffusion of heat with the passage of time:

Plot[Evaluate[Table[u[x, t] /. sol[[1]], {t, 0, 4}]], {x,-5,5},PlotRange->All,Filling->Axis]

Initial value problem for the heat equation with piecewise initial data:

heqn=D[u[x,t],t]==D[u[x,t],{x,2}];

ic=u[x, 0] == UnitBox[x];

The solution is given in terms of the error function (RefLink[Erf, paclet:ref/Erf]):

sol=DSolve[{heqn,ic },u[x,t],{x,t}]

Discontinuities in the initial data are smoothed instantly:

Plot3D[Evaluate[u[x,t]/.sol[[1]]],{x,-2,2},{t,0,1},PlotRange->All,PlotPoints->250]

Initial value problem for an inhomogeneous heat equation:

heqn=D[u[x,t],t]==D[u[x,t],{x,2}]+m;

ic=u[x, 0] == Sin[x];

sol=DSolve[{heqn,ic },u[x,t],{x,t}]

Visualize the growth of the solution for different values of the parameter m:

Table[Plot3D[Evaluate[u[x,t]/.sol[[1]]]/.{m->i},{x,-7,7},{t,0,4},PlotRange->All,Axes->False],{i,{2,0,-2}}]

Initial value problem for the heat equation with a Dirichlet condition on the half-line:

heqn=D[u[x,t],t]==D[u[x,t],{x,2}];

ic=u[x, 0] == Cos[x];

bc=u[0,t]==1;

sol=DSolve[{heqn,ic,bc },u[x,t],{x,t}]//FullSimplify

Visualize the solution:

Plot3D[Evaluate[u[x,t]/.sol[[1]]],{x,0,15},{t,0,10},Exclusions->None,PlotRange->All]

Initial value problem for the heat equation with a Neumann condition on the half-line:

heqn=D[u[x,t],t]==D[u[x,t],{x,2}];

ic=u[x, 0] == UnitTriangle[x-3];

bc=Derivative[1,0][u][0, t] ==0;

sol=DSolve[{heqn,ic,bc },u,{x,t}];

Visualize the solution:

Plot3D[Evaluate[u[x,t]/.sol[[1]]],{x,0,7},{t,0,2},Exclusions->None,PlotRange->All]

Dirichlet problem for the heat equation on a finite interval:

heqn=D[u[x,t],t]==D[u[x,t],{x,2}];

ic=u[x, 0] ==x(3-x)^2;

bc={u[0,t]==0,u[3,t]==0};

The solution is a Fourier sine series:

sol=DSolve[{heqn,ic,bc },u[x,t],{x,t}]

Extract three terms from the (RefLink[Inactive, paclet:ref/Inactive]) sum:

asol=u[x,t]/.sol[[1]]/.{∞->3}//Activate

Plot3D[asol//Evaluate,{x,0,3},{t,0,3/2},Exclusions->None,PlotRange->All]

Neumann problem for the heat equation on a finite interval:

heqn=D[u[x,t],t]==D[u[x,t],{x,2}];

ic=u[x, 0] ==x(3-x);

bc={Derivative[1,0][u][0,t]==0,Derivative[1,0][u][3,t]==0};

The solution is a Fourier cosine series:

sol=u[x,t]/.DSolve[{heqn,ic,bc },u[x,t],{x,t}][[1]]

Extract a few terms from the (RefLink[Inactive, paclet:ref/Inactive]) sum:

asol=sol/.{∞->4}//Activate

Plot3D[asol//Evaluate,{x,0,3},{t,0,1},Exclusions->None,PlotRange->All]

The solution approaches (3/2) as t->∞:

asol/.t->∞

Visualize the evolution of the solution to its steady state:

Plot[Evaluate[Table[asol, {t, 0, 1,0.2}]], {x,0,3},PlotRange->All,Filling->Axis]

Dirichlet problem for the heat equation in a disk:

rheqn=r D[u[r,t],t]==D[r D[u[r,t],r],r];

ic=u[r,0]==1-r;

bc=u[1,t]==0;

The solution is an infinite Bessel series:

(sol=u[r,t]/.DSolve[{rheqn,ic,bc},u[r,t], {r,t}][[1]])//TraditionalForm

Extract a few terms from the (RefLink[Inactive, paclet:ref/Inactive]) sum:

h[r_,t_]=sol/.{∞->3}//Activate//N;

Visualize the individual terms of the solution at time t=0.1:

Table[Plot3D[h[r,0.1][[i]]  /.{r->Sqrt[x^2+y^2]}//Evaluate,{x,y}∈Disk[],Ticks->None],{i,3}]

Initial value problem for a linear parabolic equation:

DSolve[{D[u[x,t],t]==12 D[u[x,t],{x,2}]+Sin[t]  D[u[x,t],x],u[x,0]==x},u,{x,t}]

Plot3D[u[x,t]/.%[[1]],{x,0,2},{t,0,20}]

Boundary value problem for the Black–Scholes equation:

BlackScholesPDE=D[v[t,s],t]+ 1/2σ^2 s^2 D[v[t,s],{s,2}]+(r-q) s D[v[t,s],s] -r v[t,s]==0;

bc=v[T,s]==ψ[s];

DSolve[{BlackScholesPDE,bc},v[t,s],{t,s}]

OpenersExampleSubsection13(Spacer1)Elliptic Partial Differential Equations  (9)

Dirichlet problem for the Laplace equation in the upper half-plane:

leqn=Laplacian[u[x,y],{x,y}]==0;

bc=u[x,0]==UnitBox[x];

sol=DSolve[{leqn,bc},u[x,y], {x,y}]

Discontinuities in the boundary data are smoothed out:

Plot3D[u[x,y]/.sol[[1]],{x,-3,3},{y,0,5},PlotRange->All]

Dirichlet problem for the Laplace equation in the right half-plane:

leqn=Laplacian[u[x,y],{x,y}]==0;

bc=u[0,y]==Sinc[y];

sol=DSolve[{leqn,bc},u[x,y], {x,y}]

Visualize the solution:

Plot3D[u[x,y]/.sol[[1]],{y,-10,10},{x,0,5},PlotRange->All]

Dirichlet problem for the Laplace equation in the first quadrant:

leqn=Laplacian[u[x,y],{x,y}]==0;

bc={u[x,0]==(-1/((x-2)^2+3)),u[0,y]==(1/((y-3)^2+1))};

sol=DSolve[{leqn,bc},u[x,y], {x,y}];

Visualize the solution:

Plot3D[u[x,y]/.sol[[1]],{x,0,10},{y,0,7},PlotRange->All]

Neumann problem for the Laplace equation in the upper half-plane:

leqn=Laplacian[u[x,y],{x,y}]==0;

bc=Derivative[0,1][u][x,0]==UnitBox[x];

sol=DSolve[{leqn,bc},u[x,y], {x,y}]

Visualize the solution:

Plot3D[u[x,y]/.sol[[1]],{x,-3,3},{y,0,5},PlotRange->All]

Dirichlet problem for the Laplace equation in a rectangle:

leqn=Laplacian[u[x,y],{x,y}]==0;

bc={u[x,0]==x^2(1-x),u[x,2]==0,u[0,y]==0,u[1,y]==0};

The solution is an infinite trigonometric series:

sol=FullSimplify[u[x,y]/.DSolve[{leqn,bc},u[x,y], {x,y}][[1]]]

Extract a few terms from the (RefLink[Inactive, paclet:ref/Inactive]) sum:

asol=sol/.∞->4//Activate

Visualize the solution:

Plot3D[asol,{x,0,1},{y,0,2},PlotRange->All]

Dirichlet problem for the Laplace equation in a disk:

leqn=Laplacian[u[r,θ],{r,θ},"Polar"]==0;

bc=u[3,θ]==Sin[6θ];

sol=DSolve[{leqn,bc},u[r,θ],{r,θ}]

Visualize the solution:

Plot3D[Evaluate[u[r,θ]/.sol[[1]]/.{r->Sqrt[x^2+y^2], θ->ArcTan[y/x]}],{x,y}∈Disk[{0,0},3],PlotRange->All,Exclusions->None]

Dirichlet problem for the Laplace equation in an annulus:

leqn=D[u[r,θ],{r,2}]+(1/r) D[u[r,θ],r]+(1/r^2) D[u[r,θ],{θ,2}]==0;

bc={u[1,θ]==0,u[2,θ]==5};

sol=DSolve[{leqn,bc},u[r,θ],{r,θ}]

Visualize the solution:

Plot3D[Evaluate[u[r,θ]/.sol[[1]]/.{r->Sqrt[x^2+y^2], θ->ArcTan[y/x]}],{x,y}∈Annulus[{0,0},{1,2}],PlotRange->All,Exclusions->None]

Dirichlet problem for the Poisson equation in a rectangle:

peqn=Laplacian[u[x,y],{x,y}]==6x-6y;

bc={u[x,0]==1+11x+x^3,u[x,2]==-7+11x+x^3,u[0,y]==1-y^3,u[4,y]==109-y^3};

sol = DSolve[{peqn,bc}, u[x,y], {x, y}]

Dirichlet problem for the Helmholtz equation in a rectangle:

heqn={Laplacian[u[x,y],{x,y}]+5 u[x,y]==0};

bc={u[x,0]==UnitTriangle[x-2],u[x,2]==0,u[0,y]==0,u[4,y]==0};

(sol=u[x,y]/.DSolve[{heqn,bc},u[x,y],{x,y}][[1]])//TraditionalForm

Extract a finite number of terms from the (RefLink[Inactive, paclet:ref/Inactive]) sum:

fsol=sol/.∞->30//Activate;

Visualize the approximate solution:

Plot3D[fsol//Evaluate,{x,0,4},{y,0,2},PlotRange->All]

OpenersExampleSubsection14(Spacer1)General Partial Differential Equations  (6)

A potential-free Schrödinger equation with Dirichlet boundary conditions:

eqn=I ℏ D[ψ[x,t],t] == ((-(ℏ^2))/(2m)) D[ψ[x,t],{x,2}];
DSolve[{eqn,ψ[a,t]==0,ψ[b,t]==0},ψ[x,t],{x,t}]

Extract the first four terms in the solution:

u[x_,t_]=ψ[x,t] /. Activate[First[%] /. ∞->4]

For any choice of the four constants (RefLink[C, paclet:ref/C])[k], ψ obeys the equation and boundary conditions:

Simplify[{eqn,ψ[a,t]==0,ψ[b,t]==0} /.ψ->u]

Initial value problem for a Schrödinger equation with Dirichlet boundary conditions:

eqn = I  D[ψ[x,t],t] == -2 D[ψ[x,t],{x,2}];
f[x_] := -350+155 x-22 (x^2)+(x^3)
sol=DSolve[{eqn,ψ[5,t]==0,ψ[10,t]==0,ψ[x,2]==f[x]},ψ,{x,t}]

Define a family of partial sums of the solution:

u[k_Integer]=ψ /. Activate[First[sol] /. ∞->k]

For each k, (Subscript[u, k]) satisfies the differential equation:

Table[eqn /. ψ->u[k],{k,4}]//Simplify

The boundary conditions are also satisfied:

Table[{u[k][5,t]==0,u[k][10,t]==0},{k,4}]

The initial condition is only satisfied for (Subscript[u, ∞]), but there is rapid convergence at t==2:

Grid@Partition[Table[Plot[{u[k][x,2],f[x]},{x,5,10},ImageSize->200],{k,4}],2]

Solve a Schrödinger equation with potential over the reals:

eqn=I  D[ψ[x,t],t] == - D[ψ[x,t],{x,2}] + 2 (x^2)ψ[x,t];

sol=DSolve[{eqn,ψ[-∞,t]==0,ψ[∞,t]==0},ψ[x,t],{x,t}]

Extract the first two terms in the solution:

u[x_,t_] = ψ[x,t] /.Activate[First[sol /. ∞->1]]

For any values of the constants (RefLink[C, paclet:ref/C])[0] and (RefLink[C, paclet:ref/C])[1], the equation is satisfied:

Simplify[eqn /. ψ->u]

The conditions at infinity are also satisfied:

Limit[u[x,t],x->∞]

Limit[u[x,t],x->-∞]

Although the function is time dependent, its (L^2)-norm is constant:

Integrate[((Abs[u[x,t]])^2), {x, -∞, ∞}, Assumptions->t∈Reals]

Initial value problem for Burgers' equation with viscosity ν:

BurgersEqn= D[u[x, t],t]+ u[x, t]D[u[x,t],x] ==ν D[u[x,t],{x,2}];

sol=DSolve[{BurgersEqn,u[x,0]==UnitBox[x]}, u[x,t],{x,t}];(dsol=u[x,t]/.sol[[1]]//FullSimplify)//TraditionalForm

Plot the solution at different times for ν=1/40:

Plot[Table[dsol/.{ν-> 1/40},{t,1/100,7}]//Evaluate,{x,-2,3.3},PlotRange->All,Filling->Axis,WorkingPrecision->20]

Plot the solution for different values of ν:

Table[Plot3D[dsol//Evaluate,{x,-2,2},{t,0,5},PlotRange->All,Ticks->False],{ν,{2/3,1/6,1/14}}]

Boundary value problem for the Tricomi equation:

TricomiEqn=D[u[x,y],{x,2}]+y D[u[x,y],{y,2}]==0;

DSolve[{TricomiEqn,u[x,0]==0, Derivative[0,1][u][x,0]==x^2},u[x,y],{x,y}]

Visualize the solution:

Plot3D[u[x,y]/.%[[1]]//Evaluate, {x,-3,3},{y,0,5}]

Traveling wave solution for the Korteweg–de Vries (KdV) equation:

KdV = {D[u[x,t],t]+D[u[x,t],{x, 3}]+ 6u[x,t]D[u[x,t],x]==0};

sol = DSolve[KdV,u[x,t],{x,t}]//Quiet

Obtain a particular solution for a fixed choice of arbitrary constants:

psol=u[x,t]/.sol[[1]]/.{(C[1])->1,(C[2])->-4,(C[3])->1/4}//Simplify

The wave travels to the right without changing its shape:

Plot[Evaluate[Table[psol,{t,1,12,3}]], {x,-7,35},PlotRange->All,Filling->Axis,Epilog->{Arrow[{{5,1.6},{9,1.6}}],Arrow[{{17,1.6},{21,1.6}}],Arrow[{{29,1.6},{33,1.6}}]}]

OpenersExampleSubsection15(Spacer1)Partial Differential Equations over Regions  (3)

Dirichlet problem for the Laplace equation in a rectangle:

leqn=(Laplacian[u[x,y], {x,y}])==0;

dcond=DirichletCondition[u[x,y]==Piecewise[{{UnitTriangle[2 x-1],y==0||y==2}},0],True];

Ω=Rectangle[{0,0},{1,2}];

(sol=FullSimplify[DSolve[{leqn,dcond},u[x,y],{x,y}∈Ω]])//TraditionalForm

Extract the first 100 terms from the (RefLink[Inactive, paclet:ref/Inactive]) sum:

asol=u[x,y]/.sol[[1]]/.{∞->100}//Activate;

Visualize the solution on the rectangle:

Plot3D[asol//Evaluate,{x,y}∈Ω,PlotRange->All,PlotStyle->Hue[0.2]]

Dirichlet problem for the Laplace equation in a disk:

leqn=(Laplacian[u[x,y], {x,y}])==0;

dcond = DirichletCondition[u[x, y]==Sin[6ArcTan[y/x]], True];

Ω=Disk[{0,0},3];

sol=DSolve[{leqn,dcond},u[x,y],{x,y}∈Ω]

Visualize the solution in the disk:

Plot3D[u[x,y]/.sol[[1]]//Evaluate,{x,y}∈Ω,PlotRange->All,PlotStyle->Hue[0.5]]

Dirichlet problem for the Laplace equation in a right half-plane:

leqn=(Laplacian[u[x,y], {x,y}])==0;

dcond = DirichletCondition[u[x,y]==1/(1+x^2),True];

Ω=HalfPlane[{{0,0},{1,0}},{0,1}];

sol=DSolve[{leqn,dcond},u[x,y],{x,y}∈Ω]

Visualize the solution in the half-plane:

Plot3D[u[x,y]/.sol[[1]]//Evaluate,{x,y}∈Ω,PlotRange->All,PlotStyle->Green]

OpenersExampleSection2(Spacer1)Generalizations & Extensions  (1)

No boundary condition; gives two generated parameters:

DSolve[y''[x]+4y[x]==0,y,x]

One boundary condition:

DSolve[{y''[x]+4y[x]==0,y[0]==1},y,x]

Two boundary conditions:

DSolve[{y''[x]+4y[x]==0,y[0]==1,y'[0]==4},y,x]

OpenersExampleSection3(Spacer1)Options  (6)

OpenersExampleSubsection16(Spacer1)Assumptions  (2)

Solve an eigenvalue problem for a linear second-order differential equation:

DSolve[{y''[x]+λy[x]==0,y[0]==0,y[π]==0},y[x],x]

Use (RefLink[Assumptions, paclet:ref/Assumptions]) to specify a range for the parameter λ:

DSolve[{y''[x]+λy[x]==0,y[0]==0,y[π]==0},y[x],x,Assumptions->0<λ<20]

Specify that the independent variable x is real:

eqn={y'[x]==Abs[x+Abs[x]] y[x],y[0]==1};

sol=DSolve[eqn,y,x,Assumptions->x∈Reals]

Obtain the same result using an interval specification for x:

DSolve[eqn,y,{x,-∞,∞}]

OpenersExampleSubsection17(Spacer1)DiscreteVariables  (1)

Specify that a variable maintains its value between events:

sol=DSolve[{x'[t] ==a[t],x[0]==0, a[0]==2,WhenEvent[Mod[x[t],1]==0,a[t]->- a[t]]},{x,a},{t,0,2},DiscreteVariables->a]

Plot[x[t]/.sol,{t,0,2}]

OpenersExampleSubsection18(Spacer1)GeneratedParameters  (2)

Use differently named constants:

DSolve[y''[x]==y[x],y[x],x, GeneratedParameters->d]

Use subscripted constants:

DSolve[y''[x]==y[x],y[x],x,GeneratedParameters->(Subscript[c,#]&)]

Generate uniquely named constants of integration:

DSolve[y''[x]==y[x],y[x],x, GeneratedParameters->Unique[C]]

The constants of integration are unique across different invocations of (RefLink[DSolve, paclet:ref/DSolve]):

DSolve[y''[x]==y[x],y[x],x, GeneratedParameters->Unique[C]]

OpenersExampleSubsection19(Spacer1)Method  (1)

Solve a linear ordinary differential equation:

DSolve[{y''[x]+y[x]==0,y[0]==0,y'[0]==1},y[x],x]

Obtain a solution in terms of (RefLink[DifferentialRoot, paclet:ref/DifferentialRoot]):

DSolve[{y''[x]+y[x]==0,y[0]==0,y'[0]==1},y[x],x,Method->"Holonomic"]

OpenersExampleSection4(Spacer1)Applications  (31)

OpenersExampleSubsection20(Spacer1)Ordinary Differential Equations  (7)

Solve a logistic (Riccati) equation:

DSolve[{y'[x] == y[x](1-y[x]/27),y[0]==a},y,x]//Quiet

Plot the solution for different initial values:

Plot[Evaluate[y[x]/.%/.{{a->1/13},{a->1/2},{a-> 4}}],{x,0,18}]

Solve a linear pendulum equation:

DSolve[{y''[x]+y[x]==0,y[0]==1,y'[0]==1/3},y ,x]

Plot[y[x]/.%, {x,0,17}]

Displacement of a linear, damped pendulum:

DSolve[{y''[x]+3y'[x]+40 y[x]==0,y[0]==1,y'[0]==1/3},y,x]

Plot[y[x]/.%, {x, 0,4}, PlotRange -> All]

Solve a nonlinear pendulum equation:

DSolve[{y''[x]+Sin[y[x]]==0,y[0]==0,y'[0]==1},y ,x]

Plot[y[x]/.%, {x, 0,20}, PlotRange -> All]

Study the phase portrait of a dynamical system:

DSolve[{x'[t]==-2y[t]+3x[t],y'[t]==15x[t]-y[t],x[0]==a,y[0]==b},{x,y}, t];

ParametricPlot[Evaluate[Table[{x[t], y[t]}/.%/.{a->1/(13+m), b->1/(15+m)}, {m,0,20,7}]], {t,-2,2}]

Find a power series solution when the exact solution is known:

DSolve[{y'[x]+Exp[x]y[x]==1,y[0]==3},y ,x]

Series[y[x]/.%[[1]],{x,0,7}]

Verify that y=0 and y=1 are equilibrium solutions of the logistic equation:

logisticeqn=y'[x]==r y[x](1-y[x]);

DSolve[{logisticeqn,y[0]==0},y[x],x]

DSolve[{logisticeqn,y[0]==1},y[x],x]

OpenersExampleSubsection21(Spacer1)Hybrid Differential Equations  (8)

Model a damped oscillator that gets a kick at regular time intervals:

system={x''[t]+.1x'[t]+x[t]==0,x[0]==1,x'[0]==0};
control=WhenEvent[Mod[t,1]==0,x'[t]->x'[t]+1];

sol=DSolve[{system,control},x,{t,0,50}];

Plot[Evaluate[{x[t],x'[t]}/.sol],{t,0,50}]

Rectify a sine wave:

sol=DSolve[{x''[t]+x[t]==0,x[0]==0,x'[0]==1,WhenEvent[x[t]==0,x'[t]->-x'[t]]},x,{t,0,4π}]

Plot[{Sin[t],(x[t]/.sol)},{t,0,4π}]

Model a ball bouncing down steps:

c=.75;
sol=DSolve[{y''[t]==-9.8,y[0]==13.5,y'[0]==5,a[0]==13,WhenEvent[y[t]-a[t]==0,y'[t]->-c y'[t]],WhenEvent[Mod[t,1],a[t]->a[t]-1]},{y,a},{t,0,8},DiscreteVariables->{a}] ;

Plot[Evaluate[{y[t],a[t]}/.sol],{t,0,8},Filling->{2->0},Exclusions->None]

In a square box, model a ball that changes direction upon impact with the side walls:

sol=DSolve[{x'[t]==a[t],y'[t]==b[t],x[0]==0,y[0]==0,a[0]==1,b[0]==17/12,WhenEvent[x[t]^2==1,a[t]->-a[t]],WhenEvent[y[t]^2==1,b[t]->-b[t]]},{x,y},{t,0,50}, DiscreteVariables->{a,b}];

ParametricPlot[{x[t],y[t]}/.sol,{t,0,50},Frame->True,FrameTicks->None,PlotRange->1,Axes->False]

Simulate the system y'==y+u stabilized with a discrete-time controller u(k τ)==-2 y(k τ):

system={y'[t]==y[t]+u[t],y[0]==1,u[0]==0};
control=WhenEvent[Mod[t,1]==0,u[t]->-2y[t]];

Simulate and visualize:

DSolve[{system,control},{y,u},{t,0,20},DiscreteVariables->u];

Plot[Evaluate[{u[t],y[t]}/.%], {t, 0, 10}, PlotRange->{-6,6},Exclusions->None]

Control a double integrator using a dead-beat, discrete-time controller:

system={x''[t]==u[t],x[0]==1,x'[0]==1,u[0]==-7};

Use a dead-beat digital feedback controller u(k τ)==-1/(τ^2)x(k τ)-3/(2 τ) x'(k τ):

τ=0.5;
control=WhenEvent[Mod[t,τ]==0,u[t]-> -(1/τ^2)x[t]-(3/(2τ))x'[t]];

Simulate and visualize:

DSolve[{system,control},{x,u},{t,0,2},DiscreteVariables->u];

Plot[Evaluate[{x[t],x'[t],u[t]}/.%], {t,0,2}, PlotRange->All,Exclusions->None]

Model the position of a moving body with 1 kg mass:

system={x''[t]==u[t],x'[0]==x[0]==0,u[0]==1};

Use a sampled proportional-derivative (PD) controller to keep the position constant:

kp=1; td=1;τ=1; xref=1;
control=WhenEvent[Mod[t,τ]==0,u[t]->kp(xref-x[t]-td x'[t])];

Simulate and visualize:

DSolve[{system,control},{x,u},{t, 0,12}, DiscreteVariables->u];

Plot[Evaluate[{xref,x[t],u[t]}/.%],{t,0,12},Exclusions->None]

Set the physical variable a to 0 whenever it becomes negative:

sol = DSolve[{a'[t]==-1/11u[t], a[0]==1, u[0]==1, 
     WhenEvent[a[t]<0, u[t]->0]},{a,u},{t,0,15}, DiscreteVariables->{u}]

Plot[Evaluate[a[t]/.sol],{t,0,15}, PlotRange -> All]

OpenersExampleSubsection22(Spacer1)Delay Differential Equations  (2)

Study the onset of chaos in a dynamical system governed by a delay differential equation:

sol=DSolve[{x'[t]==Sign[x[t-2]]-x[t-2], x[t/;t <= 0]==0.1},x, 
    {t,0,30}];

ParametricPlot[Evaluate[{x[t-2],x[t]}/.sol], {t,2,30}]

Study the stability of the solutions for a linear delay differential equation:

f[λ_,μ_]:=x[t]/.DSolve[{x'[t]==λ x[t] +μ x[t-1],x[t/;t≤0]==1-t},x[t],{t,0,10}][[1]]

Plot[Evaluate[{f[1/2,-1],f[-7/2,4],f[-5,4]}],{t,0,15},Exclusions-> None]

OpenersExampleSubsection23(Spacer1)Integral Equations  (4)

The tautochrone problem requires finding the curve down which a bead placed anywhere will fall to the bottom in the same amount of time. Expressing the total fall time in terms of the arc length of the curve and the speed v yields the Abel integral equation T==∫dt==∫1/vds. Defining the unknown function h by the relationship ds==h(y) dy and using the conservation of energy equation (v^2)/2==g ((Subscript[y, max])-y) yields the explicit equation:

abeleqn=T ==(∫_0^y)((h[z])/((Sqrt[2g])(Sqrt[y-z])))\[DifferentialD]z;

Use (RefLink[DSolve, paclet:ref/DSolve]) to solve the integral equation:

DSolve[abeleqn,h[y],y]

Using the relationship ds==(Sqrt[d(x^2)+d(y^2)]), solve for x'(y):

dxdy = (Sqrt[((h[y])^2)-1]) /. First[%]

Starting the curve from the origin and integrating—with assumptions that ensure the integrand is real-valued—yields x as a function of y:

x[y_]=Integrate[dxdy,{y,0,y},Assumptions->((2 g (T^2) )/((π^2)y))>1 &&y>0]

Substituting values for g and T, use (RefLink[ParametricPlot, paclet:ref/ParametricPlot]) to display the maximal tautochrone curve:

Show[ParametricPlot[{{x[y],y},{-x[y],y}} /. {g->9.8,T->2}, {y,0,((2(9.8)(2^2))/(π^2))}],ImageSize->Medium]

Making the change of variables y==((g (T^2) (1-cos(θ)))/(π^2)) gives a simple, nonsingular parametrization of the curve with -π<θ<π:

c[θ_] = ((g (T^2))/(π^2)){Sin[θ]+θ,1-Cos[θ]} ;

Combining the conservation of energy equation and the chain rule ((ds)/(dt))==((ds)/(dθ))((dθ)/(dt)) produces the following differential equation for θ as a function of t:

FullSimplify[ (((Sqrt[2g (Last[c[θMax]] - Last[c[θ]])]) )/(Sqrt[c'[θ].c'[θ]])) ,g>0 && T>0]

teqn = θ'[t]==(% /. {θ->θ[t], T->2});

This equation can be solved numerically for different starting points:

Θ[t_]=Table[NDSolveValue[{teqn,θ[0]==θMax},θ[t],{t,0,4}],{θMax,{-2 Pi/3,-Pi/2,-Pi/4,-Pi/12}}];

Plotting the solutions shows that all reach the bottom, θ==0, at the two-second mark:

Plot[Evaluate[Θ[t]],{t,0,4},PlotTheme->"Scientific"]

Visualize the motion along the tautochrone:

{cShape[t_],cBeads[t_]}={c[t], c /@Θ[t]}/. {T->2,g->9.8};
Animate@@{ParametricPlot[cShape[s] ,{s,-Pi,Pi},ImageSize->Medium,Epilog->{AbsolutePointSize[8],Point[cBeads[t]]}],{t,0,4,Appearance->"Labeled"},SaveDefinitions->True,AnimationDirection->ForwardBackward}

A spring-mass system, with an attached mass of (QuantityTF[3, "g", grams, "Grams"]), has a spring constant of (QuantityTF[3, "dynes""/""cm", dynes per centimeter, (("Dynes")/("Centimeters"))]) and a damping coefficient of (QuantityTF[2, "g""/""s", grams per second, (("Grams")/("Seconds"))]). At time t==0, the mass is pushed down and then released with a velocity 28 cm/s downward. A force of (QuantityTF[50 cos(2 t), "dynes", dynes, "Dynes"]) acts downward on the mass for t≥0. Find the velocity of the system as a function of time. The integral equation for the velocity is given by the following:

ieqn=3v'[t]+2 v[t]+40 (∫_0^t)v[m]\[DifferentialD]m==50 Cos[2 t];

Initial value of the velocity:

ic=v[0]==28;

Solve the integro-differential equation using (RefLink[DSolve, paclet:ref/DSolve]):

sol=DSolve[{ieqn,ic},v[t],t]

Plot the velocity as a function of time:

Plot[v[t]/.sol[[1]],{t,0,8},PlotRange->All, Filling->Axis]

Visualize the motion of the physical spring-mass system:

An LRC circuit has a voltage source given by v(t)==(QuantityTF[2 cos(t), "V", volts, "Volts"]). The resistance in the circuit is 0.2 Ω, the inductance is (QuantityTF[5, "H", henries, "Henries"]), and the capacitance is (QuantityTF[0.7`, "F", farads, "Farads"]). Initially, the current in the resistor is (QuantityTF[1, "A", amperes, "Amperes"]). Find the current as a function of time.

The integral equation for the current is given by:

ieqn=5 i'[t]+0.2 i[t]+(1/0.7)(∫_0^t)i[m]\[DifferentialD]m==2 Cos[t];

Initial value of the current:

ic=i[0]==1;

Solve the integro-differential equation using (RefLink[DSolve, paclet:ref/DSolve]):

sol=DSolve[{ieqn,ic},i[t],t]//FullSimplify//Chop

Plot the current as a function of time:

Plot[i[t]/.sol[[1]],{t,0,80},PlotRange->All, Filling->Axis]

A linear Volterra integral equation is equivalent to an initial value problem for a linear differential equation. Verify this relationship for the following Volterra equation:

eqn=y[x]==(x^3)+λ(∫_0^x)(t- x)y[t]\[DifferentialD]t;

Solve the integral equation using (RefLink[DSolve, paclet:ref/DSolve]):

sol=DSolve[eqn,y[x],x]

Set up the corresponding differential equation:

deqn=D[eqn,{x,2}]

Add two initial conditions since the differential equation is of second order:

init={(eqn/.{x-> 0}),(D[eqn,x]/.{x-> 0})}

The solution of the initial value problem agrees with that of the integral equation:

DSolve[{deqn,init},y[x],x]//Simplify

Plot the solution:

Plot[Table[y[x]/.%[[1]],{λ,1,3,0.5}]//Evaluate,{x,0,20},Filling->Axis]

OpenersExampleSubsection24(Spacer1)Classical Partial Differential Equations  (5)

Model the vibrations of a string with fixed length, say π, using the wave equation:

eqn = D[u[x, t], {t, 2}] == D[u[x, t], {x, 2}];

Specify that the ends of the string remain fixed during the vibrations:

bc={u[0,t]==0,u[π,t]==0};

Obtain the fundamental and higher harmonic modes of oscillation:

ic={u[x, 0] == Sin[m x], Derivative[0, 1][u][x, 0] == 0};

dsol=DSolve[{eqn,bc,ic},u,{x,t},Assumptions->Element[m,Integers]]

Visualize the vibrations of the string for these modes:

sol1[x_,t_]=u[x,t]/.dsol[[1]]

Table[Show[Plot[Table[sol1[x,t],{t,0,4}]//Evaluate,{x,0,Pi},Ticks->False]],{m,4}]

In general, the solution is composed of an infinite number of harmonics:

ic={u[x, 0] == x(π-x)^2, Derivative[0, 1][u][x, 0] == 0};

dsol=DSolve[{eqn,bc,ic},u,{x,t}]/.{K[1]-> m}

Extract four terms from the (RefLink[Inactive, paclet:ref/Inactive]) sum:

sol[x_,t_]=u[x,t]/.dsol[[1]]/.{∞->4}//Activate

Visualize the vibration of the string:

Animate[Plot[sol[x,t],{x,0,π},PerformanceGoal->"Quality",PlotRange->{-5,5},ImageSize->Medium],{t,0,12},SaveDefinitions->True]

Model the oscillations of a circular membrane of radius 1 using the wave equation in 2D:

eqn=r D[u[r,t],{t,2}]==D[r D[u[r,t],r],r];

Specify that the boundary of the membrane remain fixed:

bc=u[1,t]==0;

Initial condition for the problem:

ic={u[r,0]==0,Derivative[0,1][u][r,0]==1};

Obtain a solution in terms of Bessel functions:

(dsol=DSolve[{eqn,bc,ic},u[r,t],{r,t}])//TraditionalForm

Extract a finite number of terms from the (RefLink[Inactive, paclet:ref/Inactive]) sum:

h[r_, t_]=u[r,t]/.dsol[[1]]/.{∞->3}//Activate//N;

Visualize the oscillations of the membrane:

Animate[Plot3D[h[r,t]/.{r->Sqrt[x^2+y^2]},{x,y}∈Disk[],PlotRange->{-1,1},Ticks->None,Mesh->True,MeshStyle->{Red, Blue},PlotStyle->Yellow],{t,0,4},SaveDefinitions->True]

Model the flow of heat in a bar of length 1 using the heat equation:

heqn=D[u[x,t],t]==D[u[x,t],{x,2}];

Specify the fixed temperature at both ends of the bar:

bc={u[0,t]==20,u[1,t]==50};

Specify an initial condition:

ic=u[x,0]==0;

Solve the heat equation subject to these conditions:

sol=DSolve[{heqn,bc,ic},u[x,t],{x,t}]

Extract a few terms from the (RefLink[Inactive, paclet:ref/Inactive]) sum:

approxsol=u[x,t]/.sol[[1]]/.{Infinity->3}//Activate//Expand

Visualize the evolution of the temperature to a steady state:

Plot[Table[approxsol,{t,0.02,0.5,0.07}]//Evaluate,{x,0,1},AxesOrigin->{0,0}]

Obtain the steady-state solution v[x], which is independent of time:

ssol=DSolve[{v''[x]==0,v[0]==20,v[1]==50},v[x],x]//Expand

The steady-state solution is a linear function of x:

Plot[v[x]/.ssol[[1]],{x,0,1}]

Model the flow of heat in a bar of length 1 that is insulated at both ends:

heqn=D[u[x,t],t]==D[u[x,t],{x,2}];

Specify that no heat flow through the ends of the bar:

bc={Derivative[1,0][u][0,t]==0,Derivative[1,0][u][1,t]==0};

Specify an initial condition:

ic=u[x,0]==20+80x;

Solve the heat equation subject to these conditions:

sol=DSolve[{heqn,bc,ic},u[x,t],{x,t}]

Extract a few terms from the (RefLink[Inactive, paclet:ref/Inactive]) sum:

approxsol=u[x,t]/.sol[[1]]/.{Infinity->4}//Activate//Expand

Visualize the evolution of the temperature to the steady-state value of 60°:

Plot[Table[approxsol,{t,0.02,0.9,0.07}]//Evaluate,{x,0,1},AxesOrigin->{0,0},PlotRange->All]

Construct a complex analytic function, starting from the values of its real and imaginary parts on the x axis. The real and imaginary parts u and v satisfy the Cauchy–Riemann equations:

creqns={D[u[x,y],x]==D[v[x,y],y],D[v[x,y],x]==-D[u[x,y],y]};

Prescribe the values of u and v on the x axis:

xvals={u[x,0]==x^3,v[x,0]==0};

Solve the Cauchy–Riemann equations:

sol=DSolve[{creqns,xvals},{u,v},{x,y}]

Verify that the solutions are harmonic functions:

Laplacian[{u[x,y],v[x,y]}/.sol[[1]],{x,y}]

Visualize the streamlines and equipotentials generated by the solution:

ContourPlot[{u[x,y],v[x,y]}/.sol[[1]],{x,-5,5},{y,-5,5},ContourStyle->{Red,Blue},PlotTheme->"Marketing"]

Construct an analytic function from the solution:

f[x_,y_]=u[x,y]+I v[x,y]/.sol[[1]]

This represents the function f(z)==(z^3):

(f[x,y]//Factor)/.{x+I y->z}

OpenersExampleSubsection25(Spacer1)General Partial Differential Equations  (5)

Study the evolution of a smooth solution for Burgers' equation to a shock wave in the limit when the viscosity parameter becomes infinitely small:

eqns ={ D[u[x, t],t] + u[x, t]D[u[x,t],x] == ϵ D[u[x,t],{x,2}] ,u[x,0]==Piecewise[{{1,x<0}}]};

dsol=DSolve[eqns, u,{x,t}]

The solution is smooth for any positive value of ϵ:

Plot3D[u[x,t]/.dsol[[1]]/.{ϵ-> 1/10},{x,-2,2},{t,0.001,5}]

The solution develops a shock discontinuity in the limit when ϵ approaches 0:

Table[Plot3D[u[x,t]/.dsol[[1]]/.{ϵ-> 1/1000},{x,-2,2},{t,0.001,5},Exclusions->All,Ticks->None],{ϵ,{1/10,1/100,1/1000}}]

An electron constrained to move in a one-dimensional box of length d is governed by the free Schrödinger equation with Dirichlet conditions at the endpoints:

eqn=I ℏ D[ψ[x,t],t] == ((-(ℏ^2))/(2m)) D[ψ[x,t],{x,2}];
bcs = {ψ[0,t]==0,ψ[d,t]==0};

The general solution to this equation is a sum of trigonometric-exponential terms:

DSolve[Join[{eqn},bcs],ψ[x,t],{x,t}]

Each term in the sum is called a stationary state, as using the sine as initial conditions leads to the positional probability density ρ==(Conjugate[ψ])ψ being time independent. For example:

sol1=DSolve[Join[{eqn,ψ[x,0]==(Sqrt[(2/d)])Sin[Pi(x/d)]},bcs],ψ[x,t],{x,t}]

The resulting probability distribution is independent of time:

ρ1[x_,t_]=Simplify[ComplexExpand[Conjugate[ψ[x,t]]ψ[x,t] /. First[sol1]],d>0]

The normalization of the initial data was chosen so that the integral of the density (the total probability of finding the particle somewhere) is 1:

Integrate[ρ1[x,t],{x,0,d}]

Using any other initial condition, even one as simple as a sum of two stationary states, will lead to a complicated, time-dependent density:

sol2=DSolve[Join[{eqn,ψ[x,0]==(1/(Sqrt[d]))Sin[Pi(x/d)]+(1/(Sqrt[d]))Sin[2Pi(x/d)]},bcs],ψ[x,t],{x,t}]

This density is not stationary, as t appears in the second and third cosines:

ρ2[x_,t_]=Simplify[ComplexExpand[Conjugate[ψ[x,t]]ψ[x,t] /. First[sol2]],d>0]

Although the probability density is time dependent, its integral is still the constant 1:

Integrate[ρ2[x,t],{x,0,d}]

Entering the mass of the electron and the value of ℏ in SI units and setting d to a typical interatomic distance of 1 nm results in the following density function:

ρe[x_,t_]=ρ2[x,t]/. {ℏ->1.055*^-34,m->9.109*10^-31,d->10^-9}

Visualize the function over the spatial domain and one period in time:

Plot3D[ρe[x (10^(-9)),t (10^(-15))](10^(-9)),{x,0,1},{t,0,3.66},PlotTheme->{"Grid","LargeLabels"},AxesLabel->{"x (nm)","t (fs)", "ρe ((nm^(-1)))"},ImageSize->Medium]

Viewing the graph as a movie of probability densities, it can be seen that "center" of the electron moves from side to side of the box:

Animate[Plot[ρe[x,t],{x,0,10^-9},PerformanceGoal->-"Quality",PlotRange->{0,4*^9},ImageSize->Medium,AxesLabel->{"x (m)", "ρe ((m^(-1)))"}],{t,0,3.66*^-15},SaveDefinitions->True]

Find the value of a European vanilla call option if the underlying asset price and the strike price are both $100, the risk-free rate is 5%, the volatility of the underlying asset is 20%, and the maturity period is 1 year, using the Black–Scholes model:

BlackScholesModel={D[c[t,s],t]+ 1/2σ^2 s^2 D[c[t,s],{s,2}]+r s D[c[t,s],s] -r c[t,s]==0,c[T,s]==Max[s-k,0]};

Solve the boundary value problem:

dsol=c[t,s]/.DSolve[BlackScholesModel,c[t,s],{t,s}][[1]]

Compute the value of the European vanilla option:

dsol/.{t-> 0,s->100,k-> 100, σ-> 0.2,T-> 1,r-> 0.05}

Compare with the value given by (RefLink[FinancialDerivative, paclet:ref/FinancialDerivative]):

FinancialDerivative[{"European","Call"}, {"StrikePrice"-> 100.00, "Expiration"->1},  {"InterestRate"-> 0.05, "Volatility" -> 0.2 ,"CurrentPrice"-> 100}]

Recover a function from its gradient vector:

sol=DSolve[{D[f[x,y], x]==x y Cos[x y]+Sin[x y], 
                D[f[x,y],y]==-(E^(-y))+(x^2) Cos[x y]},f,{x,y}]

The solution represents a family of parallel surfaces:

Plot3D[Table[f[x,y,z]/.sol[[1]]/.{(C[1])->k},{k,1,22,5}]//Evaluate,{x,0,10},{y,0,2},PlotRange->All]

Solve a Cauchy problem to generate Stirling numbers:

sol=u[x,y]/.DSolve[{(1-x)D[u[x,y],x]==y u[x, y],u[0, y]==1},u, {x,y}][[1]]

Use the generating function to obtain Stirling numbers:

Table[(-1)^i SeriesCoefficient[ Series[sol,{x,0,10},{y,0,4}],{10,i}]10!,{i,4}]

StirlingS1[10,Range[4]]

OpenersExampleSection5(Spacer1)Properties & Relations  (9)

Solutions satisfy the differential equation and boundary conditions:

DSolve[{y''[x]-y[x]==0,y[0]==1,y'[0]==4},y,x]

Simplify[{y''[x]-y[x]==0,y[0]==1,y'[0]==4}/.%]

Differential equation corresponding to (RefLink[Integrate, paclet:ref/Integrate]):

DSolve[y'[x]==Exp[x^2],y,x]

Integrate[Exp[x^2],x]

Use (RefLink[NDSolve, paclet:ref/NDSolve]) to find a numerical solution:

exactsol=DSolve[{y''[x]+y[x]==0,y[0]==1,y'[0]==0},y,x]

Table[y[x]/.exactsol[[1]],{x,-2., 2}]

numsol=NDSolve[{y''[x] +y[x]==0,y[0]==1,y'[0]==0}, y,{x,-2,2}]

Table[y[x]/.numsol[[1]],{x,-2.,2}]

Use (RefLink[DEigensystem, paclet:ref/DEigensystem]) to find eigenvalues and eigenfunctions:

{ℒ,ℬ}={-Laplacian[u[x],{x}],DirichletCondition[u[x]==0,True]};

Find the complete eigensystem:

DSolve[{u''[x]+λ u[x]==0,u[0]==0,u[π]==0},u[x],x]

Find eigenvalues and eigenfunctions:

DEigensystem[{ℒ,ℬ},u[x],{x,0,Pi},3]

Compute an impulse response using (RefLink[DSolve, paclet:ref/DSolve]):

DSolve[y'''[x]-5y''[x]+9y'[x]-5y[x]==DiracDelta''[x]+2DiracDelta'[x]+DiracDelta[x]&&y[-1]==0&&y'[-1]==0&&y''[-1]==0,y[x],x]//FullSimplify

The same computation using (RefLink[InverseLaplaceTransform, paclet:ref/InverseLaplaceTransform]):

InverseLaplaceTransform[((s^2+2s+1)/(s^3-5s^2+9s-5)),s,x]//FullSimplify

(RefLink[DSolve, paclet:ref/DSolve]) returns a rule for the solution:

DSolve[{y'[x]==y[x],y[0]==1},y[x],x]

(RefLink[DSolveValue, paclet:ref/DSolveValue]) returns an expression for the solution:

DSolveValue[{y'[x]==y[x],y[0]==1},y[x],x]

Apply (RefLink[N, paclet:ref/N])[DSolve[...]] to invoke (RefLink[NDSolve, paclet:ref/NDSolve]) if symbolic solution fails:

DSolve[{y''[x]+x^2 y'[x]+Tan[y[x]]==1,y[0]==1,y'[0]==1},y,{x,0,1}]

N[%]

Table[y[x]/.%[[1]],{x,0,1,0.2}]

Solve the Laplace equation in a rectangle:

peqn=Laplacian[u[x,y],{x,y}]==0;

bc={u[x,0]==0,u[x,1]==0,u[0,y]==y^2-y,u[1,y]==0};

u[x,y]/.DSolve[{peqn,bc},u[x,y],{x,y}][[1]]

Obtain the same result using the region notation:

Ω=Rectangle[{0,0},{1,1}];

rbc=DirichletCondition[u[x,y]==Piecewise[{{y^2-y,x==0}}],True];

u[x,y]/.DSolve[{peqn,rbc},u,{x,y}∈Ω][[1]]

Use system modeling for numerical solutions to larger hierarchical models:

sim=SystemModelSimulate[]

Plot the most important values:

SystemModelPlot[sim]

OpenersExampleSection6(Spacer1)Possible Issues  (4)

Results may contain symbolic integrals:

DSolve[y'[x]==f[x],y,x]

Inverse functions may be required to find the solution:

DSolve[{y'[x]^2==(1-y[x]^2)(1-(1/2)y[x]^2),y[0]==0},y,x]

Definitions for an unknown function may affect the evaluation:

y[x_]:=Cos[x]

DSolve[{y'[x]==0,y[0]==1},y,x]

Clearing the definition for the unknown function fixes the issue:

Clear[y]

DSolve[{y'[x]==0,y[0]==1},y,x]

Here (RefLink[DSolve, paclet:ref/DSolve]) gives an error message because z(x) is not included in the second argument:

DSolve[{y'[x]==3y[x],z'[x]==2 z[x],z[0]==1,y[0]==1},y[x],x]

Include z(x) in the second argument to obtain a solution:

DSolve[{y'[x]==3y[x],z'[x]==2 z[x],z[0]==1,y[0]==1},{y[x],z[x]},x]

Alternatively, use (RefLink[DSolveValue, paclet:ref/DSolveValue]) to obtain the solution for y(x) alone:

DSolveValue[{y'[x]==3y[x],z'[x]==2 z[x],z[0]==1,y[0]==1},y[x],x]

OpenersExampleSection7(Spacer1)Neat Examples  (2)

Generate a Cornu spiral:

DSolve[{x'[s]==Cos[t[s]], y'[s]==Sin[t[s]],t'[s] ==s,x[0]==0,y[0]==0,t[0]==0}, {x,y,t},s]

ParametricPlot[Evaluate[{x[s], y[s]}/.%], {s,-10,10}]

Solve the sixth symmetric power of the Legendre differential operator:

sol = DSolve[(-((192n(1+n)x^5)/(1-x^2)^6)+(2496n(1+n)x^3)/
        (1-x^2)^5-(8160n^2(1+n)^2x^3)/(1-x^2)^5-(1632n(1+n)x)/(1-x^2)^4+(7824n^2(1+n)^2x)/(1-x^2)^4- 
       (6912n^3(1+n)^3x)/(1-x^2)^4)y[x]+((64x^6)/(1-x^2)^6-(1824x^4)/(1-x^2)^5+ 
       (8256n(1+n)x^4)/(1-x^2)^5+(2880x^2)/(1-x^2)^4- 
       (19200n(1+n)x^2)/(1-x^2)^4+(22896n^2(1+n)^2x^2)/
        (1-x^2)^4-272/(1-x^2)^3+(2208n(1+n))/(1-x^2)^3- 
       (4384n^2(1+n)^2)/(1-x^2)^3+(2304n^3(1+n)^3)/(1-x^2)^3)
      y'[x]+(-((2016x^5)/(1-x^2)^5)+ 
       (9408x^3)/(1-x^2)^4-(19488n(1+n)x^3)/(1-x^2)^4-
       (3696x)/(1-x^2)^3+(12768n(1+n)x)/(1-x^2)^3- 
       (9408n^2(1+n)^2x)/(1-x^2)^3)y''[x]+ 
     ((4816x^4)/(1-x^2)^4-(7168x^2)/(1-x^2)^3+ 
       (9632n(1+n)x^2)/(1-x^2)^3+616/(1-x^2)^2- 
       (1456n(1+n))/(1-x^2)^2+(784n^2(1+n)^2)/(1-x^2)^2) y'''[x]+(-((2800x^3)/(1-x^2)^3)+
       (1400x)/(1-x^2)^2-(1400n(1+n)x)/(1-x^2)^2)
      y''''[x]+((560x^2)/(1-x^2)^2-70/(1-x^2)+ 
       (56n(1+n))/(1-x^2))y'''''[x]- 
     (42x y''''''[x])/(1-x^2)+y'''''''[x]== 0,y,x]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[DSolveValue, paclet:ref/DSolveValue])  ▪  (RefLink[NDSolve, paclet:ref/NDSolve])  ▪  (RefLink[AsymptoticDSolveValue, paclet:ref/AsymptoticDSolveValue])  ▪  (RefLink[WhenEvent, paclet:ref/WhenEvent])  ▪  (RefLink[DEigensystem, paclet:ref/DEigensystem])  ▪  (RefLink[DEigenvalues, paclet:ref/DEigenvalues])  ▪  (RefLink[NDEigensystem, paclet:ref/NDEigensystem])  ▪  (RefLink[NDEigenvalues, paclet:ref/NDEigenvalues])  ▪  (RefLink[GreenFunction, paclet:ref/GreenFunction])  ▪  (RefLink[Solve, paclet:ref/Solve])  ▪  (RefLink[RSolve, paclet:ref/RSolve])  ▪  (RefLink[Integrate, paclet:ref/Integrate])  ▪  (RefLink[DifferentialRoot, paclet:ref/DifferentialRoot])  ▪  (RefLink[StreamPlot, paclet:ref/StreamPlot])  ▪  (RefLink[ItoProcess, paclet:ref/ItoProcess])  ▪  (RefLink[SystemModelSimulate, paclet:ref/SystemModelSimulate])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Differential Equations, paclet:tutorial/DifferentialEquations])}, {▪(RefLinkPlain[Differential Equation Solving with DSolve, paclet:tutorial/DSolveOverview])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Equation Solving, paclet:guide/EquationSolving])}, {▪(RefLinkPlain[Calculus, paclet:guide/Calculus])}, {▪(RefLinkPlain[Differential Equations, paclet:guide/DifferentialEquations])}, {▪(RefLinkPlain[Differential Operators, paclet:guide/DifferentialOperators])}, {▪(RefLinkPlain[Partial Differential Equations, paclet:guide/PDEModelingAndAnalysis])}, {▪(RefLinkPlain[Mathematical Data, paclet:guide/MathematicalData])}, {▪(RefLinkPlain[Scientific Models, paclet:guide/ScientificModels])}, {▪(RefLinkPlain[Integral Transforms, paclet:guide/IntegralTransforms])}, {▪(RefLinkPlain[Solvers over Regions, paclet:guide/GeometricSolvers])}, {▪(RefLinkPlain[Discrete Calculus, paclet:guide/DiscreteCalculus])}})}})

({{(Spacer1), ({{(Spacer1)Related Links}, {(Spacer1)▪(RefLinkPlain[(Spacer1)Implementation notes: Algebra and Calculus, paclet:tutorial/SomeNotesOnInternalImplementation#8313])}})}})