Previous Up Next

13.4.1  Solving differential equations

The desolve (or dsolve or deSolve) command can solve:

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.

desolve(y''+2*y'+y,y)
     
e−x ⎛
⎝
c0 x+c1⎞
⎠
          

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)
     
e−x ⎛
⎝
x+1⎞
⎠
          

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)
     
e−t ⎛
⎝
c0 t+c1⎞
⎠
          

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)
     
e−t ⎛
⎝
t+1⎞
⎠
          

Solve y′′+y=cos(x).

Input (typing twice prime for y''):

desolve(y''+y=cos(x),y)

or:

desolve((diff(diff(y))+y)=(cos(x)),y)
     
c0 cosx+c1 sinx+
2 x sinx+cosx
4
          

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 cost+c1 sint+
2 t sint+cost
4
          

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)
     
3
4
 cosx+c1 sinx+
2 x sinx+cosx
4
          

Solve y′′+y=cos(x), y(0)2=1.

desolve([y''+y=cos(x),y(0)^2=1],y)
     
⎡
⎢
⎢
⎣
3 cosx
4
+c1 sinx+
2 x sinx+cosx
4
,−
5 cosx
4
+c1 sinx+
2 x sinx+cosx
4
⎤
⎥
⎥
⎦
          

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)
     
⎡
⎢
⎢
⎣
3 cosx
4
+sinx+
2 x sinx+cosx
4
,−
5 cosx
4
+sinx+
2 x sinx+cosx
4
⎤
⎥
⎥
⎦
          

each component of this list is a solution (you have two solutions).

Solve y′′+2y′+y=0.

desolve(y''+2*y'+y=0,y)
     
e−x ⎛
⎝
c0 x+c1⎞
⎠
          

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⎞
⎠
+
1
6
 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.

desolve(x*y'+y-3*x^2,y)
     
c0+x3
x
          

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)
     
e
−
x2
2
 
          

Solve x(x2−1)y′+2y=0.

desolve(x*(x^2-1)*y'+2*y=0,y)
     
c0 x2
x2−1
          

Solve x(x2−1)y′+2y=x2.

desolve(x*(x^2-1)*y'+2*y=x^2,y)
     
c0 x2+x2 lnx
x2−1
          

If the variable is t instead of x, for example, solve:

  t(t2−1) y′(t)+2y(t)=t2.
desolve(t*(t^2-1)*diff(y(t),t)+2*y(t)=(t^2),y(t))
     
c0 t2+t2 lnt
t2−1
          

Solve x(x2−1) y′+2y=x2, y(2)=0.

desolve([x*(x^2-1)*y+2*y=x^2,y(2)=0],y)
     
−ln⎛
⎝
2⎞
⎠
x2+x2 lnx
x2−1
          

Solve √1+x2 y′−x−y=√1+x2.

desolve(y'*sqrt(1+x^2)-x-y-sqrt(1+x^2),y)
     
−c0+ln⎛
⎜
⎝
√
x2+1
−x⎞
⎟
⎠
x−√
x2+1
          

Examples of first differential equations with separable variables

Solve y′=2√y.

desolve(y'=2*sqrt(y),y)
     
⎡
⎢
⎢
⎢
⎢
⎢
⎣
⎛
⎜
⎜
⎝
−
1
2
 c0+x⎞
⎟
⎟
⎠
2



 
⎤
⎥
⎥
⎥
⎥
⎥
⎦
          

Solve xy′ln(x)−y(3ln(x)+1)=0.

desolve(x*y'*ln(x)-(3*ln(x)+1)*y,y)
     
c0 x3 lnx           

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)
     
⎡
⎢
⎢
⎣
0,−
1
c1 x2+x
⎤
⎥
⎥
⎦
          

Solve x y′−2y=x y3.

desolve(x*y'-2*y-x*y^3,y)
     
⎡
⎢
⎢
⎢
⎢
⎢
⎣
⎛
⎜
⎜
⎝
⎛
⎜
⎜
⎝
−
1
5
· 2 x5+c0⎞
⎟
⎟
⎠
e−4 lnx⎞
⎟
⎟
⎠
−
1
2



 
,−⎛
⎜
⎜
⎝
⎛
⎜
⎜
⎝
−
1
5
· 2 x5+c0⎞
⎟
⎟
⎠
e−4 lnx⎞
⎟
⎟
⎠
−
1
2



 
⎤
⎥
⎥
⎥
⎥
⎥
⎦
          

Solve x2 y′−2y=xe(4/x) y3.

desolve(x*y'-2*y-x*exp(4/x)*y^3,y)
     
⎡
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎣
⎛
⎜
⎜
⎜
⎜
⎝
⎛
⎜
⎜
⎜
⎜
⎝
−∫2 x4 ⎛
⎜
⎝
e
1
x
 
⎞
⎟
⎠
4


 
 dx+c0⎞
⎟
⎟
⎟
⎟
⎠
e−4 lnx⎞
⎟
⎟
⎟
⎟
⎠
−
1
2





 
,−⎛
⎜
⎜
⎜
⎜
⎝
⎛
⎜
⎜
⎜
⎜
⎝
−∫2 x4 ⎛
⎜
⎝
e
1
x
 
⎞
⎟
⎠
4


 
 dx+c0⎞
⎟
⎟
⎟
⎟
⎠
e−4 lnx⎞
⎟
⎟
⎟
⎟
⎠
−
1
2





 
⎤
⎥
⎥
⎥
⎥
⎥
⎥
⎥
⎦
          

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,−
x √
6
 
√
ln⎛
⎜
⎜
⎝
x
c0
⎞
⎟
⎟
⎠
2 ln⎛
⎜
⎜
⎝
x
c0
⎞
⎟
⎟
⎠
,
x √
6
 
√
ln⎛
⎜
⎜
⎝
x
c0
⎞
⎟
⎟
⎠
2 ln⎛
⎜
⎜
⎝
x
c0
⎞
⎟
⎟
⎠
⎤
⎥
⎥
⎥
⎥
⎥
⎦
          

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.

desolve(y*y'+x,y)
     
⎡
⎢
⎣
√
−x2−2 c0
,−√
−x2−2 c0
⎤
⎥
⎦
          

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)
     
⎡
⎢
⎣
√
a2−x2−c1 x
,−√
a2−x2−c1 x
⎤
⎥
⎦
          

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.

desolve(x*y'+y'^3-y,y)
     
⎡
⎣
c0 x+c03⎤
⎦
          

Solve y−x y′−√a2+b2 y′2=0.

desolve((y-x*y'-sqrt(a^2+b^2*y'^2),y)
     
⎡
⎢
⎣
c0 x+√
a2+b2 c02
⎤
⎥
⎦
          

Previous Up Next