Second and Higher Order Ordinary Differential Equations


This web site provides an introduction to the computer algebra system Maple, created by MapleSoft ©. This tutorial is made solely for the purpose of education, and intended for students taking APMA 0330 course at Brown University.

The commands in this tutorial are all written in red text (as Maple input), while Maple output is in blue, which means that the output is in 2D output style. You can copy and paste all commands into Maple, change the parameters and run them. You, as the user, are free to use the mw files and scripts to your needs, and have the rights to distribute this tutorial and refer to this tutorial as long as this tutorial is accredited appropriately. The tutorial accompanies the textbook Applied Differential Equations. The Primary Course by Vladimir Dobrushkin, CRC Press, 2015; http://www.crcpress.com/product/isbn/9781439851043. Any comments and/or contributions for this tutorial are welcome; you can send your remarks to <Vladimir_Dobrushkin@brown.edu>

Return to computing page for the first course APMA0330
Return to computing page for the second course APMA0340
Return to Maple tutorial for the first course APMA0330
Return to Maple tutorial for the second course APMA0340
Return to the main page for the first course APMA0330
Return to the main page for the second course APMA0340

 

1.4.1. Solving Higher Order Linear ODEs


 

 

Example 1.4.1: Consider a second order differential equation

\[ y'' (x) + y^2 \,\cos y =0. \]
We transfer this equation to an equivalent system of first order autonomous differential equations
\[ \begin{cases} y' = z , \\ z' = -y^2 \, \cos y . \end{cases} \]

Then we apply the phaseportrait function to obtain:

DE1 := diff(y(t),t) = z(t);
DE2 := diff(z(t),t) = -y(t)*cos(y(t));
phaseportrait([DE1,DE2],[y,z],t=-5..5,[[y(0)=1,z(0)=0],[y(0)=0,z(0)=2],[y(0)=0,z(0)=-2]],y=-Pi..Pi,z=-3..3,color=aquamarine,linecolor=blue);

There are a few things worth noting here. First, the solution curves are traced both forwards and backwards in time. Without actually plotting a point where the initial conditions are located, you will not be able to identify the initial point. Second, note that the function plots a direction field for autonomous equations, but does not do that for the 2-D case if the equation is not autonomous. Changing the equation to \( y' = z, \quad z' = -y cos t \) and applying the phaseportrait function to that

DE1 := diff(y(t),t) = z(t);
DE2 := diff(z(t),t) = -y(t)*cos(t); phaseportrait([DE1,DE2],[y,z],t=-5..5,[[y(0)=1,z(0)=0],[y(0)=0,z(0)=2],[y(0)=0,z(0)=-2]],y=-Pi..Pi,z=-3..3,color=aquamarine,linecolor=blue);

produces the plot

The point is that since the equation is no longer autonomous, then solutions can cross and so on, so the notion of direction field is no longer meaningful. Of course, we could make the equation autonomous by inserting a third variable, but we can't do 3-D phaseportraits with this function. Without plotting the direction field, it is impossible to identify the critical points through solution curves because they are traced both forwards and backwards in time.

Example 1.4.2:

 

 

 

II. Plotting


 

 

 

 

 

 

 

 

 

 

1.2. Direction Fields



 

 

 


 

 

1.3. Separable Equations


A differential equation y' = f(x,y) is said to be separable if the slope function is the product of two functions depending on only one variable:  f(x,y) = p(x) q(y). Then rewriting the derivative y' in differential form  y' = dy / dx , we separate variables:
                                                               dy / q(y) = p(x) dx
each part can be integrated. In other words, a separable differential equation is a differential equation in which the two variables can be placed on opposite sides of the equals sign such that the dx and x terms are on one side and the dy and the y terms are on the other. The dx and dy terms need to be multiplied by the x and y terms, respectively. There are two methods that can be used to solve the solution to a separable differential equation. We show these methods on the follwoing example.

Example 1.3.1. Consider separable differential equation:     y'= xy/(1+x*x). We show two methods that can be used to solve the given separable differential equation. A first one is to ask Matlab to find the solution.

 

 

 


Example 1.3.2. Consider separable differential equation:    y' +ycos(x) =0

Example 1.3.3. Consider separable differential equation:    x(y+1)(y-3) dx +(1+5y)(x+2) dy =0. We solve this equation by separating variables and then integrating:

 

 

1.4. Equations Reducible to the Separable Equations


Example 1.4.1.
Solutions to the equation xy'=x^2 y^3 -y

 

Example 1.4.3. Consider the initial value problem

y' = 1/(x-y+2),       y(0) =1 . We find its solution (in implicit form) and prot it using the following Mathematica's commands:

 

 

Example 1.4.4.
Another example.


 


 

Example 1.4.5.
Consider the differential equation

dy/dx = ( (2x-2y-2) / {x-1})^2 ,          where     x != 1

We exclude the singular point x=1 where the integral curves have an infinite slope. The right-hand side function (= slope function) is a composition of two functions:

( (2x-2y-2) / (x-1) )^2 = F(z(x,y)) ,         where       F(z) = z^2       and      z = (2x-2y-2) / (x-1) .

The function F(z(x,y)) is not homogeneous, but it can be converted to a homogeneous one by shifting

x=X+\alpha         and            y=Y+\beta ,

where

\alpha = 1,        \beta = 0

so x=X+1, \ y=Y. We next substitute $x=X+1$ and $y=Y$ into the given
equation and simplify. The result is

               dY/dX = dy / d(x-1) = dy /dx = {2(x-1) -2y/{x-1} )^2 = ( (2X -2Y) / X )^2

Setting $Y=vX$ gives us

X dv /dX +v = 4 (1-v)^2       or      dv (4(1-v)^2 -v) = dX / X .

Plotting the direction field, it can be seen that $v = a /2 \approx 1.64039$ is unstable equilibrium solution, and $v=
\frac{b}{2} \approx 0.609612$ is a stable equilibrium solution. These critical points are not singular solutions because integral curves do
not touch them, which means that an initial value problem for the differential equation $X\,v' = (2v-a)(2v-b)$ has a unique solution.

Now we return to the original variables. Since $X=x-1, \ Y=y$, and $v=Y/X$, the original differential equation has the general solution
in implicit form:

C|x-1|^{\sqrt{17}} = \left| \frac{8y -(9 + \sqrt{17})(x-1)}{8y -(9 -\sqrt{17})(x-1)} \right| ,   x ! = 1.

It can be solved with respect to $y$, and then plotted using the following Mathematica commands:

The given differential equation has two equilibrium solutions that correspond to $v=a/2$ and $v=b/2$:

y = (x-1) a/2 = (x-1) (9+\sqrt{17) )/8     and        y = (x-1) b/2 = (x-1) (9-\sqrt(17)) /8.

 

 

 

 

1.5. Exact Equations


The equation y dx + x dy =0 is exact. Consider the initial condition y(2)=3
Since Mathematica uses the command "N" for numerical evaluation, we change notation M(x,y) dx + N(x,y) dy =0 as MM(x,y) and NN(x,y)

 

 

Example 1.5.1.


1.6. Integrating Factors


Example 1.6.1. The equation
x(y^2 +y-6) dx (x-3)(1+2y) dy=0
is separable, with integrating factor mu(x,y)=(x-3)^(-1) (y^2 +y -6)^(-1).
Then we integrate

 

 

 

1.7. Linear and Bernoulli Equations


A linear differential equation is an equation of the form:

y' + p(x) y = f(x) .

Example 1.7.1.

 

Example 1.7.2. Another example:

SolxRule = DSolve[x y'[x] - 5 y[x] == 27 x^7 * Exp[x], y[x], x]
y3[x_] = Simplify[y[x]/.SolxRule[[1]]]

Out[11]= x^5 (27 E^x (-1 + x) + C[1])

Checking:
Simplify[x y3'[x] -5 y3[x] == 27 x^7 * Exp[x]]

Example 1.7.3. Example: 3ty' +2y=t^2 , y(1)=1

 

Example 1.7.4. Example:
Clear[x,y,gensol] (* clear all variables *)
gensol=DSolve[y'[x]==Exp[-2 x]-3 y[x],y[x],x]
Out[11]= {{y[x] -> E^(-2 x) + E^(-3 x) C[1]}}
gensol[[1,1,2]]
Out[12]= E^(-2 x) + E^(-3 x) C[1]

 


To solve the Bernoulli equation x' +px=qy^n , we use substitution

y=x^(1-n)
L[x_] := D[x, t] + p*x - q*x^n;
x = y[t]^(1/(1 - n));
a2 = Simplify[L[x]];
a3 = a2/y[t]^(n/(1 - n));
Simplify[PowerExpand[a3]]
Out[36]= ConditionalExpression[
8^(n/(1 - n)) t^((2 n)/(3 - 3 n)) (7 + t^(8/3))^(
n/(-1 + n)) (p (7/(8 t^(2/3)) + t^2/8)^(1/(1 - n)) -
q (7/(8 t^(2/3)) + t^2/8)^(n/(1 - n)) - (
2 (7/(8 t^(2/3)) + t^2/8)^(1/(1 - n)) (-7 + 3 t^(8/3)))/(
3 (-1 + n) t (7 + t^(8/3)))), (Re[t] >= 0 ||
t \[NotElement] Reals) && (Re[u] >= 0 || u \[NotElement] Reals)]

Give codes using the Bernoulli method: x=u*v, where u' +p*u=0 and v is the solution of the separable equation uv' =(u*v)^n

Example 1.7.?.
The four streamlines (corresponding to the values of an arbitrary constant C=1,2,3,4) from the general solution y=1/(x Sqrt[C-2 ln[x]]) of the Bernoulli equation
x y' =x^2 y^3 -y can be plotted with one command:
Plot[-1/(x Sqrt[#1 - 2 Log[x]] &) /@ {1, 2, 3, 4}, {x, .3, 10} ]
>>>> bernoulli1.jpg

Example 1.7.?. Example
y y' =y^2 +e^x
The general solution: y=\pm Sqrt[c e^(2x)-2 e^x] , where c is an arbitrary constant.

 

Example 1.7.?. Example
y' +xy=x y^4

 

1.8. Riccati Equations


Example
Consider the Riccati equation

y' = 2y/x+y^2 -x^4 .

It can be solved by substitution y =x^2 +1/v(x) , where y1=x^2 is a particular solution of the given RIccati equation.

Example Clairaut Equation
y=xy' + (y')^2
Clear[y];
y[x_] = x c + c^2

 

To find the singular solution (envelope), we type:
f[t_] = t^2;
Eliminate[{x==-f'[t],y==f[t]-t*f'[t]},t]
Out[37]= -4y==x^2




1.9. Existence and Uniqueness


1.10. Qualitative Analysis


1.11. Applications


Example 1.11.1. (Orthogonal trajectories)
Given the family of curves x*y=c, where c is a constant. These are
hyperbolas in quadrants 1 and 3 for c>0 or quadrants 2 and 4 for c<0,
having the axes as asymptotes. They are rectengular hyperbolas
because their asymptotes are perpendicular. The differential equation
of the family is x y' + y =0, or dy/dx = -y/x . The orthogonality
condition says that the equation of the orthogonal curves should be -
dx/dy = -y/x or dy/dx = y/x . The latter has the general solution
(after separation of variables): y^2 = x^2 +c. Now we plot these
curves.



Example 2: ????
The differential equation Exp[y] dy = Sin[x] dx defines its
family of solutions: Exp[y] == Sin {x] +c .
The orthiogonal trajectories are ln | Tan[x/2] = Exp[y] +c.

a := ContourPlot[{Exp[y] + Cos[x] == 3, Exp[y] + Cos[x] == 0.2,
Exp[y] + Cos[x] == 2, Exp[y] + Cos[x] == 0.5,
Cos[x] + Exp[y] == 1.5, Cos[x] + Exp[ y] == -2,
Cos[x] + Exp[y] == -0.2, Cos[x] + Exp[ y] == -0.5,
Cos[x] + Exp[y] == -1.5}, {x, -2, 2}, {y, -2, 2}]

b := ContourPlot[{Log[Tan[x]] == Exp[-y] + 1,
Log[Tan[x]] == Exp[-y] + 0.1, Log[Tan[x]] == Exp[-y] + 0.9,
Log[Tan[x]] == Exp[-y] - 1, xLog[Tan[x]] == Exp[-y] - 0.1,
Log[Tan[x]] == Exp[-y] - 3.9}, {x, -2, 2}, {y, -2, 2}]

Show[a, b]
>>>>> ortho2.jpg

 

 

 

 

 

 

 

 

 

 

Some parts of the syntax of the code may be confusing, so that will be explained here. You may wonder why the variable x[k] and y[k] are used instead of x(k) and y(k). The reason is because the brackets [] resemble the denotation you see. Therefore, x[k] and y[k] in actual form would be xk and yk respectively. The parenthesis, on the other hand, would resemble the independent variable relevant to the dependent variable in the parenthesis.

 

 

 

 

 

7. References