You are on page 1of 18

77

Simpozionul Tehnologii educaionale pe platforme electronice n nvmntul ingineresc,


8 - 9 mai 2009, Universitatea Tehnic de Construcii Bucureti,
Symposium Educational Technologies on Electronic Platforms in Engineering Higher Education
May 8 9, 2009, Technical University of Civil Engineering of Bucharest
LINEAR DIFFERENTIAL EQUATIONS WITH MATHCAD
NICOLAE DNE
Technical University of Civil Engineering of Bucharest
Department of Mathematics and Computer Science
124, Lacul Tei Blvd., Bucharest, Romania
E-mail: ndanet@cfdp.utcb.ro
Abstract. The paper shows how Mathcad software can be used for solving linear differential
equations symbolically and numerically.
Keywords: Ordinary differential equations, linear differential equations, Cauchy problem, initial
value problem, boundary value problem, Mathcad.
1. INTRODUCTION
Unlike other mathematical software like Maple, Mathematica and Mupad, Mathcad
does not have special functions to solve an ordinary differential equation (ODE for
short) symbolically. This does not mean that Mathcad cannot be used to solve ODEs.
In fact, Mathcad has an internal function called odesolve for solving ODEs, but this
function only works numerically.
If one wants to obtain a symbolic solution for an ODE with Mathcad, then they
must write their own Mathcad file for solving that type of ODE. Doing this work they
can understand better the method of solving instead of using a black box like in
other software.
In this paper we show how Mathcad can be used for solving linear differential
equations symbolically and numerically. Section 2 is devoted to linear differential
equations with constant coefficients. In Subsection 2.1, after we recall the algorithm
for determining the general solution of the homogeneous equation, we present a
Mathcad file which solves such an equation symbolically along with a given Cauchy
problem. In Subsection 2.2 we recall the method of variation of parameters for
determining a particular solution for the nonhomogeneous equation and present an
example in Mathcad. In Section 3 we show how the Mathcad function odesolve can
be used to solve numerically nonhomogeneous linear differential equations with
variable coefficients. Finally, an example of solving a system of linear differential
equations with odesolve is presented.
2. LINEAR DIFFERENTIAL EQUATIONS WITH CONSTANT COEFFICIENTS
An n th order linear differential equation is an equation linear in the unknown
function y and its derivatives
) (
, , ' ' , '
n
y y y K and, hence, of the form
78
) ( ) ( ' ) ( ) ( ) (
1
) 1 (
1
) (
0
x f y x a y x a y x a y x a
n n
n n
= + + + +

L . (1)
We assume that the functions
n
a a a , . ,
1 0
K and f are continuous real-valued
functions on some open interval ) , ( b a I = (the cases = a , or = b , or both,
are included), and that
0
a is nowhere zero in this interval. By dividing by
0
a we can
always assume that the equation has the canonical form
) ( ) ( ' ) ( ) (
1
) 1 (
1
) (
x f y x a y x a y x a y
n n
n n
= + + + +

L . (2)
We denote, as usually, by ) ( ) ( : I C I C L
n
the linear differential operator
defined by
y a y a y a y y L
n n
n n
+ + + + =

' ) (
1
) 1 (
1
) (
L . (3)
Then the equation (2) can be written in the abridged form
f y L = ) ( . (4)
If the right side 0 = f on I , then the equation is called homogeneous since it is
homogeneous in the unknown function y and its derivatives. For 0 f on I , the
equation is called nonhomogeneous.
2.1. Homogeneous Linear Equations with Constant Coefficients
In this section we recall the basic facts about the general solution of the
homogenous linear equation
0 ' ) (
1
) 1 (
1
) (
= + + + + =

y a y a y a y y L
n n
n n
L . (5)
If
n
y y y , , ,
2 1
K are n solutions of the equations (5), they are said to form a
fundamental set of solutions for the homogeneous linear equation (5) if they are
linearly independent on the interval I . It is well known that the functions
) ( , , ,
2 1
I C y y y
n
n
K form a fundamental set of solutions for the equation (5) if and
only if the determinant
) ( ) ( ) (
) ( ) ( ) (
) ( ) ( ) (
) )( , , , (
) 1 ( ) 1 (
2
) 1 (
1
2 1
2 1
2 1
x y x y x y
x y x y x y
x y x y x y
x y y y W
n
n
n n
n
n
n


=
L
M O M M
L
L
K , (6)
called the Wronskian of the solutions
n
y y y , , ,
2 1
K , is never zero on I .
The general solution of the homogeneous linear equation (5) is a linear
combination of a fundamental set of solution, that is
) ( ) ( ) ( ) (
2 2 1 1
x y C x y C x y C x y
n n
+ + + = L . (7)
For the equation (5) we seek solutions of the form
x
e y

= , where is a real or
complex number to be determined. Then it follows that
x
e y

= ' ,
x
e y

2
' ' = ,,
x n n
e y

=
) (
. By substituting these expressions in (5), we obtain
) ( ) ( ) (
1
1
1


P e a a a e e L
x
n n
n n x x
= + + + + =

L , (8)
for all , where
n n
n n
a a a P + + + + =


1
1
1
) ( L . (9)
79
The polynomial ) ( P is called the characteristic polynomial, and the equation
0 ) (
1
1
1
= + + + + =

n n
n n
a a a P L (10)
is called the characteristic equation of the differential equation (5).
The equality (8) shows that the function
x
e y

= is a solution of the differential
equation (5) if and only if 0 ) ( = P , that is, is a root of the characteristic equation.
2.1.1. Real and Distinct Roots
If all the roots
n
, , ,
2 1
K of the characteristic equation (10) are real and
distinct, that is, the characteristic polynomial ) ( P can be written in the form
) ( ) )( ( ) (
2 1 n
P = L ,
then we found n linearly independent solutions
x x x
n
e e e

, , ,
2 1
K of the equation
(5). Consequently,
x
n
x x
n
e C e C e C y

+ + + = L
2 1
2 1
,
(11)
where
i
C are arbitrary real constants, is the general solution of the equation (5).
2.1.2. Real and multiple Roots
If all the roots of the characteristic polynomial are real but there are multiple roots
among them, let us suppose that
m
, , ,
2 1
K are the distinct roots, where n m < ,
and that each root
i
has the multiplicity
i
k , m i , , 2 , 1 K = , with n k k
m
= + +L
1
.
Then the characteristic polynomial (9) has the form
. ) ( ) ( ) ( ) (
2 1
2 1
m
k
m
k k
P = L

In this case, to each root
i
of multiplicity
i
k , correspond
i
k solutions of the equation
(5):
x k x x
i i i i
e x xe e
1
, , ,

K .

All these solutions are linearly independent (see [2], p.102) and, consequently, the
general solution of equation (4) is of the form

+ + + =
m
i
x k
i k i i
i i
i
e x C x C C y
1
1
. 1 1 0
) (

L , (12)
where
i k i i
i
C C C
, 1 1 0
, , ,

K are arbitrary real constants.
2.1.3. Complex Roots
Since the coefficients of the characteristic polynomial (9) are real, the complex
roots of the characteristic equation appear only as conjugate pairs i =
2 , 1
.
The complex solutions
x i
e
) ( +
and
x i
e
) (
that correspond to these complex
roots can be replaced by two real solutions: the real and the imaginary part of one of
the solutions
) sin (cos
) (
x i x e e
x x i


+ =
+
, ) sin (cos
) (
x i x e e
x x i


=

.
80
Thus, to the pair of complex conjugate roots i =
2 , 1
there correspond two
real solutions of the equation (5):
x e
x

cos , x e
x

sin .
If the characteristic equation has a multiple complex root i + =
1
of
multiplicity k , the complex conjugate i =
2
is also a root with the same
multiplicity. The k complex solutions
x i k x i x i x i
e x e x xe e
) ( 1 ) ( 2 ) ( ) (
, , , ,
+ + + +
K
that correspond to one of them may be replaced with k 2 real-valued solutions, the
real and the imaginary parts of the above complex solutions:

x e x x xe x e
x e x x xe x e
x k x x
x k x x




sin , , sin , sin
cos , , cos , cos
1
1
K
K
(13)
Thus, to a pair of complex conjugate roots i =
2 , 1
of multiplicity k there
correspond k 2 linearly independent solutions (13) ([2], p.116). Hence, the general
solution of the equation (5) can always be expressed as a linear combination of n
real-valued solutions.
2.1.4. The Cauchy Problem
The Cauchy problem for the equation (5) means to find the solution of this
equation which satisfies the given initial conditions
) 1 (
0 0
) 1 (
0 0 0 0
) ( , , ' ) ( ' , ) (

= = =
n n
y x y y x y y x y L , (14)
where
0
x is any point in the interval I and
) 1 (
0 0 0
, , ' ,
n
y y y L are n arbitrary real
numbers.
If we demand that the general solution (7) of the equation (5) satisfies the initial
conditions (14), then we obtain an algebraic system of n linear equations

= + + +
= + + +
= + + +

, ) ( ) ( ) (
, ) ( ' ) ( ' ) ( '
, ) ( ) ( ) (
0 0
) 1 (
0
) 1 (
2 2 0
) 1 (
1 1
0 0 0 2 2 0 1 1
0 0 0 2 2 0 1 1
y x y C x y C x y C
y x y C x y C x y C
y x y C x y C x y C
n
n n
n n
n n
n n
L
L L L L M L L L L L L L L L L L L L L L
L
L
(15)
with n unknowns
n
C C C , , ,
2 1
K , and with a nonzero determinant, since the
determinant of this system is the Wronskian of a fundamental set of solutions of
equation (5). Thus, this system is solvable for
i
C , for any given point
0
x in the
interval I and for any kinds of right members.
2.1.5. Symbolic Solution with Mathcad
In this subsection we present a Mathcad file which determines the general solution
of a homogeneous linear differential equation with constant coefficients and solves
an associated Cauchy problem.
The presentation used the following conventions:
a) The paragraphs of text correspond to the text regions in Mathcad.
81
b) The yellow zones correspond to math regions in Mathcad used to write a
mathematical expression in order to make the text more clear. The equal sign
used in these expressions is the Boolean equal (CTRL + =).
c) The light blue zones indicate that the content of that math region did not
change automatically when the initial equation is changed and that these
changes must be made manually.

Example 2.1. a) Find the general solution of the following differential equation
y
4 ( )
y
3 ( )
+ 7 y'' y' 6 y + 0
(16)
b) Given the initial conditions
1 ) 0 ( ' ' ' , 2 ) 0 ( ' ' , 0 ) 0 ( ' , 1 ) 0 ( = = = = y y y y
(17)
find the particular solution of the equation (16) which satisfies these conditions.
First we define the equations order, n , and the vector of the coefficients of the
equation denoted by a. This vector has the length 1 + n and the first component
must be the coefficient of the unknown function y .
n 4 := a 6 1 7 1 1 ( )
T
:=
The characteristic equation is:
P
( )
0
n
j
a
j

j

=
6 7
2

3
+
4
+ :=
The roots of the characteristic equation are the components of the vector r
obtained as follows:
r P
( )
solve ,
1
2
3
1

:=
Now we compute the multiplicity of each root. In the same time we obtain the
exponents for the powers of x which appear in the fundamental set of solutions.
k i r , ( ) k 0
j 0
k k 1 + r
j
r
i
0 if
j j 1 +
j i while
k return
:=

i 0 n 1 .. :=

i
0
1
2
3
= r
i
1
2
-3
-1
= k i r , ( )
1
1
1
1
=
We define a fundamental set of solutions.
82
y x ( )
y
i
x
k i r , ( ) 1
e
Re r
i
( ) x
sin Imr
i
( ) x ( ) Imr
i
( ) 0 > if
y
i
x
k i r , ( ) 1
e
Re r
i
( ) x
cos Imr
i
( ) x ( ) Imr
i
( ) 0 < if
y
i
x
k i r , ( ) 1
e
r
i
x
Imr
i
( ) 0 if
i 0 n 1 .. for
y
:=

This set is:
y x ( )
exp x ( )
exp 2 x ( )
exp 3 x ( )
exp x ( )



The general solution of the equation is a linear combination of the above
fundamental set of solutions
Y x C , ( )
0
n 1
i
C
i 1 +
y x ( )
i

=
:=
That is
Y x C , ( ) C
1
exp x ( ) C
2
exp 2 x ( ) + C
3
exp 3 x ( ) + C
4
exp x ( ) +
(18)

Now we want to find the particular solution ) (x yp of the equation which at the
point
x0 0 :=
satisfies the initial conditions
yp x0 ( ) y0

yp' x0 ( ) y'0

yp'' x0 ( ) y''0

yp''' x0 ( ) y'''0
where
y0 1 :=

y'0 0 :=

y''0 2 :=

y'''0 1 :=
We introduce these conditions in a vector denoted ic, from initial conditions.
ic
y0
y'0
y''0
y'''0

:=

ic
1
0
2
1

=
The Wronski matrix corresponding to the fundamental set of solutions is
MW x ( )
y
1
x ( )
y
1
' x ( )
y
1
'' x ( )
y
1
''' x ( )
y
2
x ( )
y
2
' x ( )
y
2
'' x ( )
y
2
''' x ( )
y
3
x ( )
y
3
' x ( )
y
3
'' x ( )
y
3
''' x ( )
y
4
x ( )
y
4
' x ( )
y
4
'' x ( )
y
4
''' x ( )


To obtain this matrix we define the fundamental set of solutions and its derivatives:
83
y x ( )
exp x ( )
exp 2 x ( )
exp 3 x ( )
exp x ( )

:=
y' x ( )
y'
j
1
x
y x ( )
j
d
d
1

j 0 n 1 .. for
y'
:=
y'' x ( )
y''
j
2
x
y x ( )
j
d
d
2

j 0 n 1 .. for
y''
:= y''' x ( )
y'''
j
3
x
y x ( )
j
d
d
3

j 0 n 1 .. for
y'''
:=
Then the Wronski matrix is
MW x ( ) augment y x ( ) y' x ( ) , y'' x ( ) , y''' x ( ) , ( )
T
:=
MW x ( )
exp x ( )
exp x ( )
exp x ( )
exp x ( )
exp 2 x ( )
2 exp 2 x ( )
4 exp 2 x ( )
8 exp 2 x ( )
exp 3 x ( )
3 exp 3 x ( )
9 exp 3 x ( )
27 exp 3 x ( )
exp x ( )
exp x ( )
exp x ( )
exp x ( )



The determinant of this matrix is called the Wronskian of the fundamental set of
solutions and is denoted by ) (x W .
W x ( ) MW x ( ) :=
The value of this determinant at any point is nonzero
W x ( ) simplify 240 exp x ( )
In the given point x0, the Wronskian is
MW 0 ( )
1
1
1
1
1
2
4
8
1
3
9
27
1
1
1
1


and it has the value
W x0 ( ) 240
The constants
4 3 2 1
, , , C C C C , for which the general solution (18) satisfies the
given initial conditions (17), are obtained from the linear system

MW 0 ( )
C
1
C
2
C
3
C
4

ic
C
1
C
2
+ C
3
+ C
4
+
C
1
2 C
2
3 C
3
C
4
+
C
1
4 C
2
+ 9 C
3
+ C
4
+
C
1
8 C
2
27 C
3
C
4
+

1
0
2
1



This system is solved using Mathcad function lsolve.
C lsolveMW x0 ( ) ic , ( ) :=
The solution is:
84
C
T
11
8
2
3
1
8
5
12


Now we define the particular solution which satisfies the initial conditions (17).
yp x ( )
0
n 1
i
C
i
y x ( )
i

=
:=
This solution is:
yp x ( )
11
8
exp x ( )
2
3
exp 2 x ( )
1
8
exp 3 x ( )
5
12
exp x ( ) +
Finally, we plot this solution (see Figure 1).

0 0.5 1 1.5
3
2
1
1
2
3
yp x ( )
x

FIGURE 1. The particular solution which satisfies the Cauchy problem in Example 2.1.

2.2. Nonhomogeneous Linear Equations with Constant Coefficients
Now we consider the nonhomogeneous equation (4):
) ( ' ) (
1
) 1 (
1
) (
x f y a y a y a y y L
n n
n n
= + + + + =

L (19)
If
1
y and
2
y are any two solutions of this equation, then it follows from the linearity
of the operator L that
0 ) ( ) ( ) )( ( ) )( ( ) ))( ( ) ( (
2 1 2 1
= = = x f x f x y L x y L x y L y L .
Hence the difference of any two solutions of the nonhomogeneous equation (3) is a
solution of the homogeneous equation (5). Since any solution of the homogeneous
equation is a linear combination of a fundamental set of solutions
n
y y y , , ,
2 1
K , it
follows that any solution of equation (19) can be written as
) ( ) ( ) ( ) ( ) (
2 2 1 1
x y x y C x y C x y C x y
p n n
+ + + + = L ,
(20)
where
p
y is some particular solution of the nonhomogeneous equation (19). The
linear combination (20) is called the general solution of the nonhomogeneous
equation (19).
2.2.1. The Method of Variation of Parameters
A particular solution
p
y of the nonhomogeneous equation (19) can be obtained by
the method of variation of parameters. Suppose that we know a fundamental set of
85
solutions
n
y y y , , ,
2 1
K of the homogeneous equation (5). Then the general solution
of the homogeneous equation is

) ( ) ( ) ( ) (
2 2 1 1 0
x y C x y C x y C x y
n n
+ + + = L . (21)

In applying the method of variation of parameters, we seek a particular solution of the
nonhomogeneous equation (19) of the form

) ( ) ( ) ( ) ( ) ( ) ( ) (
2 2 1 1
x y x C x y x C x y x C x y
n n p
+ + + = L ,
(22)

that is, in place of the constants
n
C C C , , ,
2 1
K we introduce n unknown functions
) ( , ), ( ), (
2 1
x C x C x C
n
K . In order to obtain these functions we must first solve a
linear algebraic system for the unknown derivatives ) ( , ), ( ), (
2 1
x C x C x C
n
K :

= + + +
= + + +
= + + +

). ( ) ( ) ( ) ( ) ( ) ( ) (
, 0 ) ( ) ( ) ( ) ( ) ( ) (
, 0 ) ( ) ( ) ( ) ( ) ( ) (
) 1 ( ) 1 (
2 2
) 1 (
1 1
2 2 1 1
2 2 1 1
x f x y x C x y x C x y x C
x y x C x y x C x y x C
x y x C x y x C x y x C
n
n n
n n
n n
n n
L
L L L L L L L L L L L L L L L L L L L L L L
L
L
(23)

The determinant of this system is precisely the Wronskian (6) of the fundamental set
of solutions
n
y y y , , ,
2 1
K of the corresponding homogeneous equation (5), and this
determinant is nonzero for each value of x . Hence it is possible to determine the
functions ) ( , ), ( ), (
2 1
x C x C x C
n
K . Then, by integrating, we find
, , , 2 , 1 , ) ( ) ( n i C dx x C x C
i i i
K = + =

(24)
where
i
C are the new constants of integration.
2.2.2. Symbolic Solution with Mathcad
In this subsection we present a Mathcad file which solves symbolically a
nonhomogeneous linear differential equation with constant coefficients.

Example 2.2. Find the general solution of the differential equation
y'' x ( ) y x ( ) +
1
cos x ( )

(25)

First step. We solve the homogeneous equation
y'' x ( ) y x ( ) + 0 (26)
using the algorithm presented in subsection 2.1.4.
n 2 := a 1 0 1 ( )
T
:=

P
( )
0
n
j
a
j

j

=
1
2
+ :=

r P
( )
solve ,
i
i

:=
86
k i r , ( ) k 0
j 0
k k 1 + r
j
r
i
0 if
j j 1 +
j i while
k return
:=
i 0 n 1 .. := i
0
1
= r
i
i
-i
= k i r , ( )
1
1
=
y x ( )
y
i
x
k i r , ( ) 1
e
Re r
i
( ) x
sin Imr
i
( ) x ( ) Imr
i
( ) 0 > if
y
i
x
k i r , ( ) 1
e
Re r
i
( ) x
cos Imr
i
( ) x ( ) Imr
i
( ) 0 < if
y
i
x
k i r , ( ) 1
e
r
i
x
Imr
i
( ) 0 if
i 0 n 1 .. for
y
:=

For this equation the fundamental set of solutions is:

y x ( )
sin x ( )
cos x ( )



Then, the general solution of the homogeneous linear equation (26) is:
y0x C , ( )
0
n 1
i
C
i 1 +
y x ( )
i

=
:=
y0x C , ( ) C
1
sin x ( ) C
2
cos x ( ) +

(27)

Second step. Now we determine a particular solution of the nonhomogeneous
equation (25) using the method of variation of parameters.
The right-hand site of the equation is:
f x ( )
1
cos x ( )
:=

Wronskis matrix which corresponds to a fundamental set of solutions formed by the
two functions
2 1
, y y is:

MW x ( )
y
1
x ( )
y
1
' x ( )
y
2
x ( )
y
2
' x ( )



To obtain this matrix we define the fundamental set of solutions and its derivatives.
87

y x ( )
sin x ( )
cos x ( )

:=
y' x ( )
y'
j
1
x
y x ( )
j
d
d
1

j 0 n 1 .. for
y'
:=
The matrix and its determinant are:
MW x ( ) augment y x ( ) y' x ( ) , ( )
T
:=
MW x ( )
sin x ( )
cos x ( )
cos x ( )
sin x ( )


W x ( ) MW x ( ) :=

W x ( ) simplify 1


The particular solution of the nonhomogeneous equation (25) is sought under the
form
yp x ( ) C1 x ( ) y x ( )
0
C2 x ( ) y x ( )
1
+
The derivatives of the functions C1(x) and C2(x) are obtained from the linear
algebraic system

C1' x ( ) y x ( )
0
C2' x ( ) y x ( )
1
+ 0,

C1' x ( ) y' x ( )
0
C2' x ( ) y' x ( )
1
+ f x ( )

We resolve this system using Cramer rule and symbolic computation in Mathcad. We
have:
C1' x ( )
0
f x ( )
y x ( )
1
y' x ( )
1

W x ( )
simplify 1 :=
and
C2' x ( )
y x ( )
0
y' x ( )
0
0
f x ( )

W x ( )
simplify
sin x ( )
cos x ( )
:=

By integrating these derivatives we obtain the desired functions C1(x) and C2(x).
C1 x ( ) x C1' x ( )

d x := C2 x ( ) x C2' x ( )

d ln cos x ( ) ( ) :=
Now we can define the particular solution of the nonhomogeneous equation:

yp x ( ) C1 x ( ) y x ( )
0
C2 x ( ) y x ( )
1
+ :=
This solution is:
yp x ( ) x sin x ( ) ln cos x ( ) ( ) cos x ( ) + (28)

Then the general solution of the nonhomogeneous equation (25) is the sum of the
general solution (27) of the corresponding homogeneous equation (26) and the
particular solution (28) of the nonhomogeneous equation (25):
Y x C , ( ) y0x C , ( ) yp x ( ) + := .
Hence, we have
Y x C , ( ) C
1
sin x ( ) C
2
cos x ( ) + x sin x ( ) + ln cos x ( ) ( ) cos x ( ) +
(29)
88
Third step. We now solve the following Cauchy problem: given the point
x0

4
:=
find the particular solution of the equation (25) which satisfies the initial conditions
yp x0 ( ) y0

yp' x0 ( ) y'0
where
y0
2
16
:=

y'0
2
16
:= (30)
We define the initial conditions in a vector denoted by ic:
ic
y0
y'0

:= ic
1
16
2
1
2

1
16
2
1
2

0.278
0.278

=
The particular solution (28) has the derivative
yp' x ( )
x
yp x ( )
d
d
:=

yp' x ( ) x cos x ( ) ln cos x ( ) ( ) sin x ( )

The values of the solution ) (x yp and its derivative ) ( ' x yp calculated at the given
point
0
x are defined in a vector denoted by b:
b
yp x0 ( )
yp' x0 ( )

:= b
1
8
2
1
2

1
2
ln
1
2
2
1
2

2
1
2
+
1
8
2
1
2

1
2
ln
1
2
2
1
2

2
1
2

0.310
0.800

=
The constants
2 1
,C C are obtained from the algebraic linear system
MW x0 ( )
C
1
C
2

ic b
1
2
2
1
2
C
1

1
2
2
1
2
C
2
+
1
2
2
1
2
C
1

1
2
2
1
2
C
2

1
16
2
1
2

1
2
ln
1
2
2
1
2

2
1
2

1
16
2
1
2

1
2
ln
1
2
2
1
2

2
1
2
+


which has a non zero determinant
W x0 ( ) 1
The solution of this system is
C lsolveMW x0 ( ) ic b , ( ) :=
C
T
1
8
ln
1
2
2
1
2

0.393 0.347 ( ) =
89
Then, the particular solution of the equation (25) which satisfies the given initial
conditions (30) is:
ypc x ( )
0
n 1
i
C
i
y x ( )
i

=
yp x ( ) + :=
ypc x ( )
1
8
sin x ( ) ln
1
2
2
1
2

cos x ( ) x sin x ( ) + ln cos x ( ) ( ) cos x ( ) +


In order to avoid some mistakes in the above computations we check with
Mathcad if the obtained solution ) (x ypc satisfies the equation (25) and the initial
conditions (30).
2
x
ypc x ( )
d
d
2
ypc x ( ) + simplify
1
cos x ( )


ypc x0 ( )
1
16
2
1
2


ypc' x ( )
x
ypc x ( )
d
d
:=


ypc' x0 ( ) simplify
1
16
2
1
2

Now we plot this solution. First the graph is plotted on the interval [-10,10], which is
the default plot interval for X-Y Plot (see Figure 2).

10 8 6 4 2 0 2 4 6 8 10
10
8
6
4
2
2
4
6
8
10
ypc x ( )
x

FIGURE 2. The graph on the interval [-10,10 ] of the particular solution which
satisfies the Cauchy problem in Example 2.2.

The lack of the curve on some intervals is due to the fact that the solution exists
only on the intervals where 0 ) cos( > x .
The graph of this solution on the interval ) 2 / , 2 / ( , which contains the initial
point 4 /
0
= x , is shown in Figure 3.
90
1.57 0.79 0 0.79 1.57
0.5
1
1.5
2
2.5
3
ypc x ( )
x

FIGURE 3. The graph on the interval (-/2, /2) of the particular solution which
satisfies the Cauchy problem in Example 2.2.
3. LINEAR DIFFERENTIAL EQUATIONS WITH VARIABLE COEFFICIENTS
In this section we show how the Mathcad function odesolve can be used to obtain
a solution for a linear differential equation when its coefficients are functions and not
numbers, that is, if the equation has the form

) ( ) ( ' ) ( ) (
1
) 1 (
1
) (
x f y x a y x a y x a y
n n
n n
= + + + +

L . (31)

It is well known that in this case there is not a general theory for determining the
general solution for the homogeneous equation

. 0 ) ( ' ) ( ) (
1
) 1 (
1
) (
= + + + +

y x a y x a y x a y
n n
n n
L . (32)

But, if we know a fundamental set of solutions for the corresponding homogeneous
equation (32), then we can use the method of variation of parameters to solve the
nonhomogeneous equation (32) completely.
3.1. Solving Linear Differential Equations with Odesolve
Mathcad has the function odesolve(x,b,[step]) for solving an ordinary differential
equation. The Mathcad help [5] states: odesolve returns a function of x which is a
solution to the single ODE, subject to either initial value or boundary value constrains
provided in the solve block. The ODE must be linear in its highest derivatives and the
number of conditions must be equal to the order of the ODE. The variable b is the
terminal point of the integration interval and step (optional) is the number of steps
used for calculating the solution.
3.1.1. Solving an Initial Value Problem
In this subsection we present an example of how odesolve can be used to obtain
the solution of a linear differential equation with variable coefficients which satisfies
some given initial conditions.
91
Example 3.1. Find the solution of the equation
x
x y y x y x x
1
' ) 2 ( ' ' ) 1 ( + = + + + , (33)
which satisfies the initial conditions
2 / 5 ) 1 ( = y , 2 / 9 ) 1 ( ' = y .
(34)

In Mathcad we have the following four lines of code:

Given
x x 1 + ( ) y'' x ( ) x 2 + ( ) y' x ( ) + y x ( ) x
1
x
+
y 1 ( )
5
2

y' 1 ( )
9
2

y odesolve x 4 , 600 , ( ) :=

The equal sign in the Given block is the Boolean equal (CTRL + =). The differential
equation can be written using the Mathcad derivative operators
x
d
d

2
x
d
d
2

or using prime notation similar to ) ( ' x y . The keystroke for the prime character is
CTRL + F7.
Even if Mathcad computes ) (x y numerically, we can use the result like a true
function of variable x , for x between the initial value 1 = a and the final value
4 = b . This function has a derivative at every point in the interval [ ] b a, and can be
integrated on every subinterval [ ] [ ] b a d c , , . For example
y 3.5 ( ) 9.874 =

y' x ( )
x
y x ( )
d
d
:=

y' 3.5 ( ) 2.575 =

2
3
x y x ( )

d 7.252 =
Figure 4 shows the graph of the function ) (x y and its derivative ) ( ' x y .

1 2 3 4
5
10
15
y x ( )
y' x ( )
x

FIGURE 4. The graphs of the solution and its derivative obtained in Example 3.1.

The analytical solution of the equation (33) which satisfies the initial conditions (34)
is (see [4], Problem 702, p.58):
92
yex ( ) x 2 +
2
x

x
2
1 +

ln x ( ) +
3
2
+ :=
Then we can graphically compare the numeric solution ) (x y obtained using Mathcad
function odesolve and the exact solution ) (x ye . The Figure 5 shows that for this
equation the graphs of the two functions almost coincide.
1 1.5 2 2.5 3 3.5 4
5
10
15
y x ( )
ye x ( )
x x ,

FIGURE 5. The graph of the numerical solution obtained in Example 3.1 with odesolve
function and the graph of the exact solution.

3.1.2. Solving a Boundary Value Problem
This subsection contains an example of solving a boundary value problem using
odesolve.

Example 3.2. Find the solution of the differential equation
0
1
2
'
1
2
' '
2 2
=
+
+
+
y
x
y
x
x
y , (35)
which satisfies the boundary value conditions
1 ) 0 ( = y and 2 ) 1 ( = y . (36)
In Mathcad we have:

p x ( )
2 x
1 x
2
+
:=

q x ( )
2
1 x
2
+
:=

f x ( ) 0 :=
a 0 :=

b 1 :=

1 :=

2 :=

The Given block is:

Given
2
x
y x ( )
d
d
2
p x ( )
x
y x ( )
d
d
+ q x ( ) y x ( ) + f x ( )

y a ( )

y b ( )

y Odesolve x 1 , 100 , ( ) :=

The exact solution of the differential equation (35) with the boundary conditions
(36) is
s x ( ) x
2
2 x + 1 + :=
93
Figure 6 shows that the graphs of the function ) (x y obtained with odesolve and
the graph of ) (x s coincide on the interval [ ] 1 , 0 .
0 0.1 0.20.3 0.4 0.50.6 0.70.8 0.9 1
0
0.5
1
1.5
2
2.5
y x ( )
s x ( )
x x ,

FIGURE 6. The graph of the numerical solution obtained in Example 3.2 with odesolve
function and the graph of the exact solution.

3.2. Solving Systems of Linear Differential Equations with Odesolve
The Mathcad function odesolve can be used not only to solve differential
equations but also for systems of differential equations. The following example shows
how odesolve can be used to compute the solution of a system of two linear
differential equations.

Example 3.3. Find the solution of the nonhomogeneous linear system of
differential equations

+ =
+ =
, ) ( ) ( '
, 2 ) ( ) ( '
2
t t x t y
e t y t x
t
(37)
([4], Problem 826, p.73), which satisfies the initial conditions
. 1 ) 0 ( , 0 ) 0 ( = = y x
(38)
In Mathcad we have:

Given
t
x t ( )
d
d
y t ( ) 2 e
t
+
t
y t ( )
d
d
x t ( ) t
2
+
x 0 ( ) 0

y 0 ( ) 1
x
y

Odesolve
x
y

t , 2 , 200 ,

:=

The solution is computed on the interval [1, 2] divided in 200 subintervals. Figure 7
shows the graphs of the functions ) (t x and ) (t y which form the solution of this
system.
94
0 0.25 0.5 0.75 1 1.25 1.5 1.75 2
5
10
15
20
25
x t ( )
y t ( )
t t ,

FIGURE 7. The graphs of the functions x(t) and y(t) which are solutions for the system in Example 3.3.

The exact solution of the system is:
xx t ( ) 2 e
t
t e
t
+ t
2
2 :=

yy t ( ) 2 e
t
t 1 ( ) e
t
+ 2 t :=
Using Mathcad we check if that is true.

t
xx t ( )
d
d
yy t ( ) 2 e
t
simplify 0


t
yy t ( )
d
d
xx t ( ) t
2
simplify 0

Now we plot these functions in the same system of axes (see Figure 8).

0 0.5 1 1.5 2
10
20
30
x t ( )
xx t ( )
t t ,

0 0.5 1 1.5 2
10
20
y t ( )
yy t ( )
t t ,

FIGURE 8. The graphs of the functions (x(t), y(t)) obtained numerically with odesolve,
and the graph of the exact solution (xx(t), yy(t)) in Example 3.3.
4. REFERENCES
1. W. E. Boyce and R. C. DiPrima, Elementary Differential Equations and Boundary Value
Problems, 7th ed., John Wiley&Sons, Inc., New York, Toronto, Singapore, 2001.
2. L. Elsgolts, Differential Equations and the Calculus of Variations, Mir Publishers, Moscow,
1977.
3. P. R. Lorczak, Differential Equations from Mathcad Treasury, Update for Mathcad 2001,
E-book form www.mathcad.com.
4. A. Philippov, Recueil de problmes d'quations differentielles, Editions Mir, Moscou, 1976.
5. ***, Mathcad 11 Help.

You might also like