First order differential equations

>    restart:

Se e: Stewart, chapter 9. Maple has many facilities concerning differential equations.

As a first example we consider exercise 2 of  9.1:

>    y:=sin(x)*cos(x)-cos(x);

y := sin(x)*cos(x)-cos(x)

>    simplify(diff(y,x)+tan(x)*y);


>    simplify(subs(x=0,y));


Hence we conclude that y = sin(x)*cos(x)-cos(x)  satisfies the differential equation

>    y:='y':de:=diff(y(x),x)+tan(x)*y(x)=(cos(x))^2;

de := diff(y(x),x)+tan(x)*y(x) = cos(x)^2

and the initial condition

>    cond:=y(0)=-1;

cond := y(0) = -1

Note that Maple can also solve this initial value problem directly:

>    dsolve({de,cond},y(x));

y(x) = 1/2*sin(2*x)-cos(x)

In  9.2 direction fields  are used in order to get an idea for the solution of a differential equation.

This can also be done by using Maple. To do this we use the command dfieldplot  or DEplot  which are both available in the package DEtools .

>    with(DEtools): de:=diff(y(x),x)=x+y(x): dfieldplot(de,y(x),x=-3..3,y=-3..3);

[Maple Plot]

It can also be done in this way:

>    DEplot(de,y(x),x=-3..3,y=-3..3);

[Maple Plot]

Using the latter command we can also plot the solution curve through the point (0,1)  into the same picture:


>    DEplot(de,y(x),x=-3..3,y=-3..3,[[0,1]]);

[Maple Plot]

See also example 1:

>    de:=diff(y(x),x)=x^2+(y(x))^2-1;

de := diff(y(x),x) = x^2+y(x)^2-1

>    DEplot(de,y(x),x=-3..3,y=-3..3,[[0,-2],[0,-1],[0,0],[0,1],[0,2]]);

[Maple Plot]

Maple easily deals with the separable differential equations  of  9.3.

Example 1:


>    de:=diff(y(x),x)=x^2/(y(x))^2: dsolve({de,y(0)=2},y(x));

y(x) = (x^3+8)^(1/3)

Example 2:

>    de:=diff(y(x),x)=6*x^2/(2*y(x)+cos(y(x))): dsolve(de,y(x));

_C1+x^3-1/2*y(x)^2-1/2*sin(y(x)) = 0

Now figure 2 can be produced als follows:

>    with(plots): implicitplot({seq(y^2+sin(y)=2*x^3+C,C=-3..3)},x=-2..2,y=-4..4);

[Maple Plot]

And example 3:

>    de:=diff(y(x),x)=x^2*y(x): dsolve(de,y(x));

y(x) = _C1*exp(1/3*x^3)

The appropriate pictures, figure 3:

>    P1:=DEplot(de,y(x),x=-2..2,y=-6..6): display(P1);

[Maple Plot]

and figure 4:

>    P2:=plot({5*exp(x^3/3),seq(A*exp(x^3/3),A=-2..2)},x=-2..2,y=-6..6): display(P2);

[Maple Plot]

We can also combine the two pictures:

>    display(P1,P2);

[Maple Plot]

Figure 9 can be produced as follows:

>    implicitplot({seq(x=k*y^2,k=-3..3),seq(x^2+y^2/2=C,C=0..3)},x=-3..3,y=-3..3);

[Maple Plot]

These are the solutions of diff(y(x),x) = y(x)/(2*x)  and of diff(y(x),x) = -2*x/y(x)   respectively:

>    dsolve(diff(y(x),x)=y(x)/(2*x),y(x));

y(x) = _C1*x^(1/2)

>    dsolve(diff(y(x),x)=-2*x/y(x)),y(x);

y(x) = (-2*x^2+_C1)^(1/2), y(x) = -(-2*x^2+_C1)^(1/2), y(x)

Also the linear  differential equations of 9.6 do not lead to any difficulties for Maple.

Example 1:

>    de:=diff(y(x),x)+3*x^2*y(x)=6*x^2: dsolve(de,y(x));

y(x) = 2+exp(-x^3)*_C1

Example 2:

>    dsolve({x^2*diff(y(x),x)+x*y(x)=1,y(1)=2},y(x));

y(x) = (ln(x)+2)/x

>    plot((ln(x)+2)/x,x=0..4,y=-5..5);

[Maple Plot]

Example 3:

>    sol:=dsolve(diff(y(x),x)+2*x*y(x)=1,y(x));

sol := y(x) = (-1/2*I*Pi^(1/2)*erf(x*I)+_C1)*exp(-x^2)

Maple produces the solution in terms of the so-called error function    erf(x) .

You can use ?erf  to see the definition of this function.

We have:   erf(x) = 2/sqrt(Pi)   int(exp(-t^2),t = 0 .. x)    .

Therefore the solution can also be written as:   y(x)  = sqrt(Pi)/2   exp(-x^2) erf(x)  + C*exp(-x^2)   .

If we use the notation of the book, we can produce figure 3 as follows:

>    f:=x->exp(-x^2)*int(exp(t^2),t=0..x)+C*exp(-x^2): plot({seq(f(x),C=-2..2)},x=-2.5..2.5,y=-2.5..2.5);

[Maple Plot]