Topic 2 Introduction to Differential Equations

2.1 Basic concepts

2.1.1 How to define a differential equation in Maple

Depending on the differentiation command, there are three ways to define a differential equation in Maple.

Example 2.1 Assign the differential equation \(y'=2y\) to a variable in Maple.

  • Solution.
  • Method 1: Using the diff command

    ode111:=diff(y(x), x)=2*y(x)
  • Method 2: Using the the prime derivative notation

    ode112:=y'=2y
  • Method 3: Using the command D

    ode113:=D(y)(x)=2*y(x)

Among the three methods, the one using diff is the standard choice.

Exercise 2.1 Assign the differential equation \(y'=y(1-0.001y)\) to a variable in Maple.

2.1.2 How to check solutions

To check if a function (explicitly of implicitly defined) is a solution of a given differential equation, you may use the odetest(function, ODE, y(x)) command. If the output is 0, then the function is a solution.

Example 2.2 Verify that \(y=ce^{2x}\) is a solution to the differential equation \(y'=2y\).

Solution. Run the following command, you will see that output is 0. So the function is a solution.

odetest(y(x)=c*exp(2*x), diff(y(x), x)=2*y(x), y(x))

Example 2.3 Verify that \(x^2+y^2=1\) is a solution of the equation \(y'=-\frac xy\).

Solution. Again, running the following command returns the number 0. So the implicit function is a solution.

odetest(x^2+y(x)^2=1, diff(y(x),x)=-x/(y(x)), y(x));

When working with differential equations, we should always use \(y(x)\) instead of \(y\) to indicate that \(y\) is a function of \(x\).

Exercise 2.2 Verify that the function \(y=c_1e^x+c_2e^{-x}\) is a solution of the equation \(y''=y\).

Exercise 2.3 Verify that \(x^2+4y^2=c\) is an implicit solution of the equation \(4yy'=x\).

2.2 Solution curves vs Integral curves

A solution curve is the graph of a function \(y=f(x)\) that satisfies the given differential equation. An integral curves is a union of solution curves.

Example 2.4 Consider the differential equation \(yy'=4x\). Verify that the graphs of the functions \(y=\pm\sqrt{4x^2-1}\) are solution curves of the equation, while the hyperbola \(4x^2-y^2=1\) defines an integral curve of the equation.

Solution. Let’s rename the function as \(y_1(x)=\sqrt{4x^2-1}\) and \(y_2(x)=-\sqrt{4x^2-1}\). In Maple, it means we y[1](x) and y[2](x). We can check that they are solutions using the seq loop.

ode121:=y(x)*diff(y(x), x)=4*x:
y[1](x):=sqrt(4*x^2-1);
y[2](x):=-sqrt(4*x^2-1);
seq(odetest(y(x)=y[i](x), ode121, y(x)), i = 1 .. 2);

The outputs show that \(y_1\) and \(y_2\) are solutions.

To see that hyperbola \(4x^2-y^2=1\) defines an integral curve, we solve for \(y\).

soly:=solve(4*x^2-y^2=1, y);

You will see that the solutions are exactly the functions \(y_1\) and \(y_2\). So as an union of solution curves the hyperbola is an integral curve.

Plotting those curves will help use understand better.

solutioncurves := plot([y[1](x), y[2](x)], 
  x = -5 .. 5, y = -5 .. 5, color = [green, red]);
with(plots):
integralcurve := implicitplot(4*x^2 - y^2 = 1, 
  x = -5 .. 5, y = -5 .. 5, color = blue, 
  linestyle = dot);

To check the integral curve is the union of the two solution curve, we can use the display command.

display(solutioncurves,integralcurve)

Exercise 2.4 Consider the differential equation \(yy'=4x\). Verify that the graphs of the functions \(y=\pm\sqrt{4x^2+1}\) are solution curves of the equation, while the hyperbola \(y^2-4x^2=1\) defines an integral curve of the equation.

2.3 Direction fields

In Maple, the commands DEplot, dfieldplot, and phaseportrait supported by the package DETools can be used to plot the direction field and solution curves. The basic usage is as follows

DEplot(differential equation, function, ranges, options)

Again, using the command ?DEplot, we can find details and examples on the command. In the following, I will use DEplot as an example to show how they work.

Example 2.5 Plot the direction field for the differential equation \(y'=-\frac xy\). Can you guess what is a solution to this equation?

Solution. Let’s first define the differential equations and assign it to a variable.

ode131:=diff(y(x), x)=-x/(y(x));

Now load the package DETools using the command with().

with(DETools):

With the package loaded, we can use DEplot to plot the direction field for ode131, say in the region \(-5\le x\le 5\) and \(-5\le y\le 5\).

DEplot(ode131, y(x), x =-5..5, y =-5..5, 
  title = " Direction Field for y'=-x/y ")

Note that one may change the outlook by add options, such as color and arrows. Running the following command, you will see the difference.

DEplot(diff(y(x), x) = -(x - 1)/(y(x) + 1), y(x), 
  x = -5 .. 5, y = -5 .. 5,
  title = "Direction Field for y'=2 y",
  color = -(x - 1)/(y(x) + 1), arrows = line)

The direction field suggests that solutions are circles.

To display \(y(x)\) as \(y\) in the output, you may run the following commands first.

with(PDEtools, declare):
declare(y(x), prime=x); # Turn ON the enhanced DEdisplay feature

You will see the following output \[ {\color{blue} \text{derivatives with respect to } x \text{ of functions of one variable will now be displayed with '} } \]

Exercise 2.5 Plot the direction field for the differential equation \(y'=-\frac{x-1}{y+1}\). Can you guess what is a solution to this equation?

Exercise 2.6 Plot the direction field for the differential equation \(y'=-\frac{x}{2y}\). Can you guess what is a solution to this equation?