Example 1:
Let us start with a simple case of a constant coefficient linear differential equation when all manipulations become transparent. So we
consider the following initial value problem for a linear second order
differential equation
\begin{equation*} %\label{EqConv.1}
x''(t) + 2x'(t) - 3x(t) = 0, \qquad x(0) =3, \quad x' (0) =-1.
\tag{1.1}
\end{equation*}
This is a homogeneous, linear, second-order ODE with constant coefficients. As
a brief refresher from the previous
course, recall that its solution can be computed by finding the
roots of the corresponding
characteristic equation:
\[
\lambda^2 + 2\,\lambda - 3 = 0.
\tag{1.2}
\]
There are two distinct, real roots to the quadratic (characteristic) equation:
λ
1 = 1 and λ
2 = -3, and the general
solution is a linear combination of two exponent functions:
\[
x(t) = c_{1}e^{\lambda_{1}t} + c_{2}e^{\lambda_{2}t} =
c_{1}e^{t} + c_{2}e^{-3t} ,
\]
where
c1 and
c2 are arbitrary constants.
To satisfy the initial conditions, we have to choose these constants so that
x(0) =
c1 +
c2 = 3 and
x'(0) =
c1 -3
c2 = -1. This yields
c1 = 2 and
c2 = 1; and the solution becomes
\begin{equation*} %\label{EqConv.2}
x(t) = 2\, e^t + e^{-3t} \qquad \Longrightarrow \qquad
x'(t) = 2\, e^t -3\, e^{-3t} .
\tag{1.3}
\end{equation*}
syms x(t) t
% derivative
Dx = diff(x);
eqn = diff(x, t, 2) == - 2*Dx + 3*x;
cond1 = x(0) == 3;
cond2 = Dx(0) == -1;
conds = [cond1 cond2];
soln(t) = dsolve(eqn, conds)
soln = simplify(soln)
end
Now we convert the given problem to a vector equation by letting
x1 =
x and its first derivative we denote by
x2. Note that second derivative is known from the given equation
\( x'' = 3\,x(t) - 2\, x' (t) = 3\, x_1 - 2\, x_2
. \) This leads to the system of first order differential
equations
\[
\begin{split}
x'_1 &= x_2 = x', \\
x'_2 &= x'' = -2\, x_2 + 3\,x_1 .
\end{split}
\]
Upon introducing a column vector
x = [
x1,
x2]
T (here "T" stands for
transposition; see first chapter of this
tutorial), we can rewrite the system of ODEs in more appropriate vector form:
\begin{equation*} %\label{EqConv.3}
\frac{\text d}{{\text d}t} \begin{bmatrix} x_1 (t) \\ x_2 (t) \end{bmatrix} =
\begin{bmatrix} 0& \phantom{-}1 \\ 3 & -2 \end{bmatrix}
\begin{bmatrix} x_1 (t) \\ x_2 (t) \end{bmatrix} , \qquad
\begin{bmatrix} x_1 (0) \\ x_2 (0) \end{bmatrix} =
\begin{bmatrix} \phantom{-}3 \\ -1 \end{bmatrix} .
\tag{1.4}
\end{equation*}
syms x1(t) x2(t)
eqn1 = diff(x1, t) == x2;
eqn2 = diff(x2, t) == -2*x2 + 3*x1;
eqns = [eqn1, eqn2];
cond1 = x1(0) == 3;
cond2 = x2(0) == -1;
conds = [cond1 cond2];
[soln1(t), soln2(t)] = dsolve(eqns, conds);
soln = [soln1(t), soln2(t)];
soln = simplify(soln)
With matrix notation,
\[
{\bf x} (t) = \begin{bmatrix} x_1 (t) \\ x_2 (t) \end{bmatrix} , \qquad {\bf A} = \begin{bmatrix} 0& \phantom{-}1 \\ 3 & -2 \end{bmatrix} , \qquad {\bf x}_0 = \begin{bmatrix} \phantom{-}3 \\ -1 \end{bmatrix} ,
\]
we rewrite the system of ODEs and corresponding initial conditions in a more appropriate vector form:
\[
\frac{\text d}{{\text d}t}\,{\bf x}(t) = {\bf A}\,{\bf x}(t) , \qquad {\bf x}(0) = {\bf x}_0 .
\]
In order to find the solution to this vector differential
equation, we first need to find the
eigenvalues of the corresponding matrix (which is called the
companion
matrix):
\[
\det \left( \lambda {\bf I} - {\bf A} \right) =0 \qquad \Longleftrightarrow
\qquad \det \left( \lambda \begin{bmatrix} 1&0 \\ 0&1 \end{bmatrix} -
\begin{bmatrix} 0&\phantom{-}1 \\ 3&-2 \end{bmatrix} \right) = \det
\begin{bmatrix} \lambda & -1 \\ -3& \lambda +2 \end{bmatrix} =
\lambda^2 + 2\,\lambda - 3 =0 ,
\]
where
I is the identity matrix.
From observation, the eigenvalues of matrix
A
are the same as the roots of the characteristic equation
λ² + 2 λ −3 = 0
for the given second order differential equation.
Sometimes, we need to monitor the residual of numerical calculations by
introducing an additional auxiliary variable y3 =
x'', the second derivative of the unknown solution
x(t), and keep other variables: y1 = x and
y2 = x'. Then its derivative, according to the given differential equation, will be:
\[
y'_3 = x''' = \frac{\text d}{{\text d}t} \left( x'' \right) = \frac{\text d}{{\text d}t} \left( -2\,y_2 + 3\, y_1 \right) = -2\,y'_2 + 3\, y'_1 = -2 \left( -2\, y_2 + 3\, y_1 \right) + 3\, y_2 = 7\, y_2 -6\, y_1 .
\]
This allows us to compose the system of three equations. There are two options to achieve it. First, we recall that the derivative of
y2 is our new dependent variable
y3. So we get
\begin{equation*}
%\begin{split}
\begin{cases}
y'_1 &= y_2 = x' , \\
y'_2 &= y_3 = x'' , \\
y'_3 &= -2\, y_3 +3 \, y_2 = x''' ;
\end{cases}
%\end{split}
\qquad\quad %\begin{split}
\begin{cases}
y_1 (0) &= 3 \\
y_2 (0) &= -1 \\
y_3 (0) &= 11 .
\end{cases} %\end{split}
\tag{1.5}
\end{equation*}
Therefore, we obtain a vector differential equation
\( \dot{\bf y} = {\bf C}\,{\bf y}(t) \) that is equivalent (we hope?) to the the original IVP (1.1)
\[
\frac{\text d}{{\text d}t} \begin{bmatrix} y_1 (t) \\ y_2 (t) \\ y_3 (t) \end{bmatrix} = \begin{bmatrix} 0&1&\phantom{-}0 \\ 0&0&\phantom{-}1 \\ 0&3&-2 \end{bmatrix} \begin{bmatrix} y_1 (t) \\ y_2 (t) \\ y_3 (t) \end{bmatrix} , \qquad \begin{bmatrix} y_1 (0) \\ y_2 (0) \\ y_3 (0) \end{bmatrix} =\begin{bmatrix} \phantom{1}3 \\ -1 \\ 11 \end{bmatrix} , \qquad\mbox{with}\quad {\bf C} = \begin{bmatrix} 0&1&\phantom{-}0 \\ 0&0&\phantom{-}1 \\ 0&3&-2 \end{bmatrix} .
\]
The initial condition for this function also follows from the given
differential equation (1.1):
\[
y_3 = x'' = 3\, x(t) - 2\, x' (t) \qquad \Longrightarrow \qquad
y_3 (0) = 3\,x(0) -2\, x' (0) = 3\cdot 3 -2 \cdot (-1) = 11 .
\]
Note that the derivative of
y3 is expressed through the
original function
x(
t) as
\( y'_3 = 7\, y_2 -6\, y_1 . \) So another option is to rewrite the given system of ODEs as
\begin{equation*} %\label{EqConv.4}
%\begin{split}
\begin{cases}
y'_1 &= y_2 = x' , \\
y'_2 &= y_3 = x'' , \\
y'_3 &= -6\, y_1 +7\, y_2 = x''' ;
\end{cases}
%\end{split}
\qquad\quad %\begin{split}
\begin{cases}
y_1 (0) &= 3 \\
y_2 (0) &= -1 \\
y_3 (0) &= 11 .
\end{cases} %\end{split}
\tag{1.6}
\end{equation*}
In vector form, it becomes:
\[
\frac{\text d}{{\text d}t} \begin{bmatrix} y_1 (t) \\ y_2 (t) \\ y_3 (t) \end{bmatrix} = \begin{bmatrix} \phantom{-}0&1&0 \\ \phantom{-}0&0&1 \\ -6&7&0 \end{bmatrix} \begin{bmatrix} y_1 (t) \\ y_2 (t) \\ y_3 (t) \end{bmatrix} , \qquad \begin{bmatrix} y_1 (0) \\ y_2 (0) \\ y_3 (0) \end{bmatrix} =\begin{bmatrix} \phantom{1}3 \\ -1 \\ 11 \end{bmatrix} , \qquad\mbox{with}\quad {\bf B} = \begin{bmatrix} \phantom{-}0&1&0 \\ \phantom{-}0&0&1 \\ -6&7&0 \end{bmatrix} .
\]
DSolve[{y1'[t] == y2[t], y2'[t] == -2*y2[t] + 3*y1[t],
y3'[t] == 7*y2[t] - 6*y1[t], y1[0] == 3, y2[0] == -1,
y3[0] == 11}, {y1[t], y2[t], y3[t]}, t]
{{y1[t] -> E^(-3 t) (1 + 2 E^(4 t)),
y2[t] -> E^(-3 t) (-3 + 2 E^(4 t)),
y3[t] -> E^(-3 t) (9 + 2 E^(4 t))}}
syms y1(t) y2(t) y3(t)
eqn1 = diff(y1, t) == y2;
eqn2 = diff(y2, t) == -2*y2 + 3*y1;
eqn3 = diff(y3, t) == 7*y2 - 6*y1;
eqns = [eqn1, eqn2, eqn3];
cond1 = y1(0) == 3;
cond2 = y2(0) == -1;
cond3 = y3(0) == 11;
conds = [cond1 cond2 cond3];
[soln1(t), soln2(t), soln3(t)] = dsolve(eqns, conds);
soln = [soln1(t), soln2(t), soln3(t)];
soln = simplify(soln)
Despite that the first two components (
y1 and
y2) of the solution to the initial value problem (1.6) are the same as (1.3),
\[
\begin{bmatrix} y_1 (t) \\ y_2 (t) \\ y_3 (t) \end{bmatrix} = \begin{bmatrix} e^{-3t} + 2\,e^{t} \\ -3\,e^{-3t} + 2\,e^{t} \\ 9\,e^{-3t} + 2\,e^{t} \end{bmatrix} ,
\]
the system of differential equations (1.6) is
not equivalent to (1.1) because the corresponding matrix
B has three eigenvalues {−3, 2, 1}. Recall that matrix
A has two eigenvalues {−3, 1}. It becomes clear when we rewrite the system of three equations with matrix
B in the following form with Euler's notation
\( \texttt{D} = {\text d}/{\text d}t \) for derivative operator:
\[
\begin{split}
\texttt{D} y_1 &= y_2 , \\
\texttt{D} y_2 &= y_3 , \\
\texttt{D} y_3 &= -6\,y_1 + 7\,y_2 .
\end{split}
\]
The system above contains three unbounded derivative operators, but the original differential equation (1.1) is of order two. So its general solution is
\[
y_1 (t) = x(t) = C_1 e^t + C_2 e^{-3t} + C_3 e^{2t} ,
\]
with some arbitrary constants
C1,
C2, and
C3.
Upon using the appropriate initial conditions we eliminated unwanted additional constant
C3 from its general solution. So we obtain the same solution from the system of three equations as the original IVP, at least from theoretical point of view. However, matrix
B has a dominant eigenvalue λ = 2>1 and the corresponding numerical algorithm should avoid it.
Then the difference of y3 and \(
3\, x(t) - 2\,x' (t) = 3\,y_1 - 2\, y_2 \) gives the residual (error)
of calculations.
We use the standard Mathematica command NDSolve to solve numerically the system of three equations (1.6) and plot the residual of calculations for the equation. Blue curve gives the error with the true second derivative, and the red curve gives the residual based on numerical calculation.
sol3 = NDSolve[{y1'[t] == y2[t], y2'[t] == y3[t],
y3'[t] == -6*y1[t] + 7*y2[t], y1[0] == 3, y2[0] == -1,
y3[0] == 11}, {y1, y2, y3}, {t, 0, 3}];;
sol2 = NDSolve[{x1'[t] == x2[t], x2'[t] == 3*x1[t] - 2*x2[t],
x1[0] == 3, x2[0] == -1}, {x1, x2}, {t, 0, 3}];
a1 = Plot[
Evaluate[y3[t] /. sol3] + Evaluate[(2*x2[t] - 3*x1[t]) /. sol2], {t,
0, 1}, PlotTheme -> "Web"]
a2 = Plot[9 E^(-3 t) + 2 E^t - Evaluate[(y3[t]) /. sol3], {t, 0, 1},
PlotTheme -> "Business"]
|
 
|
|
Figure 1. Residuals of the second derivative: the error between the second derivative y3(t) and the true value in blue.
|
|
Figure 2. The residual of the second derivative y3(t) = d²x/dt² and the numerical solution 3x2(t) - 2x1(t).
|
Adjust coefficients:
odefcn2 = @(t,y)[y(2);y(3);((31/4)*y(2)) - ((15/4)*y(1))];
y0 = [ 3; -2 ; 9.5];
t = [0,3] ;
sol = ode45(odefcn2, t , y0);
plot(sol.x,((2*sol.y(3,:))-(5*sol.y(2,:))+(3*sol.y(1,:))))
Note that introducing the system of three equations with artificial differentiation does not provide an equivalent system for the given equation because the derivative operator is unbounded.
The transformation to a system of first order ODEs is straight forward,
but it is not unique. Let us try another set of new dependent variables:
\[
z_1 = x, \quad z_2 = \dot{x} - x \qquad\Longrightarrow \qquad \dot{z}_2 =
\ddot{x} - \dot{x} = -3 \left( \dot{x} - x \right) .
\]
This leads to the system of first order differential equations:
\[
\begin{split}
\dot{z}_1 &= z_1 + z_2 \qquad \Longleftrightarrow \qquad \dot{x} = \dot{x} , \\
\dot{z}_2 &= -3\, z_2 .
\end{split}
\]
We can also rewrite the above system in vector form
\[
\frac{\text d}{{\text d}t} \begin{bmatrix} z_1 (t) \\ z_2 (t) \end{bmatrix} =
\begin{bmatrix} 1& 1 \\ 0 & -3 \end{bmatrix}
\begin{bmatrix} z_1 (t) \\ z_2 (t) \end{bmatrix} , \qquad
\begin{bmatrix} z_1 (0) \\ z_2 (0) \end{bmatrix} =
\begin{bmatrix} 3 \\ -4 \end{bmatrix} ,
\]
because
\( z_2 (0) = \dot{x}(0) - x(0) = -1 -3 =-4 . \)
The characteristic polynomial for the corresponding matrix is
\[
\det \left( \lambda \begin{bmatrix} 1&0 \\ 0&1 \end{bmatrix} -
\begin{bmatrix} 1&1 \\ 0&-3 \end{bmatrix} \right) = \det
\begin{bmatrix} \lambda -1& -1 \\ 0& \lambda +3 \end{bmatrix} =
\lambda^2 + 2\,\lambda - 3 =0 .
\]
■