Topic 3 First Order Differential Equations

3.1 Classification

Knowing the type of a differential equation will be very helpful for solving it. In Maple, we can use the command odeadvisor(ode, y(x)) supported by the package DETools to learn what type of equation is it.

Example 3.1 Determine the primary type of each of the following differential equations.

  1. \(y'=xy\)

  2. \(y'=xy+1\)

  3. \(y'=xy+y^2\)

  4. \(y'=\frac{xy}{x^2+y^2}\)

Solution. We first load the package DETools anonymously.

with(DETools):

Now we can classify those equations using odeadvisor.

odeadvisor(diff(y(x),x)=x*y(x));
odeadvisor(diff(y(x),x)=x*y(x)+1);
odeadvisor(diff(y(x),x)=x*y(x)+y(x)^2;
odeadvisor(diff(y(x), x) = (x*y(x))/(x^2 + y(x)^2));

Exercise 3.1 Determine the primary type of each of the following differential equations.

  1. \(y'=x^2y^2+x^2\)

  2. \(y'=x^2y+x\)

  3. \(y'=xy+y^3\)

  4. \(y'=\frac{x-y}{x+y}\)

3.2 Solving differential equations

To solve an ordinary differential equation, or a system of them, or initial value problems, you may use the command dsolve({ODE, InitialConditions}, y(x), options), where the initial conditions may be omitted to get a general solution. Note that dsolve returns an equation with \(y(x)\) on the left.

Among options, you may choose to use different method to solve the equations, for example, numeric, series or method=laplace are options that can be imposed and will be used later.

Example 3.2 Consider the differential equation \(y'=2y+x.\)

  1. Find the general solution.

  2. Find the solution that satisfies the initial condition \(y(0)=1\).

  3. Plot the solution curve of the initial value problem.

Solution. It will be convenient to define the differential equation first.

ode221:=diff(y(x), x)=2*y(x)+x:

The general solution can be obtained by the following command.

dsolve(ode221, y(x));

The solution of the initial value problem can be obtained by

sol221:=dsolve({ode221, y(0)=1}, y(x));

To plot the solution curve, we need to get the function expression instead of the equation. This can be done using the command rhs.

plot(rhs(sol221), x=-5..5)

By default, the dsolve command only returns a function. To show more detailed information about the computation, you may assign to infolevel[dsolve] an integer 1 through 5 before using the dsolve command. For example, after running the following command infolevel[dsolve]:=3, the output from dsolve will show three pieces of information: methods tried, successful or not, the solution.

Exercise 3.2 Consider the differential equation \(y'=x+y.\)

  1. Find the general solution.

  2. Find the solution that satisfies the initial condition \(y(0)=1\).

  3. Plot the solution curve of the initial value problem.

3.3 Integrating factors

In Maple, you may use intfactor that is supported by the package DETools to find an integrating factor for a given ODE. To test an integrating factor, you may use mutest which is again supported by the package DETools. If the command returns a 0, then the expression being tested is an integrating factor.

Example 3.3 Find an integrating factor for the equations \(y'=x^2y-x\) and test it using mutest.

Solution. Let’s first define the differential equation.

ode231:=diff(y(x), x)=x^2*y(x)-x:

Now loading the package and find an integrating factor \(\mu\).

with(DETools):
mu:=intfactor(ode231);

To test it, you may run the following command.

mutest(mu, ode231, y(x));

Exercise 3.3 Find an integrating factor for the differential equation. \(xy'=y-x.\)

3.4 Commands for specific type of equations

The DETools package also provides some commands for solving specific type of equations. The following is an incomplete list.

  1. The command separablesol(ode, dependent variable) determines whether the ode is a separable first order ODE and, if so, returns a solution to the equation.

Example 3.4 Consider the first order differential equation \[y'=\frac{x}{x^2y+y}.\]

Executing The following codes

with(DEtools):
sode := diff(y(x), x) = x/(x^2*y(x)+y(x));
exactsol(sode, y(x));

will produce a set of solutions \[\color{blue}{\left\{y(x) = \sqrt{\ln(x^{2}+1)-2\_\textit{C1}}, y(x) = -\sqrt{\ln(x^{2}+1)-2\_\textit{C1}}\right\}}.\]

  1. The command linearsol(ode, dependent variable) determines whether the ode is a first order linear ODE and, if so, returns a solution to the equation.

Example 3.5 Consider the linear first order differential equation \[y'+p(x)y=q(x).\]

Executing The following codes

with(DEtools):
lode := diff(y(x), x) + p(x)*y(x) = q(x);
linearsol(lode, y(x));

will produce a set of solutions \[ \color{blue}{ \{y(x) = {\color{gray}{\int}}(-p(x) z(x)+q(x)){\color{gray}{d}}x +\_\textit{C1}\} } \]

  1. The command exactsol(ode, dependent variable) determines whether the ode is an exact first order ODE and, if so, returns a solution to the equation. When the equation is not exact, it tries to find an integrating factor that converts the equation into an equivalent exact equation.

Example 3.6 Consider the first order differential equation \[(x^2 - y^2)\mathrm{d} x + 2xy\mathrm{d} y.\]

Executing The following codes

with(DEtools):
eode := x^2 - y(x)^2 + 2*x*y(x)*diff(y(x), x) = 0;
exactsol(eode, y(x));

will produce a set of solutions \[ \color{blue}{ \{y(x) = \sqrt{-\_\textit{C1} x -x^{2}}, y(x) = -\sqrt{-\_\textit{C1} x -x^{2}}\} } \]

One can also specific the method (type of the equation) in the dsolve command so that the equation will be solve by using the given method.