13.4.1 Solving differential equations
The desolve (or
dsolve or
deSolve) command can solve:
-
linear differential equations with constant coefficients,
- first order linear differential equations,
- first order differential equations without y,
- first order differential equations without x,
- first order differential equations with separable variables,
- first order homogeneous differential equations: y′=F(y/x),
- first order differential equations with integrating factor,
- first order Bernoulli differential equations: a(x)y′+b(x)y=c(x)yn,
- first order Clairaut differential equations: y=x y′+f(y′).
-
desolve takes one mandatory arguments and two
optional arguments:
-
de, a differential equation or list of differential
equations, including any initial conditions.
- Optionally, x, the variable (by default x).
- Optionally, y, the unknown function (by default y).
The unknown function can be given in variable form (such as
y) or function form (such as y(x)), in which
case the variable does not have to be given as a separate argument.
- desolve(de ⟨,x,y ⟩)
returns the solution of the differential equation.
In the differential equations, the function y can be denoted by y
or y(x), the derivative by y′, y′(x) or diff(y(x),x),
etc.
Examples
Solve y′′+2y′+y=0.
Find the solution which satisfies the initial conditions y(0)=1 and y′(0)=0:
desolve([y''+2*y'+y,y(0)=1,y'(0)=0],y) |
or:
desolve(y''+2*y'+y and y(0)=1 and y'(0)=0,y) |
With t as the independent variable:
desolve(diff(y(t),t$2)+2*diff(y(t),t)+y(t),y(t)) |
or:
desolve(diff(y(t),t$2)+2*diff(y(t),t)+y(t),t,y) |
With the initial conditions:
desolve([diff(y(t),t$2)+2*diff(y(t),t)+y(t),y(0)=1,y'(0)=0],y(t)) |
or:
desolve([diff(y(t),t$2)+2*diff(y(t),t)+y(t),y(0)=1,y'(0)=0],t,y) |
Solve y′′+y=cos(x).
Input (typing twice prime for y''
):
or:
desolve((diff(diff(y))+y)=(cos(x)),y) |
c0, c1 are the constants of integration: y(0)=c0
y′(0)=c1.
If the variable is not x but t:
desolve(derive(derive(y(t),t),t)+y(t)=cos(t),t,y) |
c0, c1 are the constants of integration: y(0)=c0 and
y′(0)=c1.
Solve y′′+y=cos(x), y(0)=1.
desolve([y''+y=cos(x),y(0)=1],y) |
Solve y′′+y=cos(x), y(0)2=1.
desolve([y''+y=cos(x),y(0)^2=1],y) |
|
| ⎡
⎢
⎢
⎣ | | +c1 sinx+ | | ,− | | +c1 sinx+ | | ⎤
⎥
⎥
⎦ |
| | | | | | | | | | |
|
each component of this list is a solution,
you have two solutions depending
on the constant c1 (y′(0)=c1) and corresponding to y(0)=1 and to y(0)=−1.
Solve y′′+y=cos(x), y(0)2=1, y′(0)=1.
desolve([y''+y=cos(x),y(0)^2=1,y'(0)=1],y) |
|
| ⎡
⎢
⎢
⎣ | | +sinx+ | | ,− | | +sinx+ | | ⎤
⎥
⎥
⎦ |
| | | | | | | | | | |
|
each component of this list is a solution (you have two solutions).
Solve y′′+2y′+y=0.
the solution depends on two constants of integration:
c0 and c1 (y(0)=c0 and y′(0)=c1).
Solve y′′−6y′+9y=xe3x.
desolve(y''-6*y'+9*y=x*exp(3*x),y) |
|
e3 x | ⎛
⎝ | c0 x+c1 | ⎞
⎠ | + | | x3 e3 x
|
| | | | | | | | | | |
|
The solution depends on 2 constants of integration:
c0, c1 (y(0)=c0 and y′(0)=c1).
Examples of first order linear equations
Solve xy′+y−3x2=0.
Solve y′+x y=0, y(0)=1.
desolve([y'+x*y=0, y(0)=1]),y) |
or:
desolve((y'+x*y=0) && (y(0)=1),y) |
Solve x(x2−1)y′+2y=0.
desolve(x*(x^2-1)*y'+2*y=0,y) |
Solve x(x2−1)y′+2y=x2.
desolve(x*(x^2-1)*y'+2*y=x^2,y) |
If the variable is t instead of x, for example, solve:
desolve(t*(t^2-1)*diff(y(t),t)+2*y(t)=(t^2),y(t)) |
Solve x(x2−1) y′+2y=x2, y(2)=0.
desolve([x*(x^2-1)*y+2*y=x^2,y(2)=0],y) |
Solve √1+x2 y′−x−y=√1+x2.
desolve(y'*sqrt(1+x^2)-x-y-sqrt(1+x^2),y) |
Examples of first differential equations with separable variables
Solve y′=2√y.
|
| ⎡
⎢
⎢
⎢
⎢
⎢
⎣ | ⎛
⎜
⎜
⎝ | − | | c0+x | ⎞
⎟
⎟
⎠ | | ⎤
⎥
⎥
⎥
⎥
⎥
⎦ |
| | | | | | | | | | |
|
Solve xy′ln(x)−y(3ln(x)+1)=0.
desolve(x*y'*ln(x)-(3*ln(x)+1)*y,y) |
Examples of Bernoulli differential equations
a(x)y′+b(x)y=c(x)yn where n is a real constant
The method used is to divide the equation by yn,
so that it becomes a first order linear differential equation
in u=y1−n.
Solve x y′+2y+x y2=0.
desolve(x*y'+2*y+x*y^2,y) |
Solve x y′−2y=x y3.
desolve(x*y'-2*y-x*y^3,y) |
|
| ⎡
⎢
⎢
⎢
⎢
⎢
⎣ | ⎛
⎜
⎜
⎝ | ⎛
⎜
⎜
⎝ | − | | · 2 x5+c0 | ⎞
⎟
⎟
⎠ | e−4 lnx | ⎞
⎟
⎟
⎠ | | ,− | ⎛
⎜
⎜
⎝ | ⎛
⎜
⎜
⎝ | − | | · 2 x5+c0 | ⎞
⎟
⎟
⎠ | e−4 lnx | ⎞
⎟
⎟
⎠ | | ⎤
⎥
⎥
⎥
⎥
⎥
⎦ |
| | | | | | | | | | |
|
Solve x2 y′−2y=xe(4/x) y3.
desolve(x*y'-2*y-x*exp(4/x)*y^3,y) |
|
| ⎡
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎣ | ⎛
⎜
⎜
⎜
⎜
⎝ | ⎛
⎜
⎜
⎜
⎜
⎝ | − | ∫ | 2 x4 | ⎛
⎜
⎝ | e | | ⎞
⎟
⎠ | | dx+c0 | ⎞
⎟
⎟
⎟
⎟
⎠ | e−4 lnx | ⎞
⎟
⎟
⎟
⎟
⎠ | | ,− | ⎛
⎜
⎜
⎜
⎜
⎝ | ⎛
⎜
⎜
⎜
⎜
⎝ | − | ∫ | 2 x4 | ⎛
⎜
⎝ | e | | ⎞
⎟
⎠ | | dx+c0 | ⎞
⎟
⎟
⎟
⎟
⎠ | e−4 lnx | ⎞
⎟
⎟
⎟
⎟
⎠ | | ⎤
⎥
⎥
⎥
⎥
⎥
⎥
⎥
⎦ |
| | | | | | | | | | |
|
Examples of first order homogeneous differential equations y′=F(y/x)
The method of integration is to search for t=y/x instead of y).
Solve 3x3 y′=y (3x2−y2).
desolve(3*x^3*diff(y)=((3*x^2-y^2)*y),y) |
|
| ⎡
⎢
⎢
⎢
⎢
⎢
⎣ | 0,− | | , | | ⎤
⎥
⎥
⎥
⎥
⎥
⎦ |
| | | | | | | | | | |
|
Hence the solutions are y=0 and the familiy of curves with parametric
equations x=c0 e3/(2t2), y=t c0 e3/(2t2)
(the parameter is denoted by t in the answer).
Examples of first order differential equations with an integrating factor
By multiplying the equation by a function of x,y it becomes a closed differential form.
Solve y y′+x=0.
In this example, x dx+y dy is closed, the integrating factor was 1.
Solve 2x y y′+x2−y2+a2=0.
desolve(2*x*y*y'+x^2-y^2+a^2,y) |
In this example, the integrating factor was 1/x2.
Example of first order differential equations without x
Solve (y+y′)4+y′+3y=0.
This kind of equation cannot be solved directly by Xcas, you
can use the following steps on solve it with the help of Xcas.
The idea is to find a parametric representation of
F(u,v)=0 where the equation is F(y,y′)=0.
Let u=f(t),v=g(t) be such a parametrization of F=0, then
y=f(t) and dy/dx=y′=g(t). Hence
dy/dt=f′(t)=y′ dx/dt=g(t) dx/dt.
|
The solution is the curve of parametric equations
x(t), y(t)=f(t), where x(t) is solution of the differential equation
g(t) dx=f′(t)dt.
Back to the example, you can let y+y′=t, hence:
y=−t−8t4, y′=dy/dx=3t+8t4, dy/dt=−1−32t3.
|
Therefore
(3t+8t4) dx=(−1−32t3) dt.
|
desolve((3*t+8*t^4)*diff(x(t),t)=(-1-32*t^3),x(t)) |
|
| 9 c0−11 ln | ⎛
⎝ | 8 t3+3 | ⎞
⎠ | −ln | ⎛
⎝ | t3 | ⎞
⎠ |
|
|
9 |
|
| | | | | | | | | | |
|
The solution is the curve of parametric equation:
x(t)= | 9 c0−11 ln | ⎛
⎝ | 8 t3+3 | ⎞
⎠ | −ln | ⎛
⎝ | t3 | ⎞
⎠ |
|
|
9 |
| , y(t)=−t−8t4.
|
Examples of first order Clairaut differential equations y=x y′+f(y′)
The solutions are the lines Dm of equation y=mx+f(m) where
m is a real constant.
Solve x y′+(y′)3−y=0.
Solve y−x y′−√a2+b2 y′2=0.
desolve((y-x*y'-sqrt(a^2+b^2*y'^2),y) |