Professional Documents
Culture Documents
Introduction to Mathcad
Mathcad is a product of MathSoft inc. The Mathcad can help us to
calculate, graph, and communicate technical ideas. It lets us work with
mathematical expressions using standard math notation - but with the
added ability to recalculate, view, present, and publish with ease, even
to the Web. We shall explore the following functionalities provided by
Mathcad ,
Numeric operators perform summations, products, derivatives,
integrals and Boolean operations.
Numeric functions apply trigonometric, exponential, hyper-
bolic and other functions and transforms.
Symbolics simplify, dierentiate, integrate, and transform ex-
pressions algebraically.
Vectors and Matrices manipulate arrays and perform vari-
ous linear algebra operations, such as nding eigenvalues and
eigenvectors, and looking up values in arrays.
Dierential Equation Solvers support ordinary dierential equa-
tions, systems of dierential equations, and boundary value
problems both at the command line and in solve blocks that
use natural notation to specify the dierential equations and
constraints.
In this chapter, we give a brief introduction to its user interface and
the basic usage of MathCad in dening, evaluating, and graphing of
variables and functions.
1
2 1. INTRODUCTION TO Mathcad
1. User Interface: Menus and Toolbars
Since MathCad is a window program as shown in the following
screen shot after run the Mathcad program.
Figure 1. Mathcad Window
The blank area is the work area that allow us typing and evaluat-
ing mathematical expression, graphing, symbolic computing, entering
and running Mathcad scripting codes, and entering ordinary text.
It has standard main menu bar at the top of the window as most
window programs do that is shown in the following screen shot.
Figure 2. Main Menu Bar
But some menus deserve a little more attention. They are View,
Insert, and Symbolic menus.
1.1. The View Menu. The View menu, among other features,
allows a user to bring up popup menu bars for using with Mathcad .
1. USER INTERFACE: MENUS AND TOOLBARS 3
Figure 3. Menu Bar
Mathcad has nine popup toolbars that for entering math formulas,
mathematical symbol, graphing, programming, etc. We can choose to
bring up each one at a time or bring up the top level popup menu
toolbar by selecting Math as shown in the following screen shot,
Figure 4. Top Level Popup Menu Toolbar
By click each menu icon at this top level menu bar, we can bring
each individual one as needed.
4 1. INTRODUCTION TO Mathcad
Practice
(1) Start the Mathcad program and explore it top menu system by
click on each menu item.
(2) Bring up the Math popup menu toolbar, move mouse over
each icon to see the caption.
(3) Click each icon of the Math popup toolbar to bring up other
popup toolbars and explore them.
1.1.1. Graph Toolbar. The graphic toolbar contains toolbars for
Figure 5. Graph Toolbar
creating 2D-graph and 3D-graph that are most useful for our purpose.
First click on any blank spot in the work area, which tells Mathcad
where to place the graphic region; then click on the icon
or type [Shift][2]( @ sign) Mathcad creates a 2D graphic region at
the selected location that can be used to graph any equation y = f(x)
or vector pair {Y, X}. We will give examples to illustrate how to graph
functions and vector pair in later section.
1.1.2. Vector and Matrix Toolbar. The Vector and Matrix Tool-
bar contains toolbars for creating and manipulating matrices.
Figure 6. Vector and Matrix Toolbar
1. USER INTERFACE: MENUS AND TOOLBARS 5
The most frequently use menu selection in the matrix popup toolbar
is the create matrix icon,
which upon click will bring up a dialog box that allow us to create
a matrix with specied number of rows and columns. Another way to
bring up the matrix creating dialog box is press [Ctrl][M] (hold [Ctrl]
key and press [M] key)). matrix with one row or column is a
vector. The matrix popup toolbar also contains menu selections that
help us to nd eigenvalues and eigenvectors, to access each individual
row or column, or nd inverse. However once we remember the hot-key
or function-call for each operation, we dont really need these toolbars.
Using hot-key or function-call is a much quick way to invoke the menu
selection.
For example, to nd inverse of an given matrix A, we only need to
type A^{-1} (which will show as A
1
in the workplace) and = (which
tells Mathcad to execute the operation) to nd it.
1.1.3. Evaluation Toolbar. The Evaluation Toolbar contains tool-
Figure 7. Evaluation Toolbar
bar for assignment operator :=, global denition operator , and the
evaluation command =.
Notice in Mathcad , equal sign = is used as evaluation command
that tells Mathcad to carry out the computation. There are two ex-
ecution mode, one is automatic, in this mode, Mathcad carries out
execution when we press [=]; another is manual, in this mode you will
have rst press [=] followed by [F9] key to let Mathcad to carry out the
execution. The manual mode is desirable when we want to delay the
execution and dont want to be bothered by many error message Math-
cad would produce in automatic mode. You turn o/on the automatic
mode from the Math menu on the Main Menu bar.
6 1. INTRODUCTION TO Mathcad
In the automatic execution mode, after we type 3+2= we get
3 + 2 = 5.
If we want to assign 2 to variable x we will have to type x:2 , which
will be displayed as x:=2 in the work area. Therefore, a mathematical
expression
y = x + 3
will be enter dierently according to the meaning of the expression,
(1) Entering it as y:x+3 when x value has been dened before
this expression and you want y to be the value of x plus 3, i.e.
assign the value of x + 3 to y.
(2) Entering it as y(x):x+3 when we want to set y as a function
of x dened as x + 3.
(3) Entering it as y[Ctrl]=x+3 when we like to compare y and
x + 3, i.e. to logically determine if y has the same value as
x+3, here [Ctrl]= mean enter = while hold the [Ctrl] key.
We can get the logic equal sign =from the Boolean Toolbar
as shown below. Notice you also get , , =, and other logic
operation from the Boolean Toolbar.
Figure 8. Boolean Toolbar
The global assignment operator (shortcut ) is to assign an
value (expression) to a variable (a function) so it can be referred in
any place of the work area. The following screen shot illustrates the
dierence between =, :=, =, and ,
1. USER INTERFACE: MENUS AND TOOLBARS 7
The reason behind these dierences and using of Mathcad is that
scans your input from top to bottom and left to right as illustrated in
the following diagram.
Scan Start
Top-Left
to
to
//
Right
Bottom
So a variable or a function must be dened before it is used. The
will give us a leverage to defy this scan order so we can dene and use a
variable (function) without worrying about the proper order demanded
by the Mathcad as illustrated in the following two screen shots. Notice
red font indicate a error.
1.1.4. Calculus Toolbar. The Calculus Toolbar as shown below
allow us to perform computations found in Calculus. We will give
detail description in later section about the symbolic computation using
Mathcad
8 1. INTRODUCTION TO Mathcad
Figure 9. Calculus Toolbar
1.2. The Insert Menu. The Insert menu,among other features,
allows a user insert a text region in the Mathcad work place or math
region inside text region,
Figure 10. Insert Menu
In side the text region, user can enter any text as she/he would
do in a normal text editor with any format setting that can be speci-
ed through the Format->style menu. Another way to insert a text
region is to type double quotation mark . Mathcad also allow a
user to insert a math region inside a text region so users can insert a
mathematical expression in the text region.
1. USER INTERFACE: MENUS AND TOOLBARS 9
A third usage we are interested in the Insert menu is to insert a
graphic region, a matrix, and a special build in function. The following
screen shot shows the case of inserting a matrix.
Figure 11. Insert a Matrix
1.3. The Symbolic Menu. The Symbolic menu, allows us to
Figure 12. Insert Menu
carry out symbolic computation. We can factor polynomial, simplify an
complex expression, nd antiderivative, Laplace transform and inverse
Laplace transform, etc.
10 1. INTRODUCTION TO Mathcad
The following screen shot shows the case of evaluating an expression
symbolically.
Figure 13. Evaluate
Another screen shot to show nding Laplace transform symbolically.
Figure 14. Laplace Transform
Practice
(1) Find dierence between =, := ([Shift][;], :), =([Ctrl][=]) and
([Shit][], sign) with mathematical express y = x + 3.
(2) Dene some matrix in you working area and place with Matrix
toolbar.
(3) Place graph region in the work area, the typing something in
the place hold .
1. USER INTERFACE: MENUS AND TOOLBARS 11
1.4. Shortcut keystrokes. Besides using menus or popup menu
toolbars to insert item into working place, we can (should) use shortcut
keystrokes (or hot keys) to accomplish the same goals.
One important concept in entering expression in Mathcad is the
place holder. It is a little dark rectangle box . For example, when you
type + (addition operator) in any blank area we get + . In the
place holders we enter any valid mathematics expression.
Mathcad uses arithmetic operators +, , etc in the same way as
standard calculator. The following table list the keystrokes for arith-
metic operators, root operators, and subscription (indexing).
Keystroke Usage Type Display Remark
+ add a+ a + type an expression in
- subtract a- a type an expression in
* times a* a type an expression in
/ divide a/
a
type an expression in
power a a type an expression in
\ square root \
type an expression in
[Ctrl]\ n
th
root [Ctrl]\
type index in the rst and
radicand in the second
[ subscript a[ a type subscripts separated by , in
Table 1. Arithmetic And Radical Operators
Since in mathematics x = y has four dierent meanings,
(1) denition: denes functions or notation, for example, in the
expression f(x) = x
2
+ 1, one denes a function f by an ex-
pression x
2
+ 1.
(2) assignment: assigns value of y to x; like in the sentence set x
= y...
(3) logical equal: x is equal to y logically; like in the sentence if
x = y ....
(4) result of computation: like 4 + 5 = 9 here 9 is result of
adding 5 to 4.
Mathcad uses = as execution command, that is to tell Mathcad to
compute the value. It uses (:=) for assignment and denition, and
(boldface =) for logic equal.
12 1. INTRODUCTION TO Mathcad
The following table list keystrokes for assignment plus relational
operators.
Keystroke Usage Type Display Remark
Entering text type any text in
: assignment a:3 a := 3 assign 3 to a
; range
variable
a:1; a := 1 . . . if enter 4 in , a will have values
1, 2, 3, 4
[Shift][]() global
assignment
a 3 a 3 assign 3 to a globally
[Ctrl][=] logic equal a:[Ctrl][=]1; a=1 a is logically equal to 1
< less than a< a < type an expression in
> greater than a> a > type an expression in
[Ctrl][9] less or equal a [Ctrl][9] a type an expression in
[Ctrl][0] greater or
equal
a [Ctrl][0] a type an expression in
[Ctrl][3] not equal a [Ctrl][3] a = type an expression in
Table 2. Assignment And Relational Operators
The following table lists keystrokes to bring up derivative operators,
integration operators and matrix operators.
Keystroke Usage Type Display Remark
[Shift][/](?) derivative [Shift][/]
d
d
variable in at denominator
and function in other
[Shift][Ctrl][/] nth
derivative
[Shift][Ctrl][/]
d
d
index at two exponents vari-
able in at denominator after
d and function in last
[Ctrl][I] indenite
integral
[Ctrl][I]
3 4
1 18
by entering A:[Ctrl][M]
and choose 2 for row and column numbers, entering the num-
bers in proper place holder.
(a) Find inverse of A by type A^{-1}
(a) Find A
2
4
2
5
, and nd Ab.
(3) Dene the following functions
20 1. INTRODUCTION TO Mathcad
(a) f(t) = 2t e
t
(4) (b) f(t, x) = t
2
4t sin(x)
(5) (c) f(t, x) =
2xe
x
2txcos(x)
.
(6) Graph function f(t) = t
2
2t 1
(a) without specifying value for t.
(b) dene t = 0, 0.1 5
(c) Graph g(t) = 4 sin(t) in the same chart.
(d) Graph a point (4, 5) in the same plot, now you need
put t, t, 4 in the bottom place holder and f(t), g(t), 5 in the left
middle place holder. You also need to double click the graph
and change the weight so the point is shown as in the following
screen shot.
Project
At beginning you should enter: Project title, your name, ss#, and
due date in the following format
Project One: Dene and Graph Functions
John Doe
SS# 000-00-0000
Due: Mon. Nov. 23rd, 2003
2. BASIC USAGE OF Mathcad 21
You should format the text region so that the color of text is dierent
than math expression. You can choose color for text from Format
>Style select normal and click modify, then change the settings for
font. You can do this for headings etc.
(1) Dene and Graph functions
In the project you will do:
Dene f(x) = (x 3)(x 1)(x + 2)
Dene a range variable x = 5, 4 5 and nd func-
tion value at range variable.
Find zero of its derivative by perform the following task,
[-] dene df(x) with input df(x):[Shift][/] and en-
ter f(x) and x in the place holder so you have df(x) :=
d
dx
f(x).
[-] Type keyword Given , entering df(x)[Ctrl][=] in
next line, and keyword Find following by (x), then press
[Ctrl][.]
[-] Find zeros of its second derivative.
Determine intervals where the function is concave upward
and concave downward. Type your explanation in text
regions.
Graph the function, its rst derivative, and second derivative
in the same plot. Explain the relationship between the
signs of its derivatives and concavities of its graph.
(2) Matrix Calculation
Dene the matrix A =
3 2 4
1 2 1
5 8 22
1
3
20
= f(t, x) is called a
rst order ordinary dierential equation(ODE), more precisely a semi
linear rst order ordinary dierential equation. In this chapter will
will demonstrate how to nd explicit solution(s) to a given ODE . In
general one cant nd explicit solution to a given ODE , but for special
types of f(t, x), we will have luck to do that.
Some clearance of notations is needed here.
In x
is
dx
dt
, the rst derivative of x(t), and f(t, x) is a given
function of two variables t and x. So to nd an explicit solution is to
nd an formula for x(t) so that when substitute the formula in f(t, x),
we will get an expression in t only that matches x
= x+t. If
we set x(t) = 2e
t
t 1 then f(t, x) = x+t = 2e
t
t 1 +t = 2e
T
1
and x
(t) = 2e
t
1 so x
is
dy
dx
, the rst derivative of y(x). So for y
= y + x, we would
get an solution y(x) = e
x
x 1.
Sometimes the independent variable does not appear in the equa-
tion such as y
= f(y) or x
= f(y)) or t (for x
= f(x)) and
write the solution accordingly. Hence, for y
b
a
symbol to get the operator for denite integral and on the
symbol
to get the operator for the indenite operator. Then just ll in the
place holders accordingly. For denite integral, hit = to get the value
and for indenite integral, you need either
Select the entire expression and from the Symbolics menu
following the menu item evaluate to the symbolically(Or
[Shift][F9]).
or
Hold down the [Ctrl] key and press the [.] (period) key.
You can also access the integration operators by hot keys [Shift][F7]
for denite integral and [Ctrl][I] for indenite integral.
The integration operators appear on the workplace as shown in the
following diagram,
Now lets see some examples. The rst example is for nding denite
integral.
Example 1.1. Find the denite integral
3
0
(x
5
e
3x
sin(3x)) dx.
Solution At any blank space in the workplace of Mathcad , type
[Shift][F7], that is hold the [Shift] key and press [F7] key to place the
denite integration operator
d
1. FINDING ANTIDERIVATIVE USING Mathcad 3
Figure 2. Integration Operators
. Click the upper limit place holder, type 3 and click the lower limit
place holder type 0. Now click the integrant place holder type
x^5 -e^3x -sin(3x)
notice you need it the space bar twice before -sin(3x) . Of
course you need hit space bar once before entering -e^3x to exit the
power mode. Finally in the integration variable place holder type x(see
Figure 2 for the position of each place holder.) Now hit [=] key if in
automatic mode or =[F9] otherwise to nd the value 2.5 10
3
.
The second example is for nd indenite integral.
Example 1.2. Find the denite integral
x + 2e
3x
sin(3x)) dx.
Solution At any blank space in the workplace of Mathcad ,
type [Ctrl][I], that is hold the [Ctrl] key and press [I] key to place the
indenite integration operator
d .
Click the integrant place holder and type
\x+2 -e^3x -sin(3x)
Notice you need to hit the space bar twice before -sin(3x) . Of
course you also need hit space bar twice too before entering -e^3x to
exit the square root operator.
In general, you will need to hit the space bar as many times
an need to escape the power(subscript, division, etc.) mode
before you enter next term.
The backslash \ brings up the square root operator. Finally in
the integration variable place holder type x(see Figure 2 for the position
of each place holder.) Now hold down[Ctrl] to type [.] key and click on
4 1. EXPLICITLY SOLVABLE FIRST ORDER DIFFERENTIAL EQUATIONS
any region outside the bounding box, if not in the auto execution
mode hit [F9] too, to nd the antiderivative
x + 2 e
3x
sin(3x) dx
2
3
(x + 2)
3
2
1
3
exp
3x
+
1
3
cos(3x)
. Here exp represent exponential function. From Calculus, we know
that
x + 2 e
3x
sin(3x) dx =
2
3
(x + 2)
3
2
1
3
exp
3x
+
1
3
cos(3x) + C.
Mathcad omits the C for believing you know it! Remember C is im-
portant when we try to nd a particular solution for a given, so called,
initial condition.
Example 1.3. Find a function x(t) such that x
(t) dt =
2t dt
which leads to
x(t) = t
2
+ C. (1)
Evaluate this x(t) at t = 0 we have
x(0) = 0
2
+ C = C
So the requirement x(0) = 3 implies C = 3. Hence x(t) = t
2
+ 3.
Notice if we drop the C from (1), we would not be able to nd x(t)
that satises x(0) = 3!
The problem of nding a particular solution with initial condition is
called initial value problem, which we will discuss in the later section.
Practice
1. Find the following denite integral using Mathcad .
(a)
2
1
x
3
x cos(x
2
+ 1) dx
(b)
4
1
x
3
+4x5
x+1
dx
(c)
0
5
e
3x
x
x
2
+3
dx
(d)
10
1
x
2
x sec(x
2
+ 1) dx
2. Find the following indenite integral using Mathcad .
(a)
x
5
x
(x
2
+ 1) dx
(b)
x
3
+4x5
x
2
+1
dx
2. SEPARABLE EQUATIONS 5
(c)
x3
(x
2
+3)(x+5)
dx
(d)
x tan(x
2
+ 1) dx
2. Separable equations
If we let x be the independent variable and y be the dependent
variable, a separable ODE is given by,
y
= f(x)g(y)
where both f and g are given one variable functions and y
=
dy
dx
is the
derivative of y(x) with respect to x and y(x) is the unknown function
we want to nd out.
When g(y) 1, that is g(y) is a constant function whose value is
always 1, the separable ODE becomes
y
= f(x)
, which is sometimes called integrable ODE . The general solution to
the integrable ODE is the antiderivative of f(x), i.e.
y(x) =
f(x) dx
So if we can nd the antiderivative of f(x) we can nd the explicit
general solution.
Example 2.1. Find solution y
= x
2
+ 3
Solution The solution is,
y(x) =
x
2
+ 3 dx =
1
3
x
3
+ 3x + C
. Here we used the power rule of antiderivative,
x
n
dx =
x
n+1
n + 1
+ C.
To nd the solution in Mathcad , you just click any blank area in the
workplace and type [Ctrl][I] to get the indenite operator
d
and type x^2 +3 in the place holder for integrant and x in the inte-
grating variable place holder. Then press [Ctrl][.] and click on any
region outside the bounding box to get the result. Sometime you
might need to hit [F9] too if the auto execution mode is turn o.
6 1. EXPLICITLY SOLVABLE FIRST ORDER DIFFERENTIAL EQUATIONS
When g(y) is not a constant function, the general solution to
y
= f(x)g(y)
is given by the equation
dy
g(y)
=
dy
g(y)
and
= f(x)g(y)
This kind solutions are called stationary or steady-state solutions.
Sometimes they are also called singular solution.
Example 2.2. In the study of Epidemics, the spread of disease in
a population can be modelled by I
=
dI
dt
= (b(t)S(t) r(t))I,
divide its both sides by I, multiplying its both sides by dt and taking
antiderivative we have
dI
I
=
b(t)S(t) r(t) dt
The left side is easy to nd,
dI
I
= ln |I| + C (3)
Plug in the given functions, we get the right hand side
b(t)S(t) r(t) dt =
t
2
e
3t
4 dt
2. SEPARABLE EQUATIONS 7
Now open Mathcad window, click any blank area, type [Ctrl][I] to get
the antiderivative operator
d
type t^2 *e^{-3t} - 4 in the integrant place holder (again using
space bar to exit the power mode) and t in the other place holder, then
type [Ctrl][.], click any area outside the box. You will get
t
2
e
3t
4 dt =
1
3
t
2
e
3t
2
9
te
3t
2
27
e
3t
4t + C (4)
Put (3) and (4) together, we have
ln |I(t)| =
1
3
t
2
e
3t
2
9
te
3t
2
27
e
3t
4t + C
Solve for I(t), we nally arrive at
I(t) = e
1
3
t
2
e
3t
2
9
te
3t
2
27
e
3t
4t+C
= Ce
1
3
t
2
e
3t
2
9
te
3t
2
27
e
3t
4t
=
e
x
+2x
sin(y)+3y
2
+3
Solution Write y
as
dy
dx
, multiply both sides of the equation by
(sin(y) + 3y
2
+ 3)dy and take antiderivative, we have
sin(y) + 3y
2
+ 3 dy =
e
x
+ 2x dx
Now using Mathcad or compute by hand, we nd
sin(y) + 3y
2
+ 3 dy = cos(y) + y
3
+ 3y + C
and
e
x
+ 2xdx = e
x
+ x
2
+ C
So we have an implicitly dened solution y(x) by the equation
cos(y) + y
3
+ 3y = e
x
+ x
2
+ C
Here, we cant nd an explicit formula for y(t).
Practice
8 1. EXPLICITLY SOLVABLE FIRST ORDER DIFFERENTIAL EQUATIONS
Project
3. Linear equations and Bernoulli equations
3.1. Linear Equations. An ODE of form
y
+ a(x)y = b(x)
is called a linear equation. Any equation that can be converted into
this form can also be called a linear equation. Such as x
2
y
+4x
2
e
x
y =
sin(x), which can be written as y
+ e
x
y =
sin(x)
x
2
, is a linear equation.
The general solution of the linear equation is
y(x) = e
a(x) dx
b(x)e
a(x) dx
dx + C
a(x) dx
.
Example 3.1. According to Newtons law of cooling, the time rate
of change of the temperature T(t) of a air conditioned house with ex-
ternal temperature A(t) is proportional to the dierence A T. That
is,
dT
t
= k(A T),
where k is positive constant. Now, suppose A(t) = 80 10 cos(t) nd
the general solution.
Solution Since we want to use Mathcad to nd the antiderivative
for us, the rst thing is to nd how to get the Greek letter . To get
, rst bring the math tool bar from the View menu
Figure 3. Math Toolbar
3. LINEAR EQUATIONS AND BERNOULLI EQUATIONS 9
Click on the
Figure 4. Greek Letter Button
which will bring up
Figure 5. Greek Letter Bar
and select the letter.
Now if we rewrite and put in A(t)
dT
t
= k(A T),
we get
dT
t
= k(80 10 cos(t)) kT,
and is a linear equation with a(t) = k and b(t) = k(80 10 cos(t)), it
easy to see that
a(t) dt =
ke
kt
80 10 cos(t)
dt + C
.
After bring up the indenite operator
d
type k*e^k*t (80-10cos(t) as integrant and t as integration vari-
able, press [Ctrl][.], click any place outside the box, we get,
ke
kt
8010 cos(t)
dt = 80e
kt
10k
k
k
2
+
2
e
kt
cos(t)+
k
2
+
2
e
kt
sin(t)
So the solution is
T(t) = e
kt
80e
kt
10k
k
k
2
+
2
e
kt
cos(t)+
k
2
+
2
e
kt
sin(t)
+C
80e
0.2t
5
3.2
0.64 +
2
e
0.2t
cos(t)+
4
0.64 +
2
e
0.2t
sin(t)
+C
+ 4xy = x
2
(b) e
x
y
+ e
x
y = sin(x)
(c) xy
= 2y + x
3
cos(x)
(d) y
= 2xy + 3x
2
e
x
2
(e) (x
2
+ 4)y
+ 3xy = x
(f) (x
2
+ 1)y
+ 3x
3
y = 6xe
3
2
x
2
(2) Application: The equation y
v + v
x = 0, plug in x
= ax bx
2
, we have
(ax bx
2
)v + v
x = axv bx
2
v + v
x = a bx + v
x = 0 since xv = 1
So
a bx + v
x = 0 (7)
Divide (7) by x and notice
1
x
is v, we have
v
+ av b = 0,
or
v
+ av = b.
Apply the solution formula for linear equation we have
v = e
a dt
be
a dt
dt + C
So
x =
1
v
=
e
a dt
be
a dt
dt + C
a dt
be
a dt
dt + C
So
x =
e
at
be
at
dt + C
=
e
at
b
a
e
at
+ C
,
is the general solution.
When C = 0 we have x =
a
b
, a stead-state solution. Also, x = 0 is
another steady-state solution, which cant be represented in the general
solution.
We can rewrite x(t) as
x(t) =
a
b + aCe
at
,
since lim
t
e
at
= 0 So we have lim
t
=
a
b
. That is, as time goes
on the population will gradually settles itself at the level of
a
b
. The
following picture shows that the solution curves approaches the line
y =
a
b
= 10, with a = 0.2 and b = 0.002.
Figure 7. Population a = 0.2 and b = 0.02
14 1. EXPLICITLY SOLVABLE FIRST ORDER DIFFERENTIAL EQUATIONS
Here is how to get the graph in Mathcad :
- we rst dened a function x(t, C):=
0.2
0.02+Ce
0.2t
with two argu-
ments t and C by typing x(t,C):0.2/0.02+C*e^-0.2t,
- then we dened a range variable t:=0,0.1. . .20 by typing
t:0,0.1;20,
- nally, type @ at a blank area to get the xy-plot; in the function
place holder, we put
x(t,0),x(t,-0.01),x(t,-0.008),x(t,0.004),x(t,0.01)
and type t in the variable place holder, and click at outside of the
box to get the graph.
=
f(t, x) that satisfying condition x(t
0
) = x
0
is called an initial value
problem. The problem can be written
= f(t, x)
x(t
0
) = x
0
Since solving an ODE requires a lots of hard work, it is wise to know if
a given equation has any solution before march on the journey of nd
a solution. For the linear rst order ODE x
a(t) dt
b(t)e
a(t) dt
dt + C
(8)
with an appropriate value of C.
So solving an initial value problem for linear rst order ODE is easy.
One just apply the formula (8) and using the equation x(t
0
) = x
0
to
nd C.
Example 4.1. Solve the initial value problem x
+2tx = 4t
3
, x(0) =
1.
Solution First we apply the formula (8)
x(t) = e
a(t) dt
b(t)e
a(t) dt
dt + C
,
4. INITIAL VALUE PROBLEM AND EXISTENCE THEOREM 15
with a(t) = 2t and b(t) = 4t
3
. So
a(t) dt =
2t dt = t
2
, and
x(t) = e
t
2
4t
3
e
t
2
dt + C
.
Using method of substitution or Mathcad , we nd
x(t) = e
t
2
2t
2
e
t
2
2e
t
2
+ C
2t
2
e
t
2
2e
t
2
+ 3
However, for general rst order ODE , the problem is not so nice,
the following theorem is a little bit hard to state and to understand.
Theorem 4.2. Let f(t, x) be dened on interval I. If the partial
derivative of f(t, x) with respect to y (denoted as
f(t,x)
y
, reads par-
tial f(t,x) over partial y) and f(t, x) are continuous at an open disk
centered at (t
0
, x
0
), then the initial value problem
= f(t, x)
x(t
0
) = x
0
has an unique solution on some open interval containing the point t
0
.
Remark 4.1. We will not discuss this existence and uniqueness
theorem for general ODE . But we would like to make some comments.
- To nd
f(t,x)
t
, you just need to treat x variable as a constant,
for example, let f(t, x) = t
2
x
3
+ 3t 4x, we have
f(t,x)
t
=
2tx
3
+3, here 4x is a constant with respect to t, so the derivative
is 0, and x
3
is also a constant, so t
2
x
3
when taking derivative
against t we have 2tx
3
. Therefore nding partial derivative is
as easy as to nd ordinary derivative.
- This theorem only guarantees a solution dened for t in an
open interval, which might be a bounded interval. For example
x
= x
2
, we see that x(t) =
1
t+c
is the general solution, if
c = 2 then the solution is only dened on interval (0, 2) as
x(t) =
1
t2
will become undened at t = 2.
- Some time we could have more than one solution that satises
the same initial condition, for example, for x
= x
2
3
and x(0) =
0 we have two dierent solution, one is x(t) = 0 another one
16 1. EXPLICITLY SOLVABLE FIRST ORDER DIFFERENTIAL EQUATIONS
is x(t) = t
1
3
. The reason is that for f(t, x) = x
2
3
,
f(t,x)
x
=
1
3
x
which is undened at (0, 0). So the conditions of the theorem
are violated.
5. Phase and vector eld diagrams
Sometimes it is more important to know the behavior of solutions
than to know precisely detail of point-by-point of some particular so-
lutions. Here we will discuss two diagrams to get an feel of behavior
of solutions for a ODE without actually nd any solution. The rst,
phase diagram, is used for the autonomous equations and is easy to
draw. The second, vector eld diagram, can be used for any equa-
tion but harder to draw. These two diagrams make use of the facts:
(1) The derivative f
=
dx
dt
= f(x)
(The independent variable is t)or y
=
dy
dx
= f(y) (The independent
variable is x). To draw a phase diagram of x
= f(x).
Step two: Plot the solution one a horizontal (or vertical)number line.
The solutions will divide the line into intervals (segments),
pick any number from each interval (segment) and determine
the sign of the value of f(x) at the picked value.
Step three: Using the sign in Step two to draw arrow on each segment, a
right (up) arrow for positive sign and a left (down) arrow for
negative sign.
Example 5.1. Draw phase diagram for x
= (x1)(x+2)(x3).
Solution
Step one: Here f(x) = (x 1)(x + 2)(x 3) so f(x) = 0 gives
(x 1)(x + 2)(x 3) = 0,
and it has three solutions, x = 2, 1, 3
Step two: Plot the three solution on the number line,
Figure 9. Number Line
we see that we have four intervals: (-, -2), (-2, 1), (1, 3), and (3, ).
The following table organizes our computation,
Interval (-, -2) (-2, 1) (1, 3) (3, )
x-value picked -3 0 2 4
Value of f(x)=
(x-1)(x+2)(x-3)
f(-3)=(-3-1)
(-3+2)(-3-3)
=-24
f(0)=(0-1)(0+2)
(0-3)=6
f(2)=(2-1)(2+2)
(2-3)=-4
f(4)=(4-1)(4+2)
(4-3)=24
Sign of f(x) - + - +
Step three: Draw the arrows on the number line. A right arrow for
positive sign and a left arrow for negative sign.
Figure 10. Phase Diagram
If c is a critical number of x
=
df(x)
dt
=
df(x)
dx
dx
dt
= f(x)
df(x)
dx
, we can get an very good picture about the behavior
of the solutions.
Example 5.2. For x
19), (1,
2
3
+
1
3
19), and
(3, ).
(b)
d
2
x(t)
dt
2
< 0 on intervals, (, 2), (
2
3
1
3
19, 3).
With this information and the phase diagram we have the following
picture of typical solutions for x
= (x 1)(x + 2)(x + 3)
5.2. Vector eld diagram. We know that the derivative x
(t
0
)
of x(t) at t
0
is the slope of the tangent line to the graph of x(t) at
the point (t
0
, x(t
0
)), and the equation of the tangent line is y x(t
0
) =
x
(t
0
)(tt
0
). The idea of vector eld for an ODE x
= f(t, x) is to draw
a segment of tangent line to many chosen points (t
0
, x
0
) with slope
x
(t
0
) = f(t
0
, x
0
). When we draw enough such line segments, patterns
shall emerge and we shall have a clear idea(with some training) of the
behavior of solutions to the equation. The following diagram shows the
vector eld of x
= x
over [0,1][0,1] and divide [0, 1] into two subinterval, h = s = 0.5.
Then we will have nine grid points (0, 0), (0, 0.5), (0, 1), (0.5, 0),
(0.5, 0.5), (0.5, 1), (1, 0), (1, 0.5), and (1, 1). For the grid point
(0.5, 0.5) we have slop m = 0.5 as the function f(x, y) = x. So we can
get another point (0.5+
h
2
, 0.5+m
h
2
) = (0.75, 0.625), connect (0.5, 0.5)
to (0.75, 0.625) you get one line segment, continuous this we get the
following diagram.
Figure 14. Vector eld for f(x, y) = x
So it is obviously tedious to draw the vector eld by hand.
To graph vector eld in Mathcad is not an easy task. This is especially
true when you want to superimpose solution curve over the graph. You
need to write some code to instruct how you want Mathcad to graph the
vector eld for what function. you can get the code from the website
www.unf.edu/mzhan.
Project
At beginning you should enter: Project title, your name, ss#, and
due date in the following format
Project One: Dene and Graph Functions
John Doe
SS# 000-00-0000
Due: Mon. Nov. 23rd, 2003
You should format the text region so that the color of text is dierent
than math expression. You can choose color for text from Format
>Style select normal and click modify, then change the settings for
5. PHASE AND VECTOR FIELD DIAGRAMS 21
font. You can do this for headings etc. Graph Vector eld
Goal: Familiar your self with an many dierent kind of vector elds,
dened by x
_
0 5
3 4
_
=
_
8 7
7 20
_
The following fact lists all properties of matrix addition and scalar
product.
Theorem 1.1. Let A, bB, and C be matrices. Let a, b be scalars
(numbers). We have
(1) A + 0 = 0 + A = A, AA = 0;
(2) A + B = B + A (commutativity);
(3) A + (B + C) = (A + B) + C, (ab)A = a(bA) (associa-
tivity);
(4) a(A+B) = aA+aB, (a+b)A = aA+bA (distributivity)
When we have a row vector and a column vector with the same
number of elements, we can dene the dot product as
Definition 1.2. Dot Product:
in 2-dimension: Let x =
_
x
1
x
2
and y =
_
y
1
y
2
_
, the
dot product of x and y is,
x y = x
1
y
1
+ x
2
y
2
4 1. BRIEF INTRODUCTION TO VECTORS AND MATRICES
in 3-dimension: Let x =
_
x
1
x
2
x
3
and y =
_
_
y
1
y
2
y
3
_
_
,
the dot product of x and y is,
x y = x
1
y
1
+ x
2
y
2
+ x
3
y
3
Definition 1.3. Matrix product
Let A = (a
ij
) and B = (b
ij
), if the number of columns of A
is the same as number of rows of B, then the product of A and B is
given by AB = (c
ij
) where c
ij
is dot product of i
th
row of A with j
th
column of B.
Example 1.2. Let
A =
_
2 3
1 4
_
and
B =
_
0 5
3 4
_
,
nd AB
Solution
AB =
_
2 3
1 4
_ _
0 5
3 4
_
=
_
2 (0) + 3 (3) 2 5 + 3 (4)
(1) (0) + 4 3 1 5 + 4 (4)
_
=
_
9 2
12 21
_
Notice, the rst element of AB is 2 (0) + 3 (3) which is the dot
product of rst row of A,
_
2 3
The next example shows how we can determine the unknown con-
stants typically found in the initial value problems of system of dier-
ential equations.
Example 1.5. Let x
1
(t) = C
1
e
t
+ C
2
e
2t
and x
2
= 2C
1
e
t
C
2
e
2t
. If x
1
(0) = 2, x
2
(0) = 3, nd C
1
and C
2
Solution From x
1
(t) = C
1
e
t
+ C
2
e
2t
, set t = 0 we have
x
1
(0) = C
1
e
0
+ C
2
e
2(0)
= C
1
+ C
2
.
Similarly, x
2
(t) = 2C
1
e
t
C
2
e
2t
, gives x
2
(0) = 2C
1
e
(
0)
C
2
e
2(0)
= 2C
1
C
2
.
Together with x
1
(0) = 2, x
2
(0) = 3 we have the following system
of equations,
_
C
1
+ C
2
= 1
2C
1
C
2
= 3
Rewrite the equation in matrix form
_
1 1
2 1
_ _
C
1
C
2
_
=
_
1
3
_
,
and using Mathcad we nd the solution is
_
C
1
C
2
_
=
_
4
3
1
3
_
8 1. BRIEF INTRODUCTION TO VECTORS AND MATRICES
So x
1
(t) =
4
3
e
t
1
3
e
2t
and x
2
=
8
3
e
t
+
1
3
e
2t
. They are solution of
the following system of dierential equations,
_
x
1
(t) = x
1
(t) + x
2
(t)
x
2
(t) = 2x
1
a b
c d
= ad bc. For a 3 3
matrix
_
_
a
11
a
12
a
13
a
21
a
22
a
23
a
31
a
32
a
33
_
_
we can compute the matrix as
a
11
a
12
a
13
a
21
a
22
a
23
a
31
a
32
a
33
= a
11
a
22
a
23
a
32
a
33
a
12
a
21
a
23
a
31
a
33
+a
13
a
21
a
22
a
31
a
32
.
In Mathcad , type the vertical bar to bring up the absolute
evaluator | |, put the matrix in the place holder and press = to compute
the determinant. The following screen shot shows an example,
Figure 2. Compute determinant in Mathcad
The concepts of eigenvalue and eigenvector play an important role
in nd solutions to system of dierential equations.
Definition 1.5. We say is an eigenvalue of a matrix A (2 2
or 3 3) if the determinant
|AI| = 0.
An nonzero vector v is an eigenvector associated with if
Av = v.
Remark 1.1.
1. VECTORS AND MATRICES 9
- The above denition of eigenvector and eigenvalue is valid for
any square matrix with n rows and columns.
- p() = |AI| is a polynomial of degree n for nn matrix
A, which is called the characteristic polynomial of A.
- If we view A as an transform that maps a vector x to Ax,
an eigenvector v denes a straight line passing origin that is
invariant under A.
- If v is an eigenvector then for and number s = 0, sv is also
an eigenvector. This is especially useful when using Mathcad
to get eigenvectors, the result of Mathcad might look bad, you
might need to remove the common factor of the component of
the vector to make it better.
Computing eigenvalues and eigenvectors of a given matrix is quite
tedious, Mathcad provides two functions eigenvals() and eigenvecs()
to compute eigenvalues and eigenvectors of a matrix.
In Mathcad , eigenvecs(M) Returns a matrix containing the eigenvectors. The
nth column of the matrix returned is an eigenvector corresponding to the nth
eigenvalue returned by eigenvals.
The results of these functions by default is in decimal, you can
change it by using simplify key word as shown in the following dia-
gram.
(a) Find eigenvalue (b) Find eigenvector
Figure 3. Compute eigenvalue and eigenvector in Mathcad
Notice, in the diagram, the eigenvalues are listed as vector
_
3
3
_
and the eigenvectors are listed in a matrix
_
_
1+
3
(8+2
3)
1
2
-(
3-1)
(8-2
3)
1
2
2
(8+2
3)
1
2
2
(8-2
3)
1
2
_
_
,
10 1. BRIEF INTRODUCTION TO VECTORS AND MATRICES
each column represents a eigenvector. Since multiplying an eigenvector
by a nonzero constant you still get an eigenvector, so we can simplify
the eigenvectors as v
1
=
_
1 +
3
2
_
, and v
2
=
_
1
3
2
_
Here is how to use Mathcad ,
Dene the matrix by type A:[Ctrl][M] and specify the row
and column number, ll the entries.
type eigenvals(, you will get eigenvals( ) and in the place
holder type A.
Click at end of the eigenvals(A) and press [Shift][Ctrl][.],
you will get eigenvals(A) . In the place holder type in
key word simple. And click any area outside the box to get
result.
Using the same procedure for nd eigenvector using eigenvecs()
function.
2. Vector-valued functions
A vector-valued function over [a, b] is a function whose value is a
vector or matrix. For example the following functions are vector-valued
functions,
Example 2.1. (1) v(t) =
_
t
t
2
_
(2) x =
_
_
1
t
2
e
t
_
_
(3) A(t) =
_
1 t
3
4t + 5
0 sin(t)
_
2.1. Arithmetics of vector-valued function.
To add two vector-valued function is to add their correspond-
ing components.
To multiply a vector-valued function by a scalar function to
to multiply each entry by the scalar function.
To multiply a vector(matrix) valued function to another vector-
valued function is same as multiply a matrix with a vector.
The following example illustrate how to add/subtract two vector-valued
functions and how to multiply a vector-valued function by a scalar
function and how to apply a vector-valued function that is matrix to a
vector value function.
2. VECTOR-VALUED FUNCTIONS 11
Example 2.2. Suppose v(t) =
_
_
t
t
2
t
3
2
_
_
, x =
_
_
1
t
2
e
t
_
_
, and
A(t) =
_
_
1 t
3
4t + 5 1
0 2 sin(t)
2 0 1
_
_
.
(a) Find v(t) + x(t);
(b) Let f(t) = e
t
, nd f(t)x(t);
(c) Find A(t)x(t)
Solution
(a)
v(t) + x(t) =
_
_
t
t
2
t
3
2
_
_
+
_
_
1
t
2
e
t
_
_
==
_
_
t + 1
2t
2
t
3
2 + e
t
_
_
;
(b)
f(t)x(t) = e
t
_
_
1
t
2
e
t
_
_
=
_
_
e
t
t
2
e
t
e
2t
_
_
;
(c)
A(t)x(t) ==
_
_
1 t
3
4t + 5 1
0 2 sin(t)
2 0 1
_
_
_
_
1
t
2
e
t
_
_
=
_
_
1 + t
2
(t
3
4t + 5) + e
t
2t
2
+ e
t
sin(t)
2 + sin(t)
_
_
2.2. derivative and integrations of vector-valued functions.
A vector-valued function is continuous if each of its entries
are continuous.
A vector-valued function is dierentiable if each of its entries
are dierentiable.
If v(t) is an vector-valued function, then the derivative
dv(t)
dt
=
v
(t) =
dx(t)
dt
=
d
dt
_
3t
2
5
sin(t)
_
=
_
d
dt
(3t
2
5)
d
dt
(sin(t))
_
=
_
6t
cos(t)
_
= v
(t) x
(t),
-
_
v(t) x(t) dt =
_
v(t) dt
_
x(t) dt.
(2) Product rule:
- [f(t)v(t)]
= f
(t)v(t) + f(t)v
(t),
- [A(t)x(t)]
= A
(t)x(t) + A(t)x
(t),
Using Mathcad to nd derivative or antiderivative of a vector-
valued function using Mathcad , you need to nd derivative or anti-
derivative component wise as shown in the following screen shot,
2. VECTOR-VALUED FUNCTIONS 13
Figure 4. Dierentiate and integrate vector-valued function
14 1. BRIEF INTRODUCTION TO VECTORS AND MATRICES
Notice:
- Press [Shift][/]to get the derivative operator and press [Ctrl][I]
to get the antiderivative operator.
- To get dx(t)simplify you type dx(t) and press [Shift][Ctrl][.]
and type the key word simplify in the place holder before .
- To execute symbolically ( operator), just press [Ctrl][.]
3. Linearly independency
3.1. Linearly independency of vectors. Let x
1
, x
2
, , x
n
be n vectors, C
1
, C
2
, , C
n
are n scalars(numbers), the expression
C
1
x
1
+ C
2
x
2
+ + C
n
x
n
is called a linear combination of vectors x
1
, x
2
, , x
n
.
Definition 3.1. n vectors x
1
, x
2
, , x
n
is linearly independent
if
C
1
x
1
+ C
2
x
2
+ + C
n
x
n
= 0
leads to C
1
= 0, C
2
= 0, , C
n
= 0.
A set of vectors are linearly dependent if they are not linearly in-
dependent.
If 0 is one of x
1
, x
2
, , x
n
, then they linearly dependent.
Two nonzero vectors x and y are linearly dependent if and
only if x = sy for some s = 0.
n nonzero vectors are linearly independent if one can be rep-
resented as linear combination of the others.
Any three or more 2-dimensional vectors (vectors with two
entries) are linear dependent.
Any four or more 3-dimensional(vectors with three entries)
vectors are linear dependent.
To determine if a given set of vectors are linearly independent,
create a matrix so that the row of the matrix are given vectors. Using
Mathcad function rref( ) to nd the reduced echelon form of the
matrix, if the result contains one or more rows that are entirely zero
the vectors are linearly dependent, otherwise the vectors are linearly
independent.
3. LINEARLY INDEPENDENCY 15
Example 3.1. For x
1
=
_
_
2
3
4
_
_
, x
2
=
_
_
0
1
4
_
_
, and x
3
=
_
_
4
8
0
_
_
, we can form a matrix,
A =
_
_
2 3 4
0 1 4
4 8 0
_
_
,
apply rref(type rref and in the place holder type A, then press =),
rref(A) =
_
_
1 0 8
0 1 4
0 0 0
_
_
.
We see that the vectors are linearly dependent as the last row is
entirely zero.
3.2. Linearly independency of functions. We can also dene
linearly independency for a group of functions over an given inter-
val [a, b]. Let f
1
, f
2
, , f
n
be n functions dened over [a, b],
C
1
, C
2
, , C
n
are n scalars(numbers), the expression
C
1
f
1
+ C
2
f
2
+ + C
n
f
n
is called a linear combination of functions f
1
, f
2
, , f
n
.
Definition 3.2. n functions f
1
, f
2
, , f
n
is linearly indepen-
dent over [a, b]if
C
1
f
1
+ C
2
f
2
+ + C
n
f
n
= 0 for all a t b (1)
leads to C
1
= 0, C
2
= 0, , C
n
= 0.
A set of function are linearly dependent if they are not linearly
independent.
If 0 function is one of f
1
, f
2
, , f
n
, then they linearly de-
pendent.
Two nonzero functions f(t) and g(t) are linearly dependent
over [a, b] if and only if f(t) = sg(t) for a constant s = 0
and all a t b, for example, f(t) = t and g(t) = 4t
are linearly dependent but f(t) = t and g(t) = 4t
2
are not,
even f(0) = 4g(0) and f(1) = 4g(1).
There are exists innite many functions that are linearly in-
dependent. For example the set {1, t, t
2
, t
3
, , t
n
, } is
a linearly independent set.
16 1. BRIEF INTRODUCTION TO VECTORS AND MATRICES
Here are some sets of linearly independent functions that we en-
counter in solving a system of dierential equations, assume k
1
, k
2
, , k
n
are dierent numbers,
- {t
k
1
, t
k
2
, , t
k
n
}.
- {e
k
1
t
, e
k
1
t
, , e
k
1
t
}.
- {sin(k
1
t), sin(k
2
t), , sin(k
n
t)}.
- {cos(k
1
t), cos(k
2
t), , cos(k
n
t)}.
- The mixing of above sets.
- For each above set, when multiplying each element by an com-
mon nonzero factor, we get another linearly independent set.
The following screen shot displays a heuristic Mathcad function that
tries to determine if a given set of functions are linearly independent.
Figure 5. Calculus tool bar
One warning, the result of the program is not very reliable, the user
should check the result manually to conrm the result.
To manually check if an set of functions are linearly independent
on [a, b], one need to show that the only solutions are C
1
= 0, C
2
=
0, , C
n
= 0. if equation (1) holds for all t in [a, b], which requires
strong algebraic skill.
One method is to choose n dierent numbers {t
1
, t
2
, , t
n
}
from [a, b] and using the functions to create an matrix, the compute
the determinant of the matrix A = (f
i
(t
j
)), if the determinant is not
zero, the functions are linearly independent, but if the determinant is
zero, it is inconclusive(most likely are linearly dependent).
Example 3.2. Determine if f
1
(t) = t
2
2t +3, f
2
(t) = 2t
2
5t 6, and f
3
(t) = 5t
2
11t + 4 are linearly independent.
3. LINEARLY INDEPENDENCY 17
Solution Choose t
1
= 1, t
2
= 0, and t
3
= 1,
_
_
f
1
(t
1
) f
1
(t
2
) f
1
(t
3
)
f
2
(t
1
) f
2
(t
2
) f
2
(t
3
)
f
3
(t
1
) f
3
(t
2
) f
3
(t
3
)
_
_
=
_
_
7 3 2
1 6 9
20 4 2
_
_
Compute the determinant,
_
7 3 2
1 6 9
20 4
2
_
= 50,
so the functions are linearly independent.
Project
At beginning you should enter: Project title, your name, ss#, and
due date in the following format
Project One: Dene and Graph Functions
John Doe
SS# 000-00-0000
Due: Mon. Nov. 23rd, 2003
You should format the text region so that the color of text is dierent
than math expression. You can choose color for text from Format
>Style select normal and click modify, then change the settings for
font. You can do this for headings etc.
(1) Independent of functions as vectors
Goal: Familiar your self with the concept of linearly indepen-
dency.
Use the Mathcad code provided at at the website www.unf.edu/mzhan/linearindepent.mcd
to check if given set of functions are linearly independent
or not.
{sin(x), sin(2x), sin(3x)}
{t
2
, 2t
2
2t + 4, 3t, 6}
{e
t
, te
t
, t
3
e
t
}
{e
2t
, e
t
, e
3t
}
Using algebraic arguments or reasoning to verify the con-
clusion of the Mathcad code.
18 1. BRIEF INTRODUCTION TO VECTORS AND MATRICES
(2) Condition Number In solving Ax = b, one number is very
important, it is called the condition number, which can be de-
ned as C(A) = |
s
l
, where
s
is the eigenvalue with smallest
absolute value and lambda
l
is the eigenvalue with largest ab-
solute value, if C(A) is too large or too small, a little change
in b will result in a large in the solution x. We say the system
Ax = b is not stable. Now if A =
_
_
1
1
2
1
3
1
2
1
3
1
4
1
3
1
4
1
5
_
_
Find all eigenvalues, all eigenvectors, and C(A).
Find solution of Ax = b if b =
_
_
1
1
1
_
_
Change b a little to b =
_
_
1
1
1.1
_
_
we get dierent solu-
tion, which component of the new solution change most?
The change of the third component if 10% what is the
percentage change of the most changed component?
Note:
Our denition of condition number is not accurate, the
true denition is C(A) =
1
AA
-1
where is a
given norm (metric).
Mathcad provides three functions cond1(A), cond2(A)
and condi(A) in compute condition number for A in
dierent metric.
CHAPTER 1
System of First Order Dierential Equations
In this chapter, we will discuss system of rst order dierential equa-
tions. There are many applications that involving nd several unknown
functions simultaneously . Those unknown functions are related by a
set of equations that involving the unknown functions and their rst
derivatives. For example, in Chapter Two, we studied the epidemic of
contagious diseases. Now if
S(t) denotes number of people that is susceptible to the disease
but not infected yet.
I(t) denotes number of people actually infected.
R(t) denotes the number of people have recovered.
If we assume
The fraction of the susceptible who becomes infected per unit
time is proportional to the number infected, b is the propor-
tional number.
A xed fraction rS of the infected population recovers per unit
time, 0 r 1.
A xed fraction of the recovers g become susceptible and in-
fected, 0 g 1. proportional function.
The system of dierential equations model this phenomena are
S
= bIS + gR
I
= bIS rI
R
= rI gR
The numbers of unknown function in a system of dierential equa-
tions can be arbitrarily large, but we will concentrate ourselves on 2 to
3 unknown functions.
1. Principle of superposition
Let a
ij
(t), b
j
(t) i = 1, 2, , n and j = 1, 2, , n be known
function, and x
i
t, i = 1, 2, , n be unknown functions, the linear rst
1
2 1. SYSTEM OF FIRST ORDER DIFFERENTIAL EQUATIONS
order system of dierential equation for x
i
(t) is the following,
x
1
(t) = a
11
(t)x
1
(t) + a
12
(t)x
2
(t) + + a
1n
(t)x
n
(t) + b
1
(t)
x
2
(t) = a
21
(t)x
1
(t) + a
22
(t)x
2
(t) + + a
2n
(t)x
n
(t) + b
2
(t)
x
3
(t) = a
31
(t)x
1
(t) + a
32
(t)x
2
(t) + + a
3n
(t)x
n
(t) + b
3
(t)
.
.
.
x
n
(t) = a
n1
(t)x
1
(t) + a
n2
(t)x
2
(t) + + a
nn
(t)x
n
(t) + f
1
(t)
Let x(t) be the column vector of unknown functions x
i
t, i =
1, 2, , n, A(t) = (a
ij
(t), and b(t) be the column vector of known
functions b
i
t, i = 1, 2, , n, we can write the rst order system of
equations as
x
1
(t)
x
2
(t)
_
=
_
a
11
(t) a
12
(t)
a
21
(t) a
22
(t)
_ _
x
1
(t)
x
2
(t)
_
+
_
b
1
(t)
b
2
(t)
_
When n = 3, the linear rst order system of equations for
three unknown functions in matrix form is,
_
_
x
1
(t)
x
2
(t)
x
3
(t)
_
_
=
_
_
a
11
(t) a
12
(t) a
13
a
21
(t) a
22
(t) a
23
a
31
(t) a
32
(t) a
33
_
_
_
_
x
1
(t)
x
2
(t)
x
3
t
_
_
+
_
_
b
1
(t)
b
2
(t)
b
3
(t)
_
_
A solution of equation (1) on the open interval I is a column vec-
tor function x(t) whose derivative (as a vector-values function) equals
A(t)x(t) +b(t). The following theorem gives existence and uniqueness
of solutions,
Theorem 1.1. If the vector-valued functions A(t) and b(t) are con-
tinuous over an open interval I contains t
0
, then the initial value prob-
lem
_
x
(t) = A(t)x(t),
which is called a homogeneous equation.
As in the case of one equation, we want to nd out the general
solutions for the linear rst order system of equations. To this end, we
rst have the following results for the homogeneous equation,
1. PRINCIPLE OF SUPERPOSITION 3
Theorem 1.2. Principle of Superposition Let x
1
(t), bx
2
(t), , x
n
(t)
be n solutions of the homogeneous linear equation
x
(t) = A(t)x(t)
on the open interval I. If c
1
, c
2
, , c
n
are n constants, then the
linear combination
c
1
x
1
(t) + c
2
x
2
(t) + c
3
x
3
(t) + + c
n
x
n
(t)
is also a solution on I.
Example 1.1. Let
x
(t) =
_
1 0
0 2
_
x(t)
, x
1
(t) =
_
e
t
0
_
and x
2
(t) =
_
0
e
2t
_
are two solutions, as
bx
1
(t) =
_
(e
t
)
0
_
=
_
e
t
0
_
=
_
1 0
0 2
_ _
e
t
0
_
and
bx
2
(t) =
_
0
(e
2t
)
_
=
_
0
2e
2t
_
=
_
1 0
0 2
_ _
0
e
2t
_
By the Principle of Superposition, for any two constants c
1
and c
2
x(t) = c
1
x
1
(t) + c
2
x
2
(t) = c
1
_
e
t
0
_
+ c
2
_
0
e
2t
_
=
_
c
1
e
t
c
2
e
2t
_
is also solution. We shall see that it is actually the general solution.
The next theorem gives the general solution of linear system of
equations,
Theorem 1.3.
- Let x
1
(t), x
2
(t), , bx
n
(t) be n linearly independent (as vectors)
solution of the homogeneous system
x
(t) = A(t)x(t),
then for any solution x
c
(t) there exists n constants c
1
, c
2
, , c
n
such
that
x
c
(t) = c
1
x
1
(t) + c
2
x
2
(t) + + c
n
x
n
(t).
We call x
c
(t) the general solution of the homogeneous system.
4 1. SYSTEM OF FIRST ORDER DIFFERENTIAL EQUATIONS
If x
p
(t) is a particular solution of the nonhomogeneous system,
x(t) = B(t)x(t) +b(t),
and x
c
(t) is the general solution to the associate homogeneous system,
x(t) = B(t)x(t)
then x(t) = x
c
(t) +x
p
(t) is the general solution.
Example 1.2. Let
x
(t) =
_
4 3
6 7
_
x(t) +
_
4t
2
+ 5t
6t
2
+ 7t + 1
_
x(t)
, x
1
(t) =
_
3e
2t
2e
2t
_
and x
2
(t) =
_
e
5t
3e
5t
_
are two linearly independent
solutions. and x
p
(t) =
_
t
2
t
_
is a particular solution. By Theorem
1.3,
x(t) = c
1
x
1
(t) + c
2
x
2
(t) +x
p
(t) =
_
3c
1
e
2t
+ c
2
e
5t
+ t
2
2c
1
e
2t
+ 3c
2
e
5t
+ t
_
(2)
is the general solution. Now suppose we want to nd a particular so-
lution that satises the initial condition x(0) =
_
2
1
_
, then let t = 0
in (2), we have
x(0) =
_
3c
1
+ c
2
2c
1
+ 3c
2
_
=
_
2
1
_
,
which can be written in matrix form,
_
3 1
2 3
_ _
c
1
c
2
_
=
_
2
1
_
,
Solve this equation, we get
_
c
1
c
2
_
=
_
1
1
_
. So the particular
solution is x(t) =
_
3e
2t
e
5t
+ t
2
2e
2t
3e
5t
+ t
_
.
From the above example, we can summarize the general steps in
nd a solution to initial value problem,
_
x
(t) = A(t)x(t).
Step Two: Find a particular solution x
p
(t)to the nonhomo-
geneous system, x
(t) = Ax(t)
where A is a matrix with constant entry. We will present this method
for A is either a 2 2 or 3 3 cases. The method can be used for A
is an n n matrix. The idea is to nd solutions of form
x(t) = ve
t
, (3)
a straight line that passing origin in the direction v. Now taking deriv-
ative on x(t), we have
x
(t) = ve
t
(4)
put (3) and (2.2) into the homogeneous equation, we get
x
(t) = ve
t
= Ave
t
So
Av = v,
which indicates that must be an eigenvalue of A and v is an associate
eigenvector.
2.1. A is a 2 2 matrix. Suppose
A =
_
a
11
a
12
a
21
a
22
_
Then the characteristic polynomial p() of A is
p() = |AI| = (a
11
)(a
22
)a
12
a
21
=
2
(a
11
+a
22
)+(a
11
a
22
a
12
a
22
.
So p() is a quadratic polynomial of . From Algebra, we know that
p() = 0 has either 2 distinct real solutions, or a double solution, or
2 conjugate complex solutions. The following theorem summarize the
solution to the homogeneous system,
6 1. SYSTEM OF FIRST ORDER DIFFERENTIAL EQUATIONS
Theorem 2.1. Let p() be the characteristic polynomial of A, for
x
(t) = Ax(t),
Case 1: p() = 0 has two distinct real solutions
1
and
2
.
Suppose v
1
=
_
v
11
v
21
_
and v
2
=
_
v
12
v
22
_
are associate eigen-
vector (i.e, Av
1
=
1
v
1
and Av
2
=
2
v
2
) Then the general
solution is
x
c
(t) = c
1
v
1
e
1
t
+ c
2
v
2
e
2
t
And
(t) =
_
v
11
e
1
t
v
12
e
2
t
v
21
e
1
t
v
22
e
2
t
_
is called the fundamental matrix(A fundamental matrix
is a square matrix whose columns are linearly independent so-
lutions of the homogeneous system).
Case 2: p() = 0 has a double solutions
0
.
In this case p() = (
0
)
2
and
0
is a zero of p() with
multiplicity 2.
(1)
0
has two linearly independent eigenvectors:
Suppose v
1
=
_
v
11
v
21
_
and v
2
=
_
v
12
v
22
_
are associate linearly
independent eigenvectors. Then the general solution is
x
c
(t) = (c
1
v
1
+ c
2
v
2
)e
0
t
And
(t) = e
0
t
_
v
11
v
12
v
21
v
22
_
(2)
0
has only one associate eigenvector:
Suppose v
1
=
_
v
11
v
21
_
is the only associated eigenvector and
v
2
=
_
v
12
v
22
_
is a solution of
(
0
I A)v
2
= v
1
.
Then the general solution is,
x
c
(t) = (c
1
v
1
+ c
2
(tv
1
+v
2
)e
0
t
And
(t) = e
0
t
_
v
11
(v
11
t + v
12
)
v
21
(v
21
t + v
22
)
_
is the fundamental solution matrix.
2. HOMOGENEOUS SYSTEM 7
Case 3: p() = 0 has two conjugate complex solutions a+bi and abi.
Suppose v =
_
v
11
+ iv
12
v
21
+ iv
22
_
is the associate complex eigen-
vector with respect to a + bi, then the general solution is,
v
1
=
_
v
11
v
21
_
and v
2
=
_
v
12
v
22
_
x
c
(t) = [c
1
(v
1
cos(bt) v
2
sin(bt))c
2
(v
2
cos(bt) +v
1
sin(bt))]e
at
.
And
(t) = e
at
_
v
11
cos(bt) v
12
sin(bt) v
12
cos(bt) + v
11
sin(bt)
v
21
cos(bt) v
22
sin(bt) v
22
cos(bt) + v
21
sin(bt)
_
is the fundamental matrix.
From Theorem 2.1, let (t) be the fundamental matrix, the general
solution is given by x
c
(t) = (t)c, with c =
_
c
1
c
2
_
and the solution
that satises a given initial condition x(t
0
) = x
0
is given by
x(t) = (t)(t
0
)
-t
x
0
Example 2.1. Two distinct eigenvalues case Find the general
solution to x
(t) =
_
2 3
1 5
_
x(t)
Solution Using Mathcad , functions eigenvals() and eigen-
vecs()
In Mathcad , eigenvecs(M) Returns a matrix containing the eigenvectors. The
nth column of the matrix returned is an eigenvector corresponding to the nth
eigenvalue returned by eigenvals.
we nd,
1
=
3
2
+
1
2
61 and
2
=
3
2
1
2
61
2
_
and v
2
=
_
7 +
61
2
_
respectively. So
the fundamental matrix is
(t) =
_
(7
61)e
(
3
2
+
1
2
61)t
(7 +
61)e
(
3
2
1
2
61)t
2e
(
3
2
+
1
2
61)t
2e
(
3
2
1
2
61)t
_
and the general solution is, for c =
_
c
1
c
2
_
,
x
c
(t) = (t)c
(t) =
_
2 0
0 2
_
x(t).
Solution The eigenvalue is
0
= 2 and associated eigenvectors
are
_
1
0
_
and
_
0
1
_
, so the general solution is x
c
=
_
c
1
e
2t
c
2
e
2t
_
Example 2.3. One double eigenvalues with only one eigen-
vector Find the solution to x
(t) =
_
2 3
3 8
_
x(t) and x(0) =
_
2
3
_
Solution Using Mathcad , functions eigenvals() and eigen-
vecs() we can nd a double eigenvalue
0
= 5 and eigenvector
_
.707
.707
_
.
Notice, the symbolic operator (bring up by either [Shift][Ctrl][.] or
[Ctrl][.]) will not work with eigenvecs() this time, but since multiply
an eigenvector by a nonzero constant still get an eigenvector, we can
choose v
1
=
_
3
3
_
.
To nd w that satises (A
0
I)w = v
1
0
we will solve (A
0
I)
_
w
1
w
2
_
=
_
1
1
_
. That is,
_
3 3
3 3
_ _
w
1
w
2
_
=
_
3
3
_
One solution is w
1
= 1 and w
2
= 0
So the fundamental matrix is
(t) = e
5t
_
3 3t + 1
3 3t
_
and the general solution is, c =
_
c
1
c
2
_
,
x
c
(t) = (t)c
Now, (0) = e
5(0)
_
3 3(0) + 1
3 3(0)
_
=
_
3 1
3 0
_
and (0)
-1
=
1
3
_
0 1
3 3
_
.
Hence, the particular solution is x(t) = (t)(0)
-1
x
0
= e
5t
_
3t + 4
3t 3
_
2. HOMOGENEOUS SYSTEM 9
Example 2.4. Two conjugate complex eigenvalues case Find
the general solution to x
(t) =
_
2 3
1 2
_
x(t)
Solution Using Mathcad , functions eigenvals() and eigen-
vecs() we nd two conjugate complex eigenvalues,
1
= 2 + i
3 and
2
= 2i
1
. Compare this with the Theorem 2.1, we have a = 2, b =
3, v
11
=
3, v
21
= 0, v
12
= 0, and v
22
= 1.
So the fundamental matrix is
(t) = e
2t
_
3 cos(bt) sin(bt)
3 sin(bt) cos(bt)
_
and the general solution is, c =
_
c
1
c
2
_
,
x
c
(t) = (t)c = e
2t
_
3 cos(
3t) sin(
3t)
3 sin(
3t) cos(
3t)
_ _
c
1
c
2
_
= e
2t
_
3c
1
cos(
3t) c
2
sin(
3t)
3c
1
sin(
3t) c
2
cos(
3t)
_
Suppose we want to nd a solution such that x(0) =
_
1
2
_
, then
x(t) = (t)(0)
-1
x(0)
= e
2t
_
3 cos(
3t) sin(
3t)
3 sin(
3t) cos(
3t)
_ _
3 0
0 1
_
-1
_
1
2
_
= e
2t
_
3 cos(
3t) sin(
3t)
3 sin(
3t) cos(
3t)
_ _
1
3
2
_
= e
2t
_
cos(
3t) + +2 sin(
3t)
sin(
3t) + 2 cos(
3t)
_
(t) = Ax(t),
Case 1: p() = 0 has three distinct real solutions
1
,
2
, and
3
.
Suppose v
1
=
_
_
v
11
v
21
v
31
_
_
, v
2
=
_
_
v
12
v
22
v
32
_
_
, and v
3
=
_
_
v
13
v
23
v
33
_
_
are associate eigenvector (i.e, Av
1
=
1
v
1
, Av
2
=
2
v
2
, and
Av
3
=
3
v
3
) Then the general solution is
x
c
(t) = c
1
v
1
e
1
t
+ c
2
v
2
e
2
t
+ c
3
v
3
e
3
t
And the fundamental matrix is
(t) =
_
_
v
11
e
1
t
v
12
e
2
t
v
13
e
3
t
v
21
e
1
t
v
22
e
2
t
v
23
e
3
t
v
31
e
1
t
v
32
e
2
t
v
33
e
3
t
_
_
.
Case 2: p() = 0 has a double solutions
0
.
So p() = (
0
)
2
(
1
), and
0
has multiplicity 2. Let
v
3
=
_
_
v
12
v
22
v
32
_
_
is the eigenvector associated with
1
.
[1]
0
has two linearly independent eigenvectors:
Suppose v
1
=
_
v
11
v
21
_
and v
2
=
_
v
12
v
22
_
are associate linearly
independent eigenvectors. Then the general solution is
x
c
(t) = (c
1
v
1
+ c
2
v
2
)e
0
t
+ c
3
v
3
e
1
t
And
(t) =
_
_
v
11
e
0
t
v
12
e
0
t
v
13
e
1
t
v
21
e
0
t
v
22
e
0
t
v
23
e
1
t
v
31
e
0
t
v
32
e
0
t
v
33
e
1
t
_
_
2. HOMOGENEOUS SYSTEM 11
[2]
0
has one eigenvector:
Suppose v
1
=
_
_
v
11
v
21
v
31
_
_
is the associated eigenvector with re-
spect to
0
and v
2
=
_
_
v
12
v
22
v
32
_
_
is a solution of
(
0
I A)v
2
= v
1
.
Then the general solution is,
x
c
(t) = (c
1
v
1
+ c
2
(tv
1
+v
2
))e
0
t
+ c
3
v
3
e
1
And
(t) =
_
_
v
11
e
0
t
(v
11
t + v
12
)e
0
t
v
13
e
1
v
21
e
0
t
(v
21
t + v
22
)e
0
t
v
23
e
1
v
31
e
0
t
(v
31
t + v
32
)e
0
t
v
33
e
1
_
_
is the fundamental solution matrix.
Case 3: p() = 0 has two conjugate complex solutions abi and a real
solution
1
.
Suppose v =
_
_
v
11
+ iv
12
v
21
+ iv
22
v
31
+ iv
32
_
_
is the associate complex eigen-
vector with respect to a + bi, then the general solution is, let
v
3
=
_
_
v
13
v
23
V
33
_
_
, are associated eigenvectors with respect to
1
,
x
c
(t) = [c
1
(v
1
cos(bt)v
2
sin(bt))c
2
(v
2
cos(bt)+v
1
sin(bt))]e
at
+c
3
v
3
e
1
.
And
(t) = e
at
_
_
v
11
cos(bt) v
12
sin(bt) v
12
cos(bt) + v
11
sin(bt) v
13
e
1
v
21
cos(bt) v
22
sin(bt) v
22
cos(bt) + v
21
sin(bt) v
23
e
1
v
31
cos(bt) v
32
sin(bt) v
32
cos(bt) + v
31
sin(bt) v
33
e
1
_
_
is the fundamental matrix.
Case 4: p() = 0 has solution
0
with multiplicity 3.
In this case, p() = (
0
)
3
.
[1]
0
has three linearly independent eigenvectors.
Let v
1
=
_
_
v
11
v
21
v
31
_
_
, v
2
=
_
_
v
12
v
22
V
32
_
_
, and v
3
=
_
_
v
13
v
23
V
33
_
_
be
the three linearly independent eigenvectors. Then the general
12 1. SYSTEM OF FIRST ORDER DIFFERENTIAL EQUATIONS
solution is x
c
(t) = (c
1
v
1
+ c
2
v
2
+ c
3
v
3
)e
0
t
and fundamental
matrix is (t) = e
0
t
_
_
v
11
v
12
v
13
v
21
v
22
V
23
v
31
v
32
V
33
_
_
[2]
0
has two linearly independent eigenvectors.
Suppose v
1
=
_
_
v
11
v
21
v
31
_
_
, v
2
=
_
_
v
12
v
22
V
32
_
_
are the linearly inde-
pendent eigenvectors. Let v
3
=
_
_
v
13
v
23
V
33
_
_
, then only one of the
two equations, (A
0
I)v
3
= v
1
or (A
0
I)v
3
= v
2
can
has a solution that is linearly independent with v
1
, v
2
.
Suppose (A
0
I)v
3
= v
2
generates such a solution. Then
the general solution is x
c
(t) = [c
1
v
1
+ c
2
v
2
+ c
3
(tv
2
+v
3
)]e
0
t
and fundamental matrix is (t) = e
0
t
_
_
v
11
v
12
tv
12
+ v
13
v
21
v
22
tv
22
+ V
23
v
31
v
32
tv
32
+ V
33
_
_
[3]
0
has only one eigenvector.
Let v
1
=
_
_
v
11
v
21
v
31
_
_
be the linearly independent eigenvectors.
Let v
2
=
_
_
v
12
v
22
V
32
_
_
and v
3
=
_
_
v
13
v
23
V
33
_
_
be two vectors that
satises
(A
0
I)v
2
= v
1
and (A
0
I)v
3
= v
2
.
Then the general solution is x
c
(t) = [c
1
v
1
+ c
2
(tv
1
+ v
2
) +
c
3
(t
2
v
1
+ tv
2
+ v
3
)]e
0
t
and fundamental matrix is (t) =
e
0
t
_
_
v
11
tv
11
+ v
12
t
2
v
11
+ tv
12
+ v
13
v
21
tv
21
+ v
22
t
2
v
21
+ tv
22
+ V
23
v
31
tv
31
+ v
32
t
2
v
31
+ tv
32
+ V
33
_
_
Remark 2.1. Suppose A is an n n matrix, for the homogeneous
system x
1
+ c
2
v
2
e
2
+ + c
n
v
n
e
n
2. HOMOGENEOUS SYSTEM 13
Case2: A has m < n distinct eigenvalues, in this case some eigenval-
ues would have multiplicity greater than 1.
Suppose
r
has multiplicity r. Depending on how many
linearly independent eigenvectors are associated with
r
the
situation could be very complex. Let p be the number of linearly
eigenvectors associated with
r
, then d = r p is called the
decit of
r
. The simply cases are either d = 0 or d = r 1.
When 0 < d < r 1 the situation could be very complex.
Suppose d = r 1 and v
1
is the only eigenvector associate
with
r
, then one will have to solve r 1 equations (A
r
)
i
v
i+1
= v
i
, i = 1, 2, , r 1. And the general solution
would contains terms like [c
1
v
1
+c
2
(v
1
t +v
2
) +c
3
(v
1
t
2
+v
2
t +
v
3
) + + c
r
(v
r
1
+v
2
t
r1
+ +v
r
)]e
r
.
Case 3: A complex root a+bi with associated eigenvector v
a
+iv
b
, then
the general solution contains term, [c
1
(v
a
cos(bt)v
b
sin(bt))+
c
2
(v
a
sin(bt) +v
b
cos(bt))]e
at
.
Remark 2.2. Suppose x
1
(t), x
2
(t), x
3
(t), , x
n
(t) are n linearly
independent solution for nn homogeneous system, x
1
= 3x
1
+ 4x
2
2x
3
x
2
= 2x
1
+ x
2
4x
3
x
3
= x
1
+ 2x
2
Solution Let x(t) =
_
_
x
1
(t)
x
2
(t)
x
3
(t)
_
_
and
_
_
3 4 2
2 1 4
1 2 0
_
_
The equa-
tions can be written in matrix form x
(t) = Ax(t).
Using Mathcad , functions eigenvals() and eigenvecs() we nd,
1
=
2 and
2
= 1 with associated eigenvectors v
1
=
_
_
4
1
2
_
_
and v
2
=
_
_
1
0
1
_
_
respectively. Since
1
has multiplicity 2 as 1 appeared twice
in the result of eigenvals() function, we need to solve the equation
(A
1
I)v
3
= v
2
.
14 1. SYSTEM OF FIRST ORDER DIFFERENTIAL EQUATIONS
To use Mathcad ,
(1) you rst compute (A
1
I)v
3
using the fol-
lowing sequences of key stroke,
[*] type ([Ctrl][M], set the rows and
columns in the matrix denition popup menu,
input the data for A,
[*] type -[Ctrl][M] set the row and col-
umn number and input data for
1
I,
[*] type )[Ctrl][M], now set 1 as column
number, enter a, b, c in the place holders,
[*] type [Ctrl][.] to compute symboli-
cally and you get.
(2) Using the Given Find block to nd a
solution. Type Given in a blank space, type
a+2b-c[Ctrl]= 1 and 2a-4c[Ctrl]=0 in two
rows, then type key word Find following by
typing (a,b)[Ctrl][.] you will get the solution
in terms of c.
Set c = 1, we get v
3
=
_
_
4
1
1
_
_
.
So the fundamental matrix is
(t) =
_
_
4e
2t
e
t
(t + 4)e
t
e
2t
0 e
t
2e
2t
e
t
(t + 1)e
t
_
_
and the general solution is,
x
c
(t) = c
1
v
1
e
2t
+ c
2
v
2
e
t
+ c
3
(tv
2
+v
3
)e
t
(t) =
_
_
3 0 1
2 1 1
4 0 1
_
_
x(t) and x(0) =
_
_
2
3
4
_
_
Solution Using Mathcad , functions eigenvals() (Notice the
eigenvecs() will not nd a good result in this case due to the rounding
error.) we nd,
0
= 1 is the only eigenvalue. To nd the associate
eigenvectors we compute (Using (A
0
I)v = 0)
(A
0
I)v =
_
_
2 0 1
2 0 1
4 0 2
_
_
_
_
v
1
v
2
v
3
_
_
_
_
2v
1
+ v
3
2v
1
+ v
3
4v
1
2v
3
_
_
= 0
2. HOMOGENEOUS SYSTEM 15
We have only 2v
1
+ v
3
= 0 for three variables v
1
, v
2
, v
3
, this indicates
that v
2
can be any value, and set v
1
= 1 nd v
3
= 2, So v
1
=
_
_
1
0
2
_
_
and v
2
=
_
_
1
1
2
_
_
are two eigenvectors.
To nd the generalize eigenvector associated with
0
we will have
to solve two equations
(A
0
I)
_
_
w
1
w
2
w
3
_
_
=
_
_
1
0
2
_
_
,
and
(A
0
I)
_
_
w
1
w
2
w
3
_
_
=
_
_
1
1
2
_
_
,
From (2.2),
_
_
2 0 1
2 0 1
4 0 2
_
_
_
w
1
w
2
_
=
_
_
1
0
2
_
_
,
we get two inconsistent equations 2w
1
+ w
3
= 1 and 2w
1
+ w
3
= 0. So
now solution can be found in this case.
From (2.2),
_
_
2 0 1
2 0 1
4 0 2
_
_
_
w
1
w
2
_
=
_
_
1
1
2
_
_
,
we get one equation 2w
1
+ w
3
= 1 choose w
3
= 1 we get w
1
= 0, since
w
2
can be anything, we set w
2
= 1. So v
3
=
_
_
0
1
1
_
_
and we can verify
that v
1
, v
2
, and v
3
are linearly independent.
So the fundamental matrix is
(t) = e
t
_
_
1 1 t
0 1 t + 1
2 2 2t + 1
_
_
and the general solution is,
x
c
(t) = [c
1
v
1
+ c
2
v
2
+ c
3
(tv
2
+v
3
)]e
t
16 1. SYSTEM OF FIRST ORDER DIFFERENTIAL EQUATIONS
Now, (0) =
_
_
1 1 0
0 1 1
2 2 1
_
_
and (0)
-1
_
_
2
3
4
_
_
=
_
_
1
3
0
_
_
.
Hence, the particular solution is x(t) = [v
1
+ 3v
2
]e
t
(t) =
_
_
2 1 0
1 4 1
2 2 3
_
_
x(t).
Solution Using Mathcad , functions eigenvals() (Notice the
eigenvecs() will not nd a good result in this case due to the rounding
error.) we nd,
0
= 3 is the only eigenvalue. To nd the associate
eigenvectors we compute (Using (A
0
I)v = 0)
(A3I)v =
_
_
1 1 0
1 1 1
2 2 0
_
_
_
_
v
1
v
2
v
3
_
_
_
_
v
1
+ v
2
+ v
3
v
1
+ v
2
+ v
3
2v
1
2v
2
_
_
= 0
We have only one eigenvector v
1
=
_
_
1
1
2
_
_
.
To nd the generalize eigenvector associated with
0
we will have
to solve two equations
(A3I)v
2
= v
1
,
and
(A3I)v
3
= v
2
,
From (2.2),
_
_
1 1 0
1 1 1
2 2 0
_
_
_
_
a
b
c
_
_
=
_
_
1
1
2
_
_
,
we have two equations
_
b a = 1
a + b + c = 1
Choosing a = 0, we get b = 1, c = 0. Hence v
2
=
_
_
0
1
0
_
_
2. HOMOGENEOUS SYSTEM 17
From (2.2),
_
_
1 1 0
1 1 1
2 2 0
_
_
_
_
a
b
c
_
_
=
_
_
0
1
0
_
_
,
we have two equations
_
b a = 0
a + b + c = 1
Choosing a = 0, we get b = 0, c = 1. So v
3
=
_
_
0
0
1
_
_
and we can verify
that v
1
, v
2
, and v
3
are linearly independent.
So the fundamental matrix is
(t) = e
t
_
_
1 t t
2
1 1 + t t
2
+ t
2 2t 2t
2
+ 1
_
_
and the general solution is,
x
c
(t) = [c
1
v
1
+ c
2
(tv
1
+v
2
) + c
3
(t
2
v
1
+ tv
2
+v
3
)]e
3t
(t) =
_
_
1 1 3
2 0 3
1 0 1
_
_
x(t)
Solution Using Mathcad , functions eigenvals() and eigen-
vecs() we nd two conjugate complex eigenvalues and one real eigen-
value,
1
= 1,
2
=
1
2
+ i
1
2
19, and
3
=
1
2
i
1
2
19 with associ-
ated eigenvector v
1
=
_
_
0
1
1
_
_
and v =
_
_
1 + i
19
2 + i
19
2
_
_
=
_
_
1
2
2
_
_
+
i
_
_
19
19
0
_
_
with respect to
3
. Compare this with the Theorem 1.3,
18 1. SYSTEM OF FIRST ORDER DIFFERENTIAL EQUATIONS
we have a =
1
2
, b =
1
2
19, v
2
=
_
_
1
2
2
_
_
(real part of v), and v
3
=
_
_
19
19
0
_
_
(imaginary part of v).
The general solution is,
x
c
(t) = c
1
v
1
e
t
+c
2
(v
2
cos(
1
2
19)v
3
sin(
1
2
19))e
1
2
t
+c
3
(v
2
sin(
1
2
19)+v
3
cos(
1
2
19))e
1
2
t
(t) = Ax(t)
(3) The general solution to the nonhomogeneous equation x
(t) =
Ax(t) is x(t) = x
c
(t) + x
p
(t). Using x(t
0
) = x
0
to determine
the coecient vector c.
The following theorem gives one way to nd a particular solution based
on the fundamental matrix,
Theorem 3.1. Let (t) be a fundamental matrix of x
(t) = Ax(t),
a particular solution to x
1
= 3x
1
+ 4x
2
2x
3
+ t
2
x
2
= 2x
1
+ x
2
4x
3
x
3
= x
1
+ 2x
2
t
2
Solution Let x(t) =
_
_
x
1
(t)
x
2
(t)
x
3
(t)
_
_
, A =
_
_
3 4 2
2 1 4
1 2 0
_
_
, and
b(t) =
_
_
t
2
0
t
2
_
_
. The equations can be written in matrix form x
(t) =
3. NONHOMOGENEOUS SYSTEM OF EQUATIONS 19
Ax(t)+b(t). From Example 2.5, we know that the fundamental matrix
to x(t) = Ax(t) is
(t) =
_
_
4e
2t
e
t
(t + 4)e
t
e
2t
0 e
t
2e
2t
e
t
(t + 1)e
t
_
_
To nd a particular solution, we rst compute
-1
(t)b(t) =
_
_
2
5
t
2
e
2t
(
2
5
t
3
+
11
5
t
2
)e
t
2
5
t
2
e
t
_
_
then we compute
(t)
_
-1
(t)b(t) dt = (t)
_
_
_
2
5
t
2
e
2t
dt
_
(
2
5
t
3
+
11
5
t
2
)e
t
dt
_
2
5
t
2
e
t
dt
_
_
=
_
_
1
5
t
2
+ 2t +
16
5
1
5
t
2
3
5
t
7
10
9
5
t
2
+
24
5
t +
29
5
_
_
.
And so the general solution is,
x(t) = c
1
_
_
4
1
2
_
_
e
2t
+ c
2
_
_
1
0
1
_
_
e
t
+ c
3
_
t
_
_
1
0
1
_
_
+
_
_
4
1
1
_
_
_
e
t
+
_
_
1
5
t
2
+ 2t +
16
5
1
5
t
2
3
5
t
7
10
9
5
t
2
+
24
5
t +
29
5
_
_
The following is a screen shot that shows how to carry out the compu-
tation in Mathcad ,
To use Mathcad ,
(1) Dene fundamental ma-
trix A(t) and b(t) in the
same line (not as shown in
graph), and compute in the
next line A
1
b(t)
(2) type A(t)*[Ctrl][M] choose
column as 1, at each place
holder, type [Ctrl][I] to get
the indenite integral,
(3) and put the corresponding
entry of A
1
b(t) in the in-
tegrant position.
(4) press [Shift][Ctrl][.] type
key work simplify
(t) = Ax(t),
, and x
p
(t) =
_
-1
(t)b(t) dt, then x(t) = (t)
-1
(t
0
)(x
0
x
p
(t
0
)) +
x
p
(t) is the solution to the nonhomogeneous initial value problem,
x
(t) =
_
2 3
3 8
_
x(t) +
_
e
2t
2e
2t
_
and x(0) =
_
2
1
_
Solution From Example 2.3 is the fundamental matrix is
(t) = e
5t
_
3 3t + 1
3 3t
_
and (0)
-1
=
1
3
_
0 1
3 3
_
.
Now b(t) =
_
e
2t
2e
2t
_
, using the formula x
p
(t) = (t)
_
-1
(t)b(t) dt
and Mathcad , we have x
p
(t) =
_
0
1
3
e
2t
_
Therefore,
(0)
-1
(x(0) x
p
(0)) =
1
3
_
0 1
3 3
_
_
_
2
1
_
_
0
1
3
_
_
=
_
2
3
8
_
.
and the solution is
x(t) = (t)(0)
-1
(x(0) x
p
(0)) +x
p
(t) = e
5t
_
24t 6
24t 2 +
1
3
e
3t
_
(t) + cx
1
(t) = x
2
(t) (5)
x
2
(t) =
c
m
x
2
(t)
k
m
x
1
(t) +
f(t)
m
(6)
In general, if we have an dierential equation that involving nth
order derivative x
(n)
(t) of unknown function x(t),
x
(n)
= a
0
x(t) + a
1
x
(t) + + a
n1
x
(n1)
+ f(t),
we can transform it into an system of rst order equations of n unknown
functions x
1
(t) = x(t), x
2
(t) = x
(t), x
3
(t) = x
(2)
(t), , x
n
(t) =
x
(n1)
(t), and using the eigenvalue method for system of dierential
equation to solve the higher order equation.
Example 4.1. Transform the dierential equation x
(3)
+ 3x
(2)
7x
(t), x
3
(t) = x
(t), we have
x
1
(t) = x
2
(t) (7)
x
2
(t) = x
3
(t) (8)
x
3
(t) = 3x
3
(t) + 7x
2
(t) + 9x
1
(t) sin(t) (9)
Let x(t) =
_
_
x
1
(t)
x
2
(t)
x
3
(t)
_
_
, A =
_
_
1 0 0
0 1 0
9 7 3
_
_
, and b(t) =
_
_
0
0
f(t)
_
_
we can write the system of equation in matrix form x
(t) = Ax(t) +
b(t).
Example 4.2. Find the general solution for the 3rd order dieren-
tial equation x
(3)
+ 3x
(2)
7x
(t) 9x = sin(t).
Solution From previous example, Example 4.1, Let x(t) =
_
_
x
1
(t)
x
2
(t)
x
3
(t)
_
_
, A =
_
_
1 0 0
0 1 0
9 7 3
_
_
, and b(t) =
_
_
0
0
f(t)
_
_
we can write
the system of equation in matrix form x
10,
3
=
1
10
11 2
10
_
_
,
22 1. SYSTEM OF FIRST ORDER DIFFERENTIAL EQUATIONS
and v
3
=
_
_
1
1
10
11 + 2
10
_
_
respectively (after multiply the results of
Mathcad by some constants). So the fundamental matrix is
(t) =
_
_
e
t
e
(1+
10)t
e
(1+
10)t
e
t
(1 +
10)e
(1+
10)t
(1 +
10)e
(1+
10)t
e
t
(11 2
10)e
(1+
10)t
(11 + 2
10)e
(1+
10)t
_
_
From (t) we nd a particular solution
x
p
(t) = (t)
_
-1
(t)b(t) dt =
_
_
3
52
cos(t)
5
39
sin(t)
1
26
cos(t)
35
156
sin(t)
3
52
cos(t)
8
39
sin(t)
_
_
Hence the general solution to the system is
_
_
x
1
(t)
x
2
(t)
x
3
(t)
_
_
=
_
_
c
1
e
t
+ c
2
e
(1+
10)t
+ c
3
e
(1+
10)t
+
3
52
cos(t)
5
39
sin(t)
c
1
e
t
+ c
2
(1 +
10e
(1+
10)t
c
3
(1 +
10)e
(1+
10)t
+
1
26
cos(t)
35
156
sin(t)
c
1
e
t
+ c
2
(11 2
10)e
(1+
10)t
+ c
3
(11 + 2
10)e
(1+
10)t
3
52
cos(t)
8
39
sin(t)
_
_
and x
1
(t) = c
1
e
1t
+ c
2
e
(1+
10)t
+ c
3
e
(1+
10)t
+
3
52
cos(t)
5
39
sin(t) is
the general solution to the third order ordinary dierential equation
x
(3)
+ 3x
(2)
7x
(t) 9x = sin(t)
.
Example 4.3. Find the solution to the initial value problem
x
10x
+ 9x = te
t
, x(0) = 1, x
(0) = 1.
Solution Since the given equation is of second order, we will have
two unknowns x
1
(t) = x(t), x
2
(t) = x
1
(t) = x
2
x
2
(t) = 10x
2
9x
1
+ te
t
,
and the initial conditions are x
1
(0) = x(0) = 1 x
2
(0) = x
(0) = 1.
Now let x(t) =
_
x
1
(t)
x
2
(t)
_
, A =
_
0 1
9 10
_
, and b(t) =
_
0
te
t
_
.
We have the matrix version of this equation, x
1
512
(32t
2
+ 72t + 9)e
t
_
The solution with initial values x
0
=
_
1
1
_
is given by
x(t) = (t)
-1
(0)(x
0
b(0)) +b(t)
=
_
_
_
1
16
t
2
1
64
t +
639
512
_
e
t
127
512
e
9t
_
1
16
t
2
9
64
t +
631
512
_
e
t
1143
512
e
9t
_
_
.
Hence the solution to the initial value problem of the second order
dierential equation is x(t) = x
1
(t) =
_
1
16
t
2
1
64
t +
639
512
_
e
t
127
512
e
9t
.
Project
At beginning you should enter: Project title, your name, ss#, and
due date in the following format
Project One: Dene and Graph Functions
John Doe
SS# 000-00-0000
Due: Mon. Nov. 23rd, 2003
You should format the text region so that the color of text is dierent
than math expression. You can choose color for text from Format
>Style select normal and click modify, then change the settings for
font. You can do this for headings etc.
(1) Solutions To System of Equations
Finding solution to linear system using Mathcad and study
the long time dynamic behavior of the solutions.
Find general solution to
_
x
= y
y
= x
24 1. SYSTEM OF FIRST ORDER DIFFERENTIAL EQUATIONS
Plot several solutions with dierent initial values in
[-] xt-plane, yt-plane
xy-plane. Here you will need to dene range variable
t = 0, 0.1 7 and set X := x(t), Y := y(t). The graph
in xy-plane is called the trajectory. If this models the
movement of a satellite, what is its trajectory.
Find general solution to
_
x
= 8y
y
= 18x
Plot several solutions with dierent initial values in
[-] xt-plane, yt-plane
xy-plane. Here you will need to dene range variable
t = 0, 0.1 7 and set X := x(t), Y := y(t). The graph
in xy-plane is called the trajectory. If this models the
movement of a satellite, what is its trajectory.
Find general solution to
_
x
= 2x y
y
= y 3x
Plot several solutions with dierent initial values in
[-] xt-plane, yt-plane
xy-plane. Here you will need to dene range variable
t = 0, 0.1 7 and set X := x(t), Y := y(t). The graph
in xy-plane is called the trajectory. If this models the
movement of a system of two species, what is you con-
clusion about interdependency of these species? Can you
nd initial value such that x(t) = 0 (distinct) for some t?
what about y(t).
(2) Solution of Higher order equation In general mx
+cx
+
kx = f(t) models a object with mass m attached to a spring
with constant k and damping force that is proportional to
the velocity x
2
CHAPTER 1
Numerical Methods for Ordinary Dierential
Equations
In this chapter we discuss numerical method for ODE . We will
discuss the two basic methods, Eulers Method and Runge-Kutta
Method.
1. Numerical Algorithm and Programming in Mathcad
1.1. Numerical Algorithm. If you look at dictionary, you will
the following denition for algorithm,
1. a set of rules for solving a problem in a nite
number of steps; 2. a sequence of steps designed for
programming a computer to solve a specic problem.
A numerical algorithm is a set of rules for solving a problem in nite
number of steps that can be easily implemented in computer using any
programming language. The following is an algorithm for compute the
root of f(x) = 0,
Input f, a, N and tol .
Output: the approximate solution to f(x) = 0 with
initial guess a or failure message.
Step One: Set x = a
Step Two: For i=0 to N do Step Three - Four
Step Three: Compute x = x
f(x)
f
(x)
Step Four: If f(x) tol return x
Step Five return failure.
In analogy, a numerical algorithm is like a cook recipe that specify the
input cooking material, the outputthe cooking product, and steps
of carrying computation cooking steps.
In an algorithm, you will see loops (for, while), decision making
statements(if, then, else(otherwise)) and return statements.
for loop: Typically used when specic number of steps need
to be carried out. You can break a for loop with return or
break statement.
1
2 1. NUMERICAL METHODS FOR ORDINARY DIFFERENTIAL EQUATIONS
while loop: Typically used when unknown number of steps
need to be carried out. You can break a while loop with a
break statement or a return statement.
if else(otherwise): Used when condition(s) must meet be-
fore carrying out some steps. The else(otherwise) provide al-
ternative steps if any.
1.2. Programming in Mathcad. To translate a numerical al-
gorithm into a program in Mathcad , you need to dene a function
name with function arguments and function body. The function
name can be any sequence of alphabetic letter begin with an English
letter, such any myFunction, Myfunction1 etc. The function ar-
guments specify the input to the function, typically the items specied
in the input statement of an algorithm and is an comma(,) separated
list enclose by () after function name, such as myFunction(f, a, N, tol),
myOne(a,b). Notice the function argument is optional, you can dene
a function with out argument as myFunction(). The function body
implements the step section of an algorithm and the output statement.
In Mathcad the function body is on the right side of := with vertical
bars as grouping symbol. The entire function body is considered as
a group, inside, it might has many subgroups. For the algorithm of
nding f(x) = 0, there is an subgroup that contains step three and
four, as shown in the following screen shot, the screen shot also shows
how to get the programming toolbar from the math toolbar.
Figure 1. mySolver and Programming toolbar
1. NUMERICAL ALGORITHM AND PROGRAMMING IN Mathcad 3
To enter code in Mathcad ,
(1) First enter the function name with arguments list and assignment operator
:=, with sequence of typing,
mySolver(f,a,N,tol):
(2) Click the Add Line button or press ] to get a vertical bar and two (you
should add more by press ] several times).
(3) enter x and hold [Shift] type ] to get the local assignment or click on the
programming toolbar, at the type a. Notice x a reads as assign a to x.
(4) Click for on the programming menu or [Shift][Ctrl][] to get
for
in after for enter i, in after , enter 1;N, and in under for, press left
bracket ] to get a vertical line and several .
(5) To get if operator, you need either click on the toolbar or press [Shift][Ctrl][
] ]. you will get
if
enter condition in after if and other statements in before if.
(6) To get return operator, you need either click on the toolbar or press
[Shift][Ctrl][ ], you get
return
in type any information you want to return.
After dening a function, we call it with concrete input data, as
shown in the screen shot, that call the mySolver function to nd zero
for both f(x) = x
2
1, with initial guess x = 2 and g(t) = t
3
3t
2
2t,
with initial guess t = 2. Notice there is two ways to call a function,
one way is to dene all arguments before calling the function, another
is to dene some arguments and call the function with concrete values
for the undened arguments.
As in all programming language, Mathcad allows you to call one
function from within another. For example, we could create a function
called myDerivative which will compute derivative of a given func-
tion f(x) at a given number x and step size h > 0 using the forward
dierence formula: f
(s)
f(x+h)f(x)
h
. The following screen shot shows
the call of myDerivative inside mySolver,
Figure 2. Call another function
4 1. NUMERICAL METHODS FOR ORDINARY DIFFERENTIAL EQUATIONS
The algorithm for this function is very simple (here, we break down
the computation in three steps),
Input f, x, and h .
Output: the approximation to f
(x) .
Step One: Set w = f(x + h)
Step Two: Set d = f(x)
Step Three: return
wd
h
2. Eulers Method
2.1. Eulers Method. Eulers method is the simplest method in
nd approximate solutions to rst order equations. From the forward
dierence formula
f
(x)
f(x + h) f(x)
h
,
we have
f(x + h) f(x) + f
(x)h (1)
Now if x
(t) = t
2
e
x
sin(t), x(0) =
1 with h = 0.25.
Solution Here the interval is [0, 1], so a = 0, b = 1. Since h =
ba
n
= 0.25 we have n = 4 and we need to compute x
1
, x
2
, x
3
, x
4
starting
with x
0
= x(0) = 1.
x
1
= x
0
+ f(t
0
, x
0
)h = 1 + f(0, 1) 0.25 = 0.15853
x
2
= x
1
+ f(t
1
, x
1
)h = 0.15853 + f(0.25, 0.15853) 0.25 = 0.01833
x
3
= x
2
+ f(t
2
, x
2
)h = 0.01833 + f(0.5, 0.01833) 0.25 = 0.23811
x
4
= x
3
+ f(t
3
, x
3
)h = 0.23811 + f(0.75, 0.15853) 0.25 = 0.30128
So the approximation to x(1) is x(1) x
4
= 0.30128. Also x(0.25)
x
1
= 0.15853, x(0.5) x
2
= 0.01833, x(0.75) x
3
= 0.23811.
2. EULERS METHOD 5
2.2. Mathcad implementation of Eulers Method. First, we
have the following simple algorithm for the Eulers method,
Input f, a, b, x0 n.
Output: the approximate solution to x
= f(t, x)
with initial guess x0 over interval [a, b].
Step One: Initialization
Set h =
ba
n
Set x
0
= x0
Set t
0
= a
Step Two: For i=1 to n do Step Three
Step Three: Set x
i
= x
i1
f(t
i1
, x
i1
) h
Set t
i
= t
i1
+ h
Step Four return x.
Notice, algorithm return an array of values, the ith element of the
return array is an approximations of x(t) at t = a + ih.
The following screen shot shows Mathcad code for implementing
the algorithm. Notice, we also create a function tMesh(a, b, N) to
compute the ending of subinterval for graphing purpose.
Figure 3. Mathcad code for Eulers Method
Notice the line to line corresponding between the Mathcad and the
algorithm. Since Mathcad programming language is a scripting lan-
guage, the translation between algorithm and code is straight forward,
and you dont need to worry about the variable type, io, etc. Also,
without explicit return statement, the result of last is, by default, will
be returned.
6 1. NUMERICAL METHODS FOR ORDINARY DIFFERENTIAL EQUATIONS
The next screen shot shows a call to the myEuler and tMesh for
the equation x
= t
2
x + t
2
sin(t
3
). It also shows the graph of approxi-
mate solution comparing with the exact solution x(t) =
3
10
cos(t
3
)
1
10
sin(t
3
) +
3
10
e
1
10
t
3
Figure 4. Mathcad Eulers Approximation to x
= t
2
x + t
2
sin(t
3
)
2.3. Error analysis of Eulers Method. There are two source
of error in every numerical method used to approximate a solution of
x
(t)| M.
Theorem 2.2 indicates that, without roundo error, the smaller h
gives better approximate solution. However, due the roundo error
introduced in each step of computation, (such as compute can only
give approximate value for
2
M
3. Runge-Kutta Method
3.1. Runge-Kutta Method. There are several Runge-Kutta meth-
ods, but the fourth order Runge-Kutta method is most popular. Sup-
pose x
(t) = t
2
e
x
sin(t), x(0) =
1 with h = 0.25.
Solution Here the interval is [0, 1], so a = 0, b = 1. Since
h =
ba
n
= 0.25 we have n = 4 and we need to compute x
1
, x
2
, x
3
, x
4
starting with x
0
= x(0) = 1, t
0
= 0
8 1. NUMERICAL METHODS FOR ORDINARY DIFFERENTIAL EQUATIONS
x
1
:
k
1
= hf(t
0
, x
0
) = 0.25 f(0, 1) = 0
k
2
= hf(t
0
+
1
2
h, x
0
+
1
2
k
1
) = f(0.125, 1) = 0.373276
k
3
= hf(t
0
+
1
2
h, x
0
+
1
2
k
2
)
= 0.25f(0.125, 1 + 0.5(0.373276)) = 0.373276
k
4
= hf(t
0
+ h, x
0
+ k
3
) = 0.25f(0.25, 1 0.373276) = 0.309854
x
1
= x
0
+
1
6
(k
1
+ 2k
2
+ 2k
3
+ k
4
)
= 1 +
1
6
(0 + 2 (0.373276) + 2 (0.373276) 0.309854)
= 0.923911
t
1
= t
0
+ h = 0 + 0.25 = 0.25
x
2
:
k
1
= hf(t
1
, x
1
) = 0.25 f(.25, 0.923911) = 0.560741
k
2
= hf(t
1
+
1
2
h, x
1
+
1
2
k
1
)
= f(0.125, 0.923911 + 0.5(0.560741)) = 0.719601
k
3
= hf(t
1
+
1
2
h, x
1
+
1
2
k
2
)
= 0.25f(0.125, 0.923911 + 0.5(0.719601)) = 0.702688
k
4
= hf(t
1
+ h, x
1
+ k
3
)
= 0.25f(0.5, 0.923911 0.702688) = 0.763158
x
2
= x
1
+
1
6
(k
1
+ 2k
2
+ 2k
3
+ k
4
)
= 0.923911 +
1
6
(0.560741 + 2 (0.719601) + 2 (0.702688) 0.763158)
= 0.750224
t
2
= t
1
+ h = 0.25 + 0.25 = 0.5
x
3
:
k
1
= hf(t
2
, x
2
) = 0.25 f(.5, 0.750224) = 0.765171
k
2
= hf(t
2
+
1
2
h, x
2
+
1
2
k
1
)
= f(0.625, 0.750224 + 0.5(0.765171)) = 0.735295
k
3
= hf(t
2
+
1
2
h, x
2
+
1
2
k
2
)
= 0.25f(0.625, 0.750224 + 0.5(0.735295)) = 0.739508
k
4
= hf(t
2
+ h, x
2
+ k
3
)
= 0.25f(0.75, 0.750224 0.739508) = 0.637224
x
3
= x
2
+
1
6
(k
1
+ 2k
2
+ 2k
3
+ k
4
)
= 0.750224 +
1
6
(0.765171 + 2 (0.735295) + 2 (0.739508) 0.637224)
= 0.568891
t
3
= t
2
+ h = 0.5 + 0.25 = 0.75
3. RUNGE-KUTTA METHOD 9
x
4
:
k
1
= hf(t
3
, x
3
) = 0.25 f(0.75, 0.568891) = 0.641483
k
2
= hf(t
3
+
1
2
h, x
3
+
1
2
k
1
)
= f(0.875, 0.568891 + 0.5(0.641483)) = 0.485628
k
3
= hf(t
3
+
1
2
h, x
3
+
1
2
k
2
)
= 0.25f(0.875, 0.568891 + 0.5(0.485628)) = 0.510243
k
4
= hf(t
3
+ h, x
3
+ k
3
)
= 0.25f(1, 0.568891 0.510243) = 0.308297
x
4
= x
3
+
1
6
(k
1
+ 2k
2
+ 2k
3
+ k
4
)
= 0.568891 +
1
6
(0.641483 + 2 (0.485628) + 2 (0.510243) 0.308297)
= 0.446327
t
4
= t
3
+ h = 0.75 + 0.25 = 1.0
So the approximation to x(1) is x(1) x
4
= 0.446327.
3.2. Mathcad implementation. First, we have the following sim-
ple algorithm for the Eulers method,
Input f, a, b, x0 n.
Output: the approximate solution to x
= f(t, x)
with initial guess x0 over interval [a, b].
Step One: Initialization
Set h =
ba
n
Set x
0
= x0
Set t
0
= a
Step Two: For i=1 to n do Step Three
Step Three:
Set k1 = hf(t
i1
, x
i1
)
Set k2 = hf(t
i1
+
1
2
h, x
i1
+
1
2
k
1
)
Set k3 = hf(t
i1
+
1
2
h, x
i1
+
1
2
k
2
)
Set k4 = hf(t
i1
+ h, x
i1
+ k
3
)
Set x
i
= x
i
+
1
6
(k
1
+ 2k
2
+ 2k
3
+ k
4
)
Set t
i
= t
i1
+ h
Step Four return x.
This algorithm returns an array of values, the ith element of the
return array is an approximations of x(t) at t = a + ih.
The following screen shot shows Mathcad code for implementing
the algorithm. Again notice the line to line corresponding between the
Mathcad and the algorithm.
10 1. NUMERICAL METHODS FOR ORDINARY DIFFERENTIAL EQUATIONS
Figure 5. Mathcad code for Eulers Method
The next screen shot shows a call to the myRungeKutta and tMesh
for the equation x
= t
2
x+t
2
sin(t
3
). It also shows the graph of approx-
imate solution comparing with the exact solution x(t) =
3
10
cos(t
3
)
1
10
sin(t
3
) +
3
10
e
1
10
t
3
, and with the approximate solution using Eulers
method. In this case Runge-Kutta provides much superior result, an
almost exact match!
Figure 6. Mathcad Runge-Kuttas Approximation to x
= t
2
x + t
2
sin(t
3
)
4. NUMERICAL METHOD FOR SYSTEM OF EQUATIONS 11
4. Numerical Method for System of Equations
Both Eulers method and Runge-Kutta method can be used to nd
the approximate solution to the system of rst order dierential equa-
tions. In fact, the Mathcad codes for system of rst dierential equa-
tions are exactly the same as Mathcad does not dierentiate scalar and
vectors when performs most computations. The only thing needs to be
taken care is that at each step the result is vector instead of a scalar.
Suppose x(t) is a vector-valued function that satises
x
(t) = t
2
sin(x(t)) + e
t
cos(y(t))
y
(t) = 2tx(t) + e
y(t)
x(0) = 1, y(0) = 1
Find approximate solution for x(t), y(t) over interval [0, 1] with h =
0.1
Solution Set x(t) =
x(t)
y(t)
and F(t, x) =
t
2
sin(x) + e
t
cos(y)
2tx + e
y
1
1
1
1
t
2
0
sin(x
0
) + e
t
0
cos(y
0
)
2t
0
x
0
+ e
y
0
cos(1)
e
1
The following screen shot shows the results obtain by calling our
Mathcad implementation of Eulers method. Notice that in dening
the vector-valued function F(t, X), for Mathcad to know that X is an
vector, in the denition, we use subscript to access the component of
X, as shown in the screen shot.
12 1. NUMERICAL METHODS FOR ORDINARY DIFFERENTIAL EQUATIONS
Figure 7. Eulers method for system of equations
+ kx = ax
b(x
)
3
Find approximate solution for m = 1, k = 1, a = 2, b = 3. and initial
conditions x(0) = 1, x
(0) = 2
14 1. NUMERICAL METHODS FOR ORDINARY DIFFERENTIAL EQUATIONS
Solution Suppose y(t) = x
= y
y
= 2y 3y
3
2x
So we apply the numerical method for F =
y
2y 3y
3
2x
and
x
x(t) = x(t)
y(t)
, x(0) =
1
2
. The following
screen shot gives approximate solution using Runge-Kutta method,
Figure 9. Runge-Kuttas method for Rayleighs equation
f)(t) = f(t).
Theorem 1.3. If both
f(s) and g(s) exist for all s > c, then af(t)+
bg(t) has Laplace transform for all constant a and b and
af + bg(s) = a
(s) = s
f(s) f(0).
Now if nth derivative f
n
(t) is piecewise smooth, then
f
(n)
(s) = s
n
f(s) s
n1
f(0) s
n2
f
(0) f
(n1)
(0).
For example,
When n = 2
f
(2)
(s) = s
2
f(s) sf(0) f
(0).
When n = 3
f
(3)
(s) = s
3
f(s) s
2
f(0) sf
(0) f
(0).
When n = 4
f
(4)
(s) = s
4
f(s) s
3
f(0) s
2
f
(0) sf
(0) f
(3)
(0).
The following table list most commonly used functions, and
u
a
(t) = u(t a) =
_
0 if t < a
1 if t a
is the Heaviside function.
1. THE LAPLACE TRANSFORM 3
f = L
1
(
f)
f f = L
1
(
f)
f
1
1
s
(s > 0) t
1
s
2
(s > 0)
t
n
(n 0)
n!
s
n+1
(s > 0) t
a
(a > 1)
(a+1)
s
a+1
(s > 0)
e
at 1
sa
(s > 0) sin(kt)
k
s
2
+k
2
(s > 0)
cos(kt)
s
s
2
+k
2
(s > 0) sinh(kt)
k
s
2
k
2
(s > |k|)
cosh(kt)
s
s
2
k
2
(s > |k|) u(t a)
e
as
s
(s > 0)
Example 1.1. Find x(s) if x
+2x
3x = e
t
, x(0) = 1, x
(0) = 1.
Solution Apply Laplace transform on both side of the equation,
L(x
+ 2x
3x)(s) = L(e
t
)(s)
Using the linear property
af + bg(s) = a
+ 2x
3x)(s) =
x
(s) + 2
(s) 3 x(s).
Together with
x
(s) = s
2
x(s) sx(0) x
(0) and
x
(0) = 1,
L(x
+ 2x
3x)(s) =
x
(s) + 2
(s) 3 x(s)
= [s
2
x(s) sx(0) x
2. Using Mathcad
Mathcad can help us in nd both Laplace transform and inverse
Laplace transform.
To use Mathcad to nd Laplace transform, we rst enter the expres-
sion of the function, then press [Shift][Ctrl][.], in the place holder type
the key word laplace followed by comma(,) and the variable name.
For example, to nd the Laplace of f(t) = t
2
sin(at), you rs enter the
expression t
2
sin(at) by typing,
t^2*sin(a*t),
then press [Shift][Ctrl][.], and entering keyword laplace followed by
comma(,) and t, you will get
t
2
sin(at)laplace, t
8as
2
(s
2
+ a
2
)
3
2a
(s
2
+ a
2
)
2
If you want a simplied result, you type comma(,) after entering
the variable name and keyword simplify, so the following input
t^2*sin(a*t)[Shift][Ctrl][.]laplace,t,simplify
will produce the result
t
2
sin(at)laplace, t, simplify
2a(a
2
3s
2
)
(s
2
+ a
2
)
3
Similarly, to use Mathcad to nd inverse Laplace transform, we rst
enter the expression, then press [Shift][Ctrl][.], in the place holder type
the key word invlaplace followed by comma(,) and the variable name.
For example, to nd the inverse Laplace of
8as
2
(s
2
+a
2
)
3
, you rs enter the
expression
8as
2
(s
2
+a
2
)
3
as,
8a*s^2/(s^2+a^2)^3,
then press [Shift][Ctrl][.], and entering keyword invlaplace followed by
comma(,) and s, and for simplifying the result, by another comma(,)
and keyword simplify, we get
8as
2
(s
2
+ a
2
)
3
invlaplace, s, simplify
1
a
2
_
sin(at)ta cos(at)+t
2
a
2
sin(at)
_
2. USING Mathcad 5
When using Mathcad together with Laplace transform to solve an
ODE
a
n
x
(n)
+ a
n1
x
(n1)
+ + a
1
x
+ a
0
x = f(t)
we follow these steps,
Step One: Apply Laplace to both sides of equation. Using
Mathcad to nd Laplace transform of f(t).
Step Two: Using the linear property and
f
(n)
(s) = s
n
f(s) s
n1
f(0) s
n2
f
(0) f
(n1)
(0).
to nd an algebraic equation for x(s),
Step Three: Solve the equation obtained in Step Two for
x(s) and using Mathcad to nd inverse transform which will
be the solution x(t).
Example 2.1. Find general solution to x
+ 2x
+ 3x = t
2
e
t
.
Solution Since we want to nd general solution, we set x(0) = a
and x
(0) = b
Step One Apply Laplace transform to both sides of the equa-
tion and nd Laplace transform for t
2
e
t
.
L(x
+ 2x
+ 3x)(s) = L(t
2
e
2
)(s)
Type,
t^2*e^t[Shift][Ctrl][.]laplace,t,simplify
we nd
L(t
2
e
2
)(s) =
2
(s 1)
3
Step Two: Using linear property to nd an equation for x(s).
L(x
+ 2x
+ 3x)(s) = (
+ 2
+ 3 x(s)
= s
2
x(s) sa b + 2(s x(s) a) + 3 x(s)
= (s
2
+ 2s + 3) x(s) sa b 2a
The equation for x(s) is
(s
2
+ 2s + 3) x(s) sa b 2a =
2
(s1)
3
Hence,
x(s) =
sa+b+2a
(s
2
+2s+3)
+
2
(s1)
3
(s
2
+2s+3)
Step Three: Using Mathcad to nd inverse Laplace trans-
form and x(t), we enter,
s*a+b+a/(s^2+2s+3)+2/(s-1)^3(s^2+2s+3)[Shift][Ctrl][.]laplace,s
6 1. LAPLACE TRANSFORM METHODS
and get
x(t) = ae
t
_
2
2
sin(
2t) + cos(
2t)
_
+ b
2
2
e
t
sin(
2t)
+e
t
_
1
3
t +
2
9
+
2
9
cos(
2t)
_
+
2
18
e
t
sin(
2t)
= 3x 4y + t
2
y
= x + 5y + e
t
x(0) = 1, y(0) = 1
Solution
Step One: Apply Laplace transform to both sides of the equa-
tions and use Mathcad to nd Laplace transform of t
2
and e
t
,
L(x
) = L(3x 4y + t
2
)
L(y
) = L(x + 5y + e
t
)
and L(t
2
)(s) =
6
s
3
and L(e
t
)(s) =
1
s1
,
Step Two: Apply linear property to get a system of equations
for x(s) and y(s), due to L(x
) =
s y(s) y(0),
s x(s) 1 = 3 x(s) 4 y(s) +
6
s
3
s y + 1 = x(s) + 5 y(s) +
1
s1
from which we get
(s 3) x(s) + 4 y(s) = 1 +
6
s
3
x(s) + (s 5) y = 1 +
1
s1
Dene x(s) =
_
x(s)
y(s)
_
, A =
_
s 3 4
1 s 5
_
, and b(s) =
_
1 +
6
s
3
1 +
1
s1
_
, we have, in matrix form,
A x(s) = b(s)
3. THE PIECEWISE DEFINED FUNCTIONS 7
Step Three: Solve the algebraic equation and apply the in-
verse Laplace transform, using Mathcad we have
x(s) = A
-1
b(s) =
1
s
2
8s + 11
_
(s5)(s
3
+6)
s
3
4
2s
s1
(s3)(2s)
s1
s
3
+6
s
3
_
x(t) =
_
x(t)
y(t)
_
=
_
15
11
t
2
174
121
t
1062
1331
+ e
4t
_
3742
1331
cosh(
5t)
2334
6655
sinh(
5t)
_
e
t
3
11
t
2
48
121
t
318
1331
e
4t
_
695
2662
cosh(
5t) +
8143
1331
sinh(
5t)
_
1
2
e
t
_
+a
0
x = f(t)
with multiple dened function f(t), we need to change f(t) into linear
combinations of step functions u
a
(t).
Here u
a
(t) = u(t a) =
_
0 if t < a
1 if t a
and
u(t) =
_
0 if t < 0
1 if t 0
is called Heaviside function or unit step function.
We have graphed some step functions,
Figure 1. Step Functions
8 1. LAPLACE TRANSFORM METHODS
In general, if b > a, u
a
(t) u
b
(t) =
_
_
_
0 if 0 < t < a
1 if a < t b
0 if t > b
To express a multiple dened function as linear combination of step
functions, we need, for each nite interval [a, b] on which f has a
dierent expression, multiply the expression by the dierence of step
functions u
a
(t) u
b
(t); for the expression dened on an innite interval
[c, ) we just multiply the expression by u
c
(t). f(t) is the summation
of all the products, as illustrated in the following examples,
Example 3.1. Express
f(t) =
_
_
_
t
2
t + 3 if 0 < t < 2
e
t
if 2 t < 5
2t sin(t) if t 5
as linear combination of step functions.
Solution Notice f(t) has three dierent expresses over interval
[0, 2), [2, 5) and [5, ), so we have two dierence, u(t) u
2
(t) and
u
2
(t) u
5
(t), and three products,
(t
2
t + 3)(u(t) u
2
(t)) for (t
2
t + 3) dened on [0,2);
e
t
(u
2
(t) u
5
(t)) for e
t
dened on [2, 5);
2t sin(t)u
5
(t) for 2t dened on [5, ).
f(t) is sum of these three products,
f(t) = (t
2
t + 3)(u(t) u
2
(t)) + e
t
(u
2
(t) u
5
(t)) + 2t sin(t)u
5
(t)
= (t
2
t + 3)u(t) + (e
t
t
2
+ t 3)u
2
(t) + (2t sin(t) e
t
)u
5
(t).
t
3
if 0 < t < 3
cos(t) if 3 t < 6
2t if t 6
can be dened in Mathcad as
f(t) = t
2
e
t
3
(t) + (cos(t) t
2
e
t
3
)(t 3) + (2t cos(t))(t 6).
The following graph shows this function in Mathcad and its graph,
10 1. LAPLACE TRANSFORM METHODS
3.2. Solve ODE With Piecewise Input Function.
Example 3.3. Find solution to x
+ 4x = f(t), x(0) = 0, x
(0) =
1, where f(t) =
_
cos(2t) if 0 t <
0 if t
Solution First we express f(t) as linear combination of step
function, f(t) = cos(2t)(u(t) u
2
(t)) Apply Laplace transform to
both sides of the equation and using Mathcad we get
(s
2
+ 4) x(s) = 1 + (1 e
s
)
s
s
2
+ 4
x(s) =
1
s
2
+ 4
+ (1 e
s
)
s
(s
2
+ 4)
2
Apply inverse Laplace transform, we get,
x(t) =
_
1
2
sin(2t) +
1
4
t sin(2t) if 0 t <
0 if
2
4
sin(2t)
The equation x
(0) = 1. From
the graph we can clearly see that when the force is turno at t = its
eect is immediately gone(as shown below)!
4. Delta Function
Delta function is one of so-called generalized functions, which are
not functions in ordinary sense but as an operators that sometimes can
be represented by ordinary functions.
Definition 4.1. The Dirac delta function at a,
a
(t), is an op-
erator that satises
_
0
g(t)
a
(t) dt = g(a)
for any continuous function g(t).
In Physics, if f(t), a t b is a force that acts only during a short
period of time interval [a, b], the impulse p of force f(t) is computed
as
_
b
a
f(t) dt.
a
(t) can be viewed as an instantaneous unit impulse that occurs pre-
cisely at the instant t = a. And p
a
(t) is an instantaneous p units
impulse that occurs precisely at the time t = a.
a
(t) is an important function used in modelling real phenomena,
for example,
12 1. LAPLACE TRANSFORM METHODS
In modelling the movement of a baseball after being hit by
bat.
In spring-mass system, where a object with given mass it at-
tached to one end of a spring whose other end is attached to
a steady object (such as wall), modelling the movement when
hits the object with a hammer.
Modelling the current in a closed circuit when the switch is
turn on and o instantly.
It turns out that we can stretch ourself a little and compute the
Laplace transform of
a
(t). Let (t) =
0
(t) then
a
(t) = (t a).
Theorem 4.1.
(s) = 1 and
a
(s) = e
as
.
Example 4.1. A mass m = 1 is attached to a spring with constant
k = 4; there is not dashpot. The mass is released from the rest with
x(0) = 3. At the instant t = the mass is struck with a hammer,
providing an impulse p = 8. Determine the motion of the mass.
Solution In general mx
+ 4x = 8
(t), x(0) = 3, x
(0) = 0.
Applying Laplace transform to both sides of the equation,
(s) + 4 x(s) = 8
(s)
s
2
x sx(0) x
(0) + 4 x(s) = 8e
s
(s
2
+ 4) x(s) 3s = 8e
s
Solve for x(s), we get
x(s) =
3s
s
2
+ 4
+
8
s
2
+ 4
e
s
Using Mathcad , we can nd inverse Laplace transform,
x(t) = 2 cos(2t) + 4u
(t) sin(2t) =
_
2 cos(2t) if 0 t <
2 cos(2t) + 4 sin(2t) if t
So clearly the impact of the impulse is felt by the spring and change
the its movement immediately. The solution curve is shown below,
4. DELTA FUNCTION 13