Documente Academic
Documente Profesional
Documente Cultură
University of Sheffield
Aleksandar Pavic
Stana Zivanovic
October 2009
Contents
Contents
1.1
Introduction to Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2
System Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3
Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4
Signal Classification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4.1
1.4.2
1.5.1
Linearity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.5.2
Time Invariance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.5.3
1.5.4
Causality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.5.5
Stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.5
2 Introduction to MATLAB
2.1
2.2
13
Finding MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.1.2
Simple Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.1.3
Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.1.4
Mathematical Functions . . . . . . . . . . . . . . . . . . . . . . . . 16
2.1.5
Help in MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.1.6
2.1.7
2.2.2
2.2.3
CONTENTS
ii
2.2.4
Matrix Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.3
2.4
2.3.2
. . 26
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
30
3.1
Numerical Differentiation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.2
Numerical Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.2.1
Trapezoidal Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.2.2
Simpsons Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
3.2.3
4 Linear Algebra
4.1
4.1.2
4.1.3
4.1.4
4.1.5
4.2
43
Matrix Notation . . . . . . . . . . . . . . . . . . . . . . . 46
4.1.1.2
Vector Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
4.1.2.1
Vectors in R2 . . . . . . . . . . . . . . . . . . . . . . . . . 48
4.1.2.2
Vectors in R3 . . . . . . . . . . . . . . . . . . . . . . . . . 49
4.1.2.3
Vectors in Rn . . . . . . . . . . . . . . . . . . . . . . . . . 49
4.1.2.4
Linear Combinations . . . . . . . . . . . . . . . . . . . . . 49
Matrix Equation Ax = b . . . . . . . . . . . . . . . . . . . . . . . . 51
4.1.3.1
Existence of Solutions . . . . . . . . . . . . . . . . . . . . 52
4.1.3.2
Computation of Ax . . . . . . . . . . . . . . . . . . . . . . 52
4.1.4.2
. . . . . . 55
Linear Independence . . . . . . . . . . . . . . . . . . . . . . . . . . 56
4.1.5.1
4.1.5.2
Matrix Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.2.1
Matrix Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.2.1.1
4.2.1.2
Matrix Multiplication . . . . . . . . . . . . . . . . . . . . 60
CONTENTS
iii
4.2.1.3
4.2.1.4
Powers of a Matrix . . . . . . . . . . . . . . . . . . . . . . 63
4.2.1.5
Transpose of a Matrix . . . . . . . . . . . . . . . . . . . . 63
4.2.2
Inverse of a Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
4.2.3
4.3
Determinants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
4.4
Vector Spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
4.5
4.4.1
Vector Subspaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
4.4.2
4.4.3
4.4.4
4.5.2
5 Time-Domain Models
78
5.1
5.2
5.2.2
5.3
Homogeneous Solution . . . . . . . . . . . . . . . . . . . . . . . . . 80
5.2.1.1
5.2.1.2
5.2.1.3
Repeated Roots . . . . . . . . . . . . . . . . . . . . . . . . 82
5.2.1.4
Particular Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
5.2.2.1
f (t) = eat . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
5.2.2.2
f (t) = polynomial . . . . . . . . . . . . . . . . . . . . . . 86
5.2.2.3
5.2.2.4
Convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
5.3.1
. . . . . . . . . . . . . . . . . . . 88
5.3.2
96
6.1
6.2
Chapter 1
Introduction to Systems and Signals
1) Fundamentals of Signals and Systems using Web and Matlab, E. W. Kamen, B. S. Heck,
Prentice Hall, 2000.
2) Continuous and Discrete Signal and System Analysis, C. D. McGillem, G. R. Cooper,
Sounders College Publishing, 1991.
3) Contemporary Linear Systems using Matlab, R. D. Strum, D. E. Kirk, Brooks/Cole, 2000.
1.1
Introduction to Systems
A system is an interconnection of components (e.g. devices or processes) with terminals or access ports through which matter, energy or information can be applied or
extracted. As illustrated by a block diagram in Figure 1.1, a common way of viewing
a system is in terms of a black box with input and output terminals. In the figure,
x1 (t), x2 (t), ..., xp (t) are the signals applied to the p input terminals of the system and
y1 (t), y2 (t), ..., yq (t) are the resulting response signals (responses) appearing at the q
output terminals of the system. In general, p is not equal to q. In other words, the number
of input signals may not be the same as the number of output signals. When p = q = 1,
the system is called a single-input single-output (SISO) system. It is mostly this sort
of system that will be studied in this course. On the other hand, if a system is exposed
to more than one input, and has more than one output, it is called multiple-inputs
multiple-outputs (MIMO) system. As one would expect, there exist SIMO systems
(single-input multiple-outputs) and MISO systems (multiple-inputs singe-output).
CIV6115
CIV6115
1.2
System Representation
(1.1)
The nature of the operation T {.} depends on the nature of the component of the system
(i.e. its properties) and might be anything from simple scaling to a complicated nonlinear
function that maps given input with a certain output.
CIV6115
1.3
Signals
The concept of a signal has already been introduced in Section 1.1. Signal can be defined
as a time-dependent variation of a characteristic of a physical phenomenon, used to
convey information (definition from http://www.atis.org/tg2k/ signal.html). The signals
that are present at all instants of time are known as continuous signals. The signals
occurring in nature are generally continuous. Some examples are: the variation of the air
temperature, the variation in sea level, the variation in wind pressure on buildings, the
variation in deflection of a bridge under traffic load, etc.
The system that receives a continuous input signal and generates a continuous output
signal is called the continuous system (or sometimes continuous-time system). Such a
system is presented in Figure 1.4.
CIV6115
(shown in Figure 1.5b). The original continuous signal is also presented in Figure 1.5b as
a dashed line.
Therefore, discrete signals are signals that are only available at discrete time intervals,
usually equally spaced. The standard way of presenting a discrete signal is in the form of
circles that are connected with the time axis by vertical lines, as shown in Figure 1.5b.
This helps distinguishing between continuous and discrete signals even when not explicitly saying which signal (continuous or discrete) is being presented/analysed. MATLAB
deals with discrete signals only. However, the command plot(t,r) could be used
if the discrete points are to be plotted as connected (by linear functions) while using
stem(t,r,.) leaves a clear impression that the signal is discrete.
Figure 1.5: (a) Continuous signal and (b) its discrete counterpart resulting from the
sampling process at equally spaced intervals.
The systems that receive inputs and produce outputs in discrete time points are called
discrete systems. One example is presented in Figure 1.6. The abscissas of the graphs
of x(n) and y(n) present the order number of the point sampled in time. For example,
if the spacing between each sample is equal to t then n = 2 corresponds to the time
instant t = 2t. Usually n = 0 is chosen to correspond to the time instant t = 0.
1.4
Signal Classification
There are many different ways in which signals can be separated into categories, and only
a few are discussed here.
CIV6115
1.4.1
A periodic signal is one that repeats itself after a fixed length of time known as the
period. More precisely, a signal x(t) is periodic if there is a positive real number T such
that
x(t) = x(t + T )
(1.2)
for all t. The smallest positive number T that satisfies Equation 1.2 is the period (or
fundamental period), and it defines the duration of one complete cycle of the signal.
Note that if x(t) is periodic with period T , it is also periodic with period qT , where q is
any positive integer. The fundamental frequency f0 of a periodic signal is
f0 =
1
T
(1.3)
and it represents the number of cycles in one second, usually expressed in Hertz (Hz).
The frequency can also be expressed in form of circular frequency (with units radians
per second i.e. rad/s) using this relationship with the frequency expressed in Hz:
0 = 2f0 .
(1.4)
Probably the most important and the most used example of a periodic signal is the
sinusoidal (harmonic) signal (Figure 1.8)
x(t) = A cos(t + ), < t < ,
(1.5)
where A is the amplitude, the frequency in radians per second, and the phase in radians. Note that there is no significance in the fact that we used cosine function to define a
sinusoidal function, since by choosing = /2 the signal defined in Equation 1.5 becomes
a sinusoid. You can play with amplitude, phase and frequency parameters of a sinusoidal
signal at http://www.facstaff.bucknell.edu/mastascu/elessonshtml/Signal/Signal1.htm.
An important question for signal analysis is whether or not the sum of two periodic signals
is periodic. Suppose that x1 (t) and x2 (t) are periodic signals with fundamental periods
T1 and T2 , respectively. The signal x1 (t) + x2 (t) is periodic if and only if the ratio TT12 can
be written as the ratio rq of two integers q and r. Namely, if TT12 = rq , then rT1 = qT2 , and
since r and q are integers, then x1 (t) which is periodic on T1 is also periodic on rT1 i.e.
qT2 . For the same reason x2 (t) is periodic on the same period. Therefore, their sum will
also be periodic on period T = rT1 = qT2 . In addition, if r and q are coprimes (i.e. r and
q have no common integer factors other than 1), then T = rT1 is the fundamental period
of the sum x1 (t) + x2 (t).
A nonperiodic (aperiodic) signal is one for which no value of T satisfies Equation 1.2.
CIV6115
1.4.2
1.5
Throughout this section the focus is on SISO (single-input single-output) systems. Two
of most fundamental properties of the system are linearity and time invariance. These
two properties and other basic properties are defined in this section.
CIV6115
1.5.1
Linearity
One of the most important concepts in system theory is linearity. Many accepted
forms of mathematical analysis are permitted with a linear system that allow for easier
and more convenient methods of analysis and design. In addition, in many situations
practical engineering systems may be modelled as being linear. Linear systems possess
the property of superposition, which leads to the following definition: A system is
linear if and only if it satisfies the principle of homogeneity and the principle
of additivity.
1. Homogeneity: Let us consider a system exposed to input x1 (t). The system
produces output y1 (t). We can present this as x1 (t) y1 (t), meaning input x1 (t)
acting on the system produces output y1 (t). When a new input x(t) = C1 x1 (t) is
applied to the linear system, the output is y(t) = C1 y1 (t). That is, if the input is
scaled by the complex constant C1 , the output will be scaled by the same constant
(Figure 1.10). This is the homogeneity property.
2. Additivity: If we have a system such that x1 (t) y1 (t) and x2 (t) y2 (t), then
the new input x1 (t) + x2 (t) applied to the linear system will produce the output
y1 (t) + y2 (t). That is, the additivity principle reads: the output due to the sum
of two (or more) inputs is equal to the sum of the outputs produced by individual
inputs (Figure 1.11).
CIV6115
A linear system usually results if none of the components in the system changes its
characteristics as a function of the magnitude of the excitation applied to it. In the case
of a mass-spring-damper system (commented on in more detail later on in the course) this
means that mass, spring and damping do not change their values as the force applied to
the system changes. In physical world, however, the concept of linearity is almost always
an approximation because most system components will change their characteristics if
the force applied to it is large enough. Hence, when we speak about a linear system, what
we really mean is that with the normal input magnitudes, the system does not
change significantly; therefore, linearity may be assumed, and the methods of linear
system analysis may be employed. What changes are significant and what inputs will
produce them are matters of engineering judgement.
Linearity is extremely important property. If a system is linear, it is possible to apply the
vast collection of existing results on linear operations in the study of system behaviour. In
contrast, the analytical theory of nonlinear systems is very limited in scope. In practice,
a given nonlinear system is often approximated by a linear system so that analytical
techniques for linear systems can then be applied.
EXAMPLE 1.1:
Amplifier
Consider an ideal amplifier with the input/output relationship y(t) = Kx(t), where K is
a positive real number. A plot of the output y(t) versus the input x(t) is given in Figure
1.13.
The ideal amplifier is clearly linear, but this is not the case for an actual (nonideal)
amplifier (from a real world), since the output y(t) will not equal Kx(t) for arbitrarily
large input signals. In a nonideal amplifier, the output versus input characteristics may
CIV6115
10
be as shown in Figure 1.14. From the figure it is clear that y(t) = Kx(t) only when
absolute value of the magnitude |x(t)| of the input is less than M . The nonideal amplifier
is not homogeneous since the response to ax(t) is not equal to a times the response to
x(t) unless |x(t)| < M . Therefore, the nonideal amplifier can be viewed as a linear system
only if it can be guaranteed that the magnitude of the input applied to the amplifier will
never exceed M .
where h(t) is an arbitrary real-valued function of t with h(t) = 0 for all t < 0. (It will
be seen later that h(t) is called the impulse response of the system with input-output
relationship defined in Equation 1.6.)
Now suppose that the input is ax1 (t) + bx2 (t), where x1 (t), x2 (t), a, and b are arbitrary.
By Equation 1.6 the resulting output response is
Z t
y(t) =
h(t )[ax1 () + bx2 ()]d.
t0
t0
Hence y(t) is equal to a times the response to x1 (t) plus b times the response to x2 (t),
which proves that the system that satisfies Equation 1.6 is linear.
end of the example
As we explained, linearity is a property of systems. However, it is also a property
of mathematical operators, such as Laplace and Fourier transforms used (later
CIV6115
11
in these notes) to analyse the systems. Indeed, linearity is necessary (but it is not itself
sufficient) to provide an important benefit of Laplace transforms in the transformation
of linear differential equations to linear algebraic equations.
1.5.2
Time Invariance
Suppose x1 (t) y1 (t). Consider now another input x2 (t) that is a time-shifted version
of x1 (t), that is
x2 (t) = x1 (t t0 ).
If the output y2 (t) caused by x2 (t) is a shifted version of y1 (t), that is
y2 (t) = y1 (t t0 )
for arbitrary x1 (t) and t0 and for all t, then the system is said to be a time-invariant
system. Loosely speaking, the system parameters do not change with time, and the same
input applied at different times will produce outputs that are identical in shape and size
but shifted in time. The time-invariant systems are schematically shown in Figure 1.15.
1.5.3
When a system is both linear and time invariant, it is called a linear time-invariant
(LTI) system. This system is convenient for analysis using many techniques, such as
Laplace and Fourier transform. LTI systems are typically described in the time domain
by linear differential equations with constant coefficients. In transform domain
(Laplace or Fourier) the equations are linear algebraic equations. This means that we
can use linear algebra (that we will study in Chapter 4) to study LTI systems. In this
course, we focuss on the analysis of LTI systems.
1.5.4
Causality
A causal (not casual!) (or physical, or nonanticipatory) system is one whose present
response does not depend upon future values of the input. This means that for any time t1
the output response y(t) at time t1 resulting from input x(t) does not depend on values of
the input x(t) for t > t1 . Thus in a causal system it is not possible to get an output before
an input is applied to the system. A system is said to be noncausal or anticipatory if
it is not causal. Although all systems that arise in nature are causal (or appear to be),
there are applications in engineering where noncausal systems arise.
CIV6115
1.5.5
12
Stability
We normally do not design engineering systems that are inherently unstable, because we
want to have stable systems (in our case structures) with the outputs (deformation, for
example) that do not exceed a certain limit. Therefore, the system is said to be stable if
for a bounded input x(t) (i.e. for an input which magnitude does not approach ) the
output is also bounded. This stability criterion is sometimes called the bounded-inputbounded-output (BIBO) criterion.
Chapter 2
Introduction to MATLAB
Based on Lecture Notes: AMA144 by M. Petkovski and R. S. Crouch, University of Sheffield,
2006.
The overall aim of this introductory course is to help a student to use MATLAB for
solving a range of mathematical problems related to system analysis rather than to teach
programming in MATLAB. This means that we will mainly use MATLAB as a powerful
calculator rather than as a programming language, although some programming
cannot be (and should not be) avoided. Students are encouraged to explore many of
the options within MATLAB to build-up their programming skills that will help them to
broaden the usage of MATLAB and to increase computing efficiency throughout this and
some other modules. Throughout lectures in CIV6115, we will be paying special attention
how to use MATLAB in order to solve the problems of interest.
2.1
MATLAB is a very powerful computer software which allows the user to express and solve
a wide range of applied mathematical problems. The name MATLAB comes from MATrix
LABoratory because the code was designed to make matrix manipulations particularly
easy.
MATLAB may be run interactively. This means that once the user has typed-in some
commands, the program will respond with an answer. MATLAB can be used in its
simplest mode just like a very powerful scientific calculator, or in its most advanced mode
as a complete programming environment with a rich library of high level graphics routines
built-in.
An example of using interactive mode would be to type an expression in the command
window, press Enter (or Return) and wait for the result issued by MATLAB and displayed
in the window. For example:
>> 2+3
ans =
5
2.1.1
Finding MATLAB
MATLAB can be found on the University of Sheffields network in start- applicationsacademic - maths&stats- matlab6. Once the MATLAB has been activated, the user
13
CIV6115
14
will have to wait some time (up to several minutes, if the network is busy) before the
window entitled MATLAB appears. This window, the MATLAB desktop, is the graphical
user interface for MATLAB. Within the desktop, there is a window called Command Window
(Figure 2.1). This is the main window for all the communication between the user and
MATLAB. When the Command Window is active (the cursor blinks in front of the >>
prompt) the user is free to start entering commands. To leave MATLAB at any stage, the
user should type >> quit.
If your MATLAB desktop differs from the one shown in Figure 2.1 you can get the same one
by activating Desktop/Desktop Layout/Default from the main menu.
At this stage it might be useful to try typing >> demo in the command window. This
will bring up a number of demonstration examples which illustrate some of the features
of MATLAB.
2.1.2
Simple Arithmetic
The first exercise for a new user is to try some simple arithmetic. The Table 2.1 lists
the symbols associated with the basic arithmetic operations, while Table 2.2 gives some
simple examples.
CIV6115
operations.
Example
4+3
27-1
18 3
18 3
25
15
MATLAB
4+3
27-1
18*3
18/3
2^5
2.1.3
Output
ans=11
ans=24
ans=3
ans=3
ans=37
ans=145
ans=37
ans=6.6000e+009
ans=6.6000e+009
Comments
Note that result is given the default name ans
and that spaces in the expression do not affect the operation.
The operations are performed left to right. Operations that have
precedence (priority): (1) power (^), (2) multiplication and division
(*, /) (3) addition and subtraction (+,-). If the precedence is
altered by brackets, the evaluation starts with the
innermost brackets and proceeds outwards.
When using scientific notation (2*106 is written as 2e6) note that
1011 is entered as 1e-11, not as e-11.
Variables
In MATLAB you may assign a name to an expression and then use it in other expressions.
The statement a=3 means that the value 3 (on the right hand side) is assigned to a
variable called a (on the left hand side). Now we can issue a new statement b=a^2 and
MATLAB will display b=9. This means that it has first calculated the expression on the
right hand side (a^2) and assigned its value to the variable on the left hand side (hence
b=9). The variables used on the right hand side must always have a value. For example,
if we enter b=c^2, MATLAB will reply with ??? Undefined function or variable c. It
is important that you read the = symbol not as an equals sign but as an assignment
operator. This implies that x=x+1 is a valid MATLAB statement which increments the
variable x by one, assuming that the old value of x is known.
Variables do not have to be always named a, b and c or x and y. They can be called
mangos, pizzas or money_for_food. In fact any name can be used, providing that it is
within the MATLAB rules:
Variable name must be a single word containing no spaces. Blank spaces are not allowed in the variable name but an underscore can be used to link multiple words into
a phrase for a single variable. For example cost_of_night_out or bending_moment
are valid names for variables, whereas shear force is not.
The variable name must begin with a letter of the alphabet. Thus chocolate or a3
are valid variable names but 3x is not.
Variable names are case sensitive. Thus Fruit, fruit, fruiT and FRUIT are all
different MATLAB variables.
CIV6115
16
2.1.4
Mathematical Functions
MATLAB has all the usual mathematical functions like sqrt, sin, cos, tan, log and many
more. Note that all trigonometric functions expect the argument to be expressed in
radians (and not degrees). It is worth remembering that MATLAB stores in pi.
Here is calculation of square root of 16:
>> x=16;
>> a=sqrt(16)
a =
4
2.1.5
Help in MATLAB
Look at the help menu to find a listing of all standard functions. Or simply type
help elfun in the command window for the list of all elementary functions. For further help on any of the listed functions or any other topic type help and then name of
the function at the command prompt. For example,
>> help sqrt
SQRT
Square root.
CIV6115
17
2.1.6
If you are going to write a series of MATLAB instructions (that is, a program) which
will be used more than once, then you should create and save the algorithm in an
m-file, by using Notepad.
To open Notepad, use the menu in the MATLAB desktop (File-New-m file). Enter all
your MATLAB commands here and save the work in a file with .m as the extension
(menu File-Save As in the Notepad window).
To run the commands (assuming the file was saved in the same directory as the
current directory defined in the MATLAB desktop) simply type the filename (without
the .m extension) in the Command window and press Enter.
During the process of creating the program, do not forget to save the file regularly, otherwise you may lose all your work if the system crashes.
You can make your program easier to understand by choosing meaningful variable
names and using comment statements. Comments are created by inserting a %
symbol in a line. All text to the right of of the % symbol is treated as a comment.
Do not forget to identify any units (using comment statements) appropriate to each
variable in your program.
The following example program determines
the roots to the quadratic equation
b b2 4ac
2
ax + bx + c = 0 (solutions are x1/2 =
).
2a
1. Open Notepad and type in the following command lines
% quadeq_sol .. program for
sqrt_term=sqrt(b^2-4*a*c));
xroot1=(-b-sqrt_term)/(2*a)
xroot2=(-b+sqrt_term)/(2*a)
solving y=ax^2+bx+c
% quadratic equation
% first root
% second root
CIV6115
18
Note that in the above example, three MATLAB commands appear on the first line. This is
possible because the ; separator has been used. Also note that the given set of coefficients
leads to imaginary roots, which MATLAB is perfectly able to detect and report. Enter new
values for a, b and c and run the program quadeq_sol again to calculate the new roots
to the quadratic equation.
2.1.7
The for loop is a procedure for executing a group of commands a fixed number of times.
The basic structure of the for loop is as follows
for counter=start_value:increment:end_value
command_1
command_2
...
command_n
end
Upon the first entry into the for loop the variable counter is assigned the value start_value
and all the commands in the specified set are executed sequentially (top-to-bottom). In
every subsequent cycle of the loop, the value of increment is added to the previous value
of counter and all the commands are executed again. The last cycle of the procedure is
the one when counter becomes equal to end_value.
Note that every for loop must finish with an end statement.
If the increment is omitted, a default value of 1 is assigned by MATLAB.
Consider the following example:
for x=1:10
y=x^2+2*x-4
end
In this example x increases from 1 to 10 with a step 1 and y = x2 + 2x 4 is calculated in
each cycle, for the value of x in that cycle. In the first cycle x = 1 and y = 12 +214 = 1,
in the second cycle x = 2 and y = 22 + 2 2 4 = 4 and so on. The operation proceeds
until x becomes equal to 10 and the last value of y will be y = 102 + 2 10 4 = 116.
If we execute this code, y variable kept in MATLAB workspace will be equal to the last
value calculated. However, we might want to have all values of y (that correspond to all
x used in calculations) stored in MATLAB workspace at the end of calculation. For this we
may use array notation for y, which is y(x):
for x=1:10
y(x)=x^2+2*x-4;
end
Check what is the variable y (available in the workspace) like now! You will see that it is
an array containing all 10 results. More about this array notation will come later.
CIV6115
2.2
19
The matrix operations are probably the greatest strength of MATLAB. This section reviews
some of the operations related to matrices. Chapter 4 dealing with linear algebra will
extend it further.
2.2.1
MATLAB treats every variable as a matrix. For example, the statement mangos=11
assigns a numerical value (11) to a 1 1 matrix called mangos. Or, we can say that
some parameter (for example number of mangos, which is 11) is stored in a matrix
called mangos. Therefore, every scalar is treated as 1 1 matrix in MATLAB. Because
of this we can recall it either by typing in:
>> mangos or
>> mangos(1)
>> mangos(1,1)
where (1) or (1,1) denote the first element of an array and the first-row firstcolumn element in the matrix, respectively.
The command >> fruit = [11 8 6 14 21] will create a matrix called fruit. This
matrix has 1 row and 5 columns (and it is, in fact, an array, but for MATLAB there
is no need to distinguish between matrices with one and more rows), which means
the size of fruit is 1 5 (MATLAB will display the size of the matrix if you type
>> size(fruit)).
Previous examples could be presented in the following way:
column 1
mangos =
11
row 1
columns: 1 2 3 4 5
fruit = 11 8 6 14 21 row 1
The values 11 8 6 14 21 are stored as fruit(1), fruit(2), ..., fruit(5) (or
equally correct in fruit(1,1), fruit(1,2), ..., fruit(1,5))in the same way as 11
was stored under the variable name mangos. Now we can calculate, for example,
a=fruit(1)+fruit(5) (a = 11 + 21 = 32) or b=mangos*fruit(3) (b = 11 6 = 66).
Each number in the matrix (like fruit(2), fruit(4)) is called element of the
matrix. The number in the brackets is called subscript and it denotes the position
of the element in the matrix.
In MATLAB matrices can contain multiple rows and columns. For example A(2 3)
matrix contains two rows and three columns. It can be entered in a similar way
as the row vector (array) fruit, by using semicolon (;) to separate the rows. One
example would be the matrix
CIV6115
20
2.2.2
A matrix with elements which follow a linear progression in their values can be
generated by using a statement like y = 0:10. Note that there is a colon between
0 and 10. This will create an eleven element row vector called y which has elements
0 1 2 3 4 5 6 7 8 9 10. This can also be written as y=(0:10); the use of round
brackets may help clarify the code, but it is not necessary.
In the previous example where the vector y was generated, the values of the elements
of y were incremented by one (the default increment). A vector containing elements
with a different increment can be generated by specifying the increment. For example, y=0:0.1:10 provides an array with a step size of 0.1 (0 0.1 0.2 0.3 ... 10).
Zero matrices (that is, matrices filled with zeros) may be generated by using a
command of the form >> S = zeros(5,13) (in this case a 5 13 rectangular zero
matrix is created).
The identity matrix (i.e. a square matrix with ones on the main diagonal) can be
created quickly using the MATLAB function eye:
>> iden=eye(4)
iden =
1.0000 0.0000 0.0000 0.0000
0.0000 1.0000 0.0000 0.0000
0.0000 0.0000 1.0000 0.0000
0.0000 0.0000 0.0000 1.0000
In MATLAB, the subscripts can be used to access individual elements or entire sections
of the matrix:
>> x=(0:0.2:1) % Generate a six element, one-dimensional array
x =
0 0.2000 0.4000 0.6000 0.8000 1.0000
>> y=sin(x*pi)
y =
0 0.5878 0.9511 0.9511 0.5878 0.0000
>> y(3) % The third element of y
ans = 0.9511
>> y(1:3) % The first through to the third element in y
CIV6115
21
2.2.3
It was shown that a matrix of elements which follow a linear progression can be
generated automatically. The command
>> amat=1:2.1:10
will generate a row vector amat= [1.00 3.10 5.20 7.30 9.40].
The same row vector amat can be generated by using a for loop. Write the following
MATLAB program (save it as mat_gen.m):
clear
ind=0;
for k=1:2.1:10
ind=ind+1;
amat(ind)=k;
end
amat % display output
How does mat_gen.m work? In the first cycle k=1, ind=0+1=1, amat(1)=1; in the
second cycle k=1+2.1=3.1, ind=1+1=2, amat(2)=3.1... and so on. Note the incrementing of ind.
How can we use the same for loop to create another matrix (bmat) which will
contain the squares of the elements of amat?
This can be done by adding an additional line bmat(ind)=amat(ind)^2; after the
command amat(ind)=k;.
The same can be achieved introducing a new for loop (after end command of the
previous loop):
for i=1:length(amat)
bmat(i)=amat(i)^2;
end
or even without any loop:
bmat=amat.^2;
The program amat_gen.m can be easily extended to create a matrix in which the
first row will store the values of k (1.0, 3.1, 5.2, 7.3, 9.4), the second row
will store their squares and the third row their cubes. The new program (called
amat_GT.m) may look like this:
CIV6115
22
clear
% clear all previous variables from MATLAB workspace
icol=0;
for k=1:2.1:10
icol=icol+1;
for irow=1:3
amat(irow,icol)=k^irow;
end;
end;
amat
% display output
How does it work? Now we have two loops: outer and inner (nested). The program
first runs the first cycle of the outer loop: k=1, icol=0+1=1. Then it cycles the
inner loop for irow from 1 to 3. First irow=1, amat(1,1)=k^1=1, then irow=2, so
amat(2,1)=1^2=1, and finally irow=3, so amat(3,1)=1^3=1. When the inner loop is
completed, the outer loop enters its second cycle. Now k=1+2.1=3.1; icol=1+1=2.
The inner loop again cycles three times: (1) irow=1, amat(1,2)=3.1^1=3.1; (2)
irow=2, amat(2,2)=3.1^2=9.61 and (3) irow=3, amat(3,2)=3.1^3=29.791. The
outer loop enters with a new value of k=3.1+2.1=5.2 and the inner loop cycles
again three times, filling up amat(1,3), amat(2,3) and amat(3,3). The process
continues with k increasing to 5.2+2.1=7.3 and 7.3+2.1=9.4. After that, the next
time the counter is updated (9.4+2.1=11.5) k receives a value greater than the
upper limit (10), and the outer loop is not executed. The program stops.
2.2.4
Matrix Operations
Generating new vector from old ones is particularly simple. For example, for
y=0:10; z=sin(2*y) will automatically generate a new eleven element vector z
containing the sine of double each of the y values.
The addition, subtraction and multiplication of matrices is very straightforward in
MATLAB. For example, if W=(10:0.5:20); and V=sin(0.1*W); then U=V+W; is all
that need to be written to imply matrix addition.
Of course, if matrix multiplication is to be carried out, than the matrices must
conform (that is the number of columns of the first matric must equal to the
number of rows of the second). For example, matrices
4 5
2 2 7
A23 =
and B32 1 8
3 6 0
3 7
can be multiplied by issuing the command >> A*B while matrices
2 2 7
4 5 3
A23 =
and C23 =
3 6 0
1 8 7
cannot, since they do not conform.
In addition to matrix operations MATLAB can perform element-by-element array
manipulations. This is done by adding a dot in front of the standard operation
symbols (multiplication, division or power). This is possible only for matrices of the
CIV6115
23
same size (i.e. the same number of rows and columns). An example are matrices A
and C from the previous example. >> A.*C would result in
ans =
8
3
-10
48
21
0
Here, we will give few more examples for different operations in MATLAB:
>> a=1:5
a= 1 2 3 4 5
>> b=1:2:9
b= 1 3 5 7 9
>> a+b
ans = 2 5 8 11 14
>> 2*a-b
ans=1 1 1 1 1
>> a.*b
ans=1 6 15 28 45
>> a*b
??? Error using ==> *
Inner matrix dimensions must agree.
>> a./b
ans = 1.0000 0.6667 0.6000 0.5714 0.5556
>> a.\b
ans = 1.0000 1.5000 1.6667 1.7500 1.8000
>> c=[1 2 3 2 1]
c= 1 2 3 2 1
>> a.^c
ans= 1 4 27 16 5
>> a^c
??? Error using ==> ^
At least one operand must be scalar.
New arrays can be built from subsets of other arrays. That is, if x and y are
row oriented arrays, >> z=[x y] produces a row oriented array composed of the
elements of x followed by the elements of y ([x1 x2 ... xn y1 y2 ... yn ]). Similarly,
>> z=[x(1:5) -x(6:10) 5.6 2.0 10.0 y(5:23)] produces a row oriented array
composed of the first five elements of x, elements 6 to 10 of x multiplied by -1,
three new elements (5.6, 2.0, and 10.0) and elements 5 to 23 of y.
CIV6115
2.3
24
2.3.1
Relational and logical operators can be used in expressions to pose questions which
give either TRUE or FALSE as their answers. Note that if the answer is TRUE, the
expression returns a value of 1, whereas if the answer is FALSE the expression returns
0. One important application of this capability is to control the execution flow in a
series of MATLAB commands in the m-file.
Some MATLAB relational operators are shown in Table 4.
Table 2.4: Relational operators.
Operator Description
<
Less than
<=
Less than or equal to
>
Greater than
>=
Greater than or equal to
==
Equal to
~=
Not equal to
Note that for the equal to relation the double equals sign == is used to distinguish
it from the assignment symbol =.
The following example illustrates the use of logical operators.
>> x1=11.5; x2=81.1;
>> a1=x1>x2
>> a1 =
0
The result is a1=0 because the expression x1>x2 is FALSE (x1 is not greater than x2)
and the expression returns zero. Similarly, if a1=(x1==x2), the answer is also FALSE
and a1 will again be equal to 0. However, in the cases of a1=(x1<x2), a1=(x1~=x2)
and a1=(x1<=x2), which are all TRUE, a1 will be equal to 1.
Relational operators can be used in any MATLAB expression, such as:
>>
>>
>>
>>
x1=11.5; x2=81.1;
angle=0:0.1:10;
wave=(x1<x2)*sin(angle)+(x1>x2)*cos(angle);
plot(wave)
The result is a sine wave, because (x1>x2) is FALSE and, as a consequence, the term
cos(angle) is multiplied by 0.
CIV6115
25
Examine the following script. Consider the meaning of each line in a step-by-step
fashion (plot blink after every alteration).
>> blob=0:0.1:10; % create a 101 element vector 0, 0.1, 0.2, ..., 10
>> blah=sin(blob);
% compute sine
The signal blah is presented in Figure 2.2a.
>> blink=(blah>=0).*blah;
% set negative values of blah to zero
The signal blink obtained is shown in Figure 2.2b.
>> blink=blink+0.5*(blah<0); % add 0.5 to blink when blah is negative
This signal is shown in Figure 2.2c.
>> blink=blink.*(blob<=8);
% set blink to zero when blob>8
>> plot(blob,blink)
And final signal is shown in Figure 2.2d.
Symbol
&
|
~
CIV6115
26
The following example can be used to illustrate how relational and logical operators
can be combined in MATLAB expressions.
>>
>>
>>
>>
>>
z=-5:0.1:5
squarez=z.^2
plot(z,squarez)
newsquarez=squarez.*((z>-2)&(z<2))
plot(z,newsquarez,ro)
% create data
% square every element of z
% set to 0 at z<-2 and z>2
2.3.2
MATLAB allows if ... else ... end constructions to be used to control the flow
of the program. This feature is as useful as the for loop. Consider the following
example.
if(age<5)
milk=0;
else
milk=3.24*age+1.902*grass+0.3;
end
This example assumes that some values have been assigned to the variables age and
grass at an earlier stage in the program.
CIV6115
27
Note that, like for the for loop, an end statement is required at the end of the if
construction.
Also note that, once again, the lines of code between the if, else and end statements
are indented 2 blank spaces to improve the clarity of the algorithm structure.
The relational operators >, <, <= and == (see Table 2.4) may be used in conjunction
with the logical operators &, | and ~ (see Table 2.5). This is illustrated in the
following example.
if((age<=4.8)&(health<0.7))
milk=0
else
milk=2.98*age*health + 1.902*grass + 0.52
end
If the logical expression is TRUE (both age is less than or equal to 4.8 and health is
less than 0.7), then milk=0, else (the logical expression is FALSE) milk is calculated
as a function of age, health and grass.
When there are three or more alternatives, the if-else-end structure takes the
following form.
if expression_1
commands evaluated
elseif expression_2
commands evaluated
elseif expression_3
commands evaluated
elseif ....
..
..
else
commands evaluated
end
if expression_1 is TRUE
if expression_2 is TRUE
if expression_1 is TRUE
CIV6115
28
if constructions can be used within for loops. The following example calculates the
maximum of the function y = sin(x)ex/10 , for x between -8 and 5.
2.4
Functions
MATLAB provides a structure for creating functions of your own (in addition to the
MATLAB intrinsic functions like inv, abs, sin, sqrt, etc.) in the form of text files
(m-files) stored in your computer.
When you use a function, MATLAB takes the variables you pass to it, computes the
required results using your input data, then passes the results back to you. The
commands evaluated by the functions as well as any intermediate variables created
by those commands are hidden.
The basic structure of a function is as follows.
function[result1,result2,...]=funct_name(inputdata_1,inputdata_2,....)
% Some comments which describe what the function does, which variables
% are passed through the argument list and what output is expected
% These comments should also identify who wrote the function
command_1 operating on inputdata .....
command_2 operating on inputdata and/or results of the previous command
...
...
result_1=some_expression
result_2=another_expression
...
CIV6115
29
Chapter 3
Numerical Differentiation and
Integration
Modern Engineering Mathematics, G. James, Prentice Hall, 2001
When we are dealing with continuous deterministic signals (functions) we often can calculate their derivatives and/or integrals using analytical procedures, i.e. accurately.
Sometimes this might be overcomplicated or even impossible in which case we have to
do the calculations numerically, i.e. approximately. However, if we do not have a
continuous signal available, but we have only a set of signal values at discrete time points
(i.e. we have a discrete signal only) then we do not have a choice. In this case we have
to use numerical procedures for calculating derivatives/integrals. This section reviews
several methods of this kind.
A real-life example when we might need to conduct these two operations is when we
measure velocity of a structure exposed to some dynamic load, say wind. The signal
collected is usually discrete. Therefore, if we want to learn about the corresponding
acceleration of the structure we have to apply numerical differentiation procedure to the
measured velocity, while if we want to analyse structural displacement we would need to
apply numerical integration procedure to the measured velocity signal.
3.1
Numerical Differentiation
Before computing the derivative of an arbitrary discrete signal numerically, let us remind
ourselves that the first derivative of a function at a specific time point is equal to the
slope (of the tangent to the function) at this particular point.
The formula
x(t + t) x(t)
x
= lim
(3.1)
t0
t0 t
t
provides a formal definition of the derivative x0 (t) for signal x(t). The same formula can
be used for numerical differentiation of discrete signal x(n). The discrete version can be
written in the form:
x
x(tn + t) x(tn )
=
.
(3.2)
x0 (n)
t
t
However, Equation 3.2 does not provide a good basis for evaluating x0 (t) numerically.
This is because it gives one-sided approximation of the slope at t = t0 as shown in Figure
3.1. Namely, when we set t > 0, we obtain the slope of the chord PR. When we set
x0 (t) = lim
30
CIV6115
31
t < 0, we obtain the slope of the chord QP. It can be noticed that both PR and QP
are poor approximation of the slope of the function at t = tn , i.e. at point P. This could
be improved only by decreasing the step t (i.e. by making R and Q closer to point
P). Clearly, the chord QR offers a better approximation to the tangent at P. Second
reason why the formal definition of a derivative yields a poor approximation is that the
evaluation of derivatives involves the division of a small quantity x by a second small
quantity t. This process magnifies the rounding errors involved in calculating x, a
process that worsens as t 0. This phenomenon is called ill-conditioning, and could
be avoided by increasing the step t. Unfortunately, to decrease both types of error
mentioned, the two opposite measures are required. This means that the time step should
be chosen carefully, neither to be too big that approximation of the slope is poor, nor to
be too small that rounding off error is large. This also suggests that there is an optimum
value of t that should be chosen in order to have minimum possible error when using
this numerical procedure for calculating the first derivative of a signal. Note that when
using Equation 3.2, the first derivative at a single point was calculated using the value of
the function in this point and one neighbouring point.
x(tn + t) x(tn t)
.
2t
(3.3)
Higher order methods approximating the derivative are also possible to derive. One
possible way of doing this is to approximate the discrete signal by a polynomial of degree
n which passes through discrete points. For this purpose n + 1 coefficients that define
polynomial are required. A polynomial that is used very often is given by Lagranges
formula:
x(t) = L0 (t)x(t0 ) + L1 (t)x(t1 ) + L2 (t)x(t2 ) + ... + Ln (t)x(tn )
(3.4)
where L0 (t), L1 (t), ..., Ln (t) are polynomials of degree n such that
Lk (tj ) = 0, tj 6= tk i.e.j 6= k
Lk (tk ) = 1.
CIV6115
32
(3.5)
Once the polynomial of the discrete signal is defined, the first derivative can easily be
found. This will be demonstrated on an example of 3-point polynomial approximation.
Namely, say that we want to approximate the first derivative of a discrete signal using
three neighbouring points in the signal, these being (tk1 , xk1 ), (tk , xk ), and (tk+1 , xk+1 ).
First, we find Lagranges polynomial fitted through these three discrete points:
(t tk )(t tk+1 )
(t tk1 )(t tk+1 )
(t tk1 )(t tk+1 )
xk1 +
xk +
xk+1 .
(tk1 tk )(tk1 tk+1 )
(tk tk1 )(tk tk+1 )
(tk+1 tk1 )(tk+1 tk )
(3.6)
The polynomial can then be written as:
x(t) =
t2 tk+1 t tk t + tk tk+1
t2 tk+1 t tk1 t + tk1 tk+1
x(t) =
xk1 +
xk +
(t)(2t)
(t)(t)
t2 tk t tk1 t + tk1 tk
xk+1 .
(2t)(t)
(3.7)
2t tk tk+1
2t tk1 tk+1
2t tk tk1
xk1 +
xk +
xk+1 .
2
2
2(t)
(t)
2(t)2
(3.8)
We can now use this expression to calculate the first derivative at any point in the discrete
data set consisting of n + 1 points (0, 1, 2, ..., n). These derivatives for first (i.e. t = tk1
and then k 1 = 0), any middle (i.e. t = tk , k = 2, 3, ..., n 2) and last point (i.e. t = tk+1
and then k + 1 = n) in the signal can be written as:
3x0 + 4x1 x2
2t
x
xk1
k+1
x0k =
2t
x
4xn1 + 3xn
n2
x0n =
.
2t
x00 =
(3.9)
(3.10)
(3.11)
It can be noticed that the result for middle points when k = 1, 2, 3, ..., n 1 is the same
result as that obtained geometrically earlier (Figure 3.1) and presented in Equation 3.3.
Some additional formulae for derivatives, such as the one based on 5-point polynomial
approximation of the signal could be found at http://www.sitmo.com/eqcat/12.
Second derivative can be calculated using the same procedures by implementing them to
discrete signal of the first derivative.
Finally, we can think about numerical calculation of the derivative as transforming an
input signal x(t) into and output signal y(t) = x0 (t) by means of a system, that is in
this case actually the derivation process itself. In this example you can see that a system
can be anything that receives some input and transfers it into some output, i.e. the term
system is not limited to the physical (i.e. material) world only.
CIV6115
33
EXAMPLE 3.1
Write a script in MATLAB for numerical calculation of the velocity signal if the displacement
time history is known to be x(t) = sin(2t).
EXAMPLE 3.1:
SOLUTION
As we know, the velocity is the first derivative of the displacement. Therefore, we have
to write a program that will find derivative of the input specified.
Our input signal is a sinusoidal function with amplitude equal to 1 and circular frequency
grid on
CIV6115
hold on
plot(t,y,-.)
xlabel(Time [s])
ylabel(Signals x and y)
title(Numerical differentiation)
legend on
34
% legend content
Both signals are presented in Figure 3.2. Displacement signal is presented as a solid line
while velocity is shown as dot-dashed line. As we expected, the amplitude of the velocity
signal is equal to 2 = 6.28 and it is a cosine signal.
Numerical differentiation
8
Displacement [m]
Velocity [m/s]
Signals x and y
4
2
0
2
4
6
8
0.5
1.5
2
Time [s]
2.5
3.5
Acceleration [m/s ]
30
Signals x and y
20
10
0
10
20
30
40
0.5
1.5
2
Time [s]
2.5
3.5
CIV6115
3.2
35
Numerical Integration
Although numerical integration is a term that is sometimes used for finding solution of
differential equations numerically, in this section we are using it to refer to numerical
procedure for calculating integrals. We start this section with reminding ourselves that
a definite integral (i.e. integral with fixed lower and upper limits) represents the area
defined by the signal (function) in question.
In many practical problems the functions that have to be integrated are specified by a
graph or by a table of values (i.e. as discrete signals). Even when the function is given
analytically, it often cannot be integrated to give an answer in terms of simple functions.
In all these cases we have to evaluate integrals numerically. There are many ways of doing
this; only some of them will be presented in this section.
3.2.1
Trapezoidal Rule
The simplest methods of integration involve slicing up the area to be found into a number
of strips of equal width, approximating the area of each strip in some way. The sum of
these approximations then gives the final numerical result. The value of the integral of
the signal presented in Figure 3.4 on the domain of integration [a, b] can be found by
summing the area of each strip approximated by a trapezoidal area.
x(t)dt
a
n1
X
1
k=0
n1
1 X
(xk + xk+1 )t = t
(xk + xk+1 ) =
2
2
k=0
1
t[(x0 + x1 ) + (x1 + x2 ) + ... + (xn1 + xn )].
2
Finally, the value of integral is:
Z b
1
1
x(t)dt t
x0 + x1 + x2 + ... + xn1 + xn .
2
2
a
(3.12)
(3.13)
CIV6115
36
EXAMPLE 3.2
Write a program (in MATLAB) for numerical integration of the acceleration signal if its time
history is known to be a(t) = 4 2 sin(2t).
EXAMPLE 3.2:
SOLUTION
The integration of an acceleration signal a would lead to the corresponding velocity signal
v. By integration of the acceleration signal given, we know we have to get the following
velocity signal
Z
4 2
4 2 sin(2t)dt =
cos(2t) + C = 2 cos(2t) + C,
2
where C is an integration constant. This knowledge will help us to check if our numerical
integration of acceleration sinal produces the expected result.
To start with the integration, we need an initial value of the velocity v0 that will be associated with starting time instant t = t0 (see formulae below). This is usually available
from some, known in advance, initial condition. Note that when dealing with real problems we have to acquire this information from experiments or based on some additional
knowledge related to the problem under consideration.
Now we can start the integration process based on Figure 3.4
1
1
v1 = v(t = t1 ) = v0 + t
a0 + a1 .
2
2
Then
v2 = v(t = t2 ) = v1 + t
1
1
a1 + a2 .
2
2
vi = v(t = ti ) = vi1 +
or
vi = v0 +
1
1
ai1 + ai
2
2
1
1
a0 + a1 + a2 + ... + ai1 + ai .
2
2
CIV6115
37
a=-4*pi^2*sin(2*pi*1*t);
v=cumtrapz(a);
v=v*dt;
plot(t,a)
grid on
hold on
plot(t,v,-.)
xlabel(Time [s])
ylabel(Signals a and v)
title(Numerical integration)
legend on
legend(Acceleration [m/s^2],Velocity [m/s])
hold off
As a result, we get the plot presented in Figure 3.5.
Numerical integration
40
Acceleration [m/s2]
Velocity [m/s]
30
Signals a and v
20
10
0
10
20
30
40
0.5
1.5
2
Time [s]
2.5
3.5
CIV6115
38
Numerical integration
40
Acceleration [m/s2]
Velocity [m/s]
30
Signals a and v
20
10
0
10
20
30
40
0.5
1.5
2
Time [s]
2.5
3.5
3.2.2
Simpsons Rule
In the trapezoidal rule the shape of the signal x(t) was approximated by a series of
straight line segments. In Simpsons rule two neighbouring segments are approximated
by quadratic (parabolic) curves, as shown in Figure 3.7a. For this, the area has to be
divided into an even number of strips of equal width.
Figure 3.7: (a) Approximating shape of the signal by a parabola on each two neighbouring
vertical strips. (b) Calculation of the area of two strips.
The area of two neighbouring segments is then equal to the sum of areas A1 and A2 (Figure
3.7b), where area A1 is area of a parabola, and therefore is equal to 23 (xk p)(2t), while
k1
.
area A2 is a trapezoidal area equal to 21 p(2t), while p is equal to xk+1 +x
2
CIV6115
39
2
xk+1 + xk1
1 xk+1 + xk1
t
xk
2t +
(2t) =
(xk1 + 4xk + xk+1 ).
3
2
2
2
3
(3.14)
3.2.3
dA
(3.17)
CIV6115
40
n
X
Ai ,
(3.20)
i=1
Qx
Qy
xc =
=
A
n
X
yi Ai and Qy
i=1
Pn
xi Ai
Pi=1
n
i=1 Ai
n
X
xi Ai ,
(3.21)
i=1
Pn
yi Ai
Qx
= Pi=1
and yc =
.
n
A
i=1 Ai
(3.22)
EXAMPLE 3.3
By using numerical procedure find the centroid
of
CIV6115
EXAMPLE 3.3:
SOLUTION
41
In order to find centroid by numerical integration, we will divide the area in question by
vertical strips of equal width, say t = 1 (Figure 3.10).
CIV6115
42
A Aexact
26.7188 26.6667
100 =
100 = 0.1%
exact
A
26.6667
only.
The relative errors for other quantities are:
EQt = 0.00%, EQx = 0.78%, Etc = 0.58%, Exc = 0.19%.
The effect of changing the step t on the accuracy of the results can be studied by
playing with this parameter in MATLAB file Example3_3.m. You are encouraged to add
calculation of relative errors to the code.
end of the example
Note that the complete calculation could have been done by dividing the area on horizontal
strips, instead of using the vertical ones. You are encouraged to try this and compare
results with those presented.
Chapter 4
Linear Algebra
1) Linear Algebra and its Applications, D. C. Lay, Addison Wesley, Boston, 2003.
This chapter aims to remind you about the basic operations on vectors and matrices, and
about their properties. It focuses pretty much on columns of a matrix rather than on the
matrix individual entries. The aim is to see a matrix-vector product [A]{x} as a linear
combination of the columns of [A]. Throughout the section the matrices will be shown
by using square brackets [ ], while curly brackets { } will be use to designate vectors.
4.1
4.1.1
A linear equation in the variables x1 ,x2 ,...,xn is an equation that can be written in the
form
a1 x1 + a2 x2 + ... + an xn = b
(4.1)
where b and the coefficients a1 ,a2 ,...,an are real or complex numbers, usually known in
advance, and where variables x1 ,x2 ,...,xn are unknown. The subscript n may be any
positive integer. In a linear equation each term is either a constant or the product of a
constant times the first power of a variable.
The equations
4x1 5x2 + 2 = x1
and
x2 = 2( 6 x1 ) + x3
are both linear because they can be rearranged algebraically as in Equation 4.1:
3x1 5x2 = 2
and
2x1 + x2 x3 = 2 6.
The equations
4x1 5x2 = x1 x2
and
x2 = 2 x1 6
43
CIV6115
44
are not linear because of the presence of the product of two variables x1 x2 in the first and
power of a variable other than 1 in the second (x0.5
1 ).
A system of linear equations (or a linear system of equations) is a set of linear
equations involving the same variables (in each equation) such as x1 , x2 , ..., xn . An example
is
2x1 x2 + 1.5x3 = 8
x1 4x3 = 7.
(4.2)
A solution of the system is a list of numbers (s1 , s2 , ..., sn ) that makes each equation a true
statement when the values s1 , s2 , ..., sn are substituted for x1 , x2 , ..., xn , respectively. For
instance, (5, 6.5, 3) is a solution of system 4.2 because, when these values are substituted
in system 4.2 for x1 , x2 , x3 , respectively, the equations simplify to 8=8 and -7=-7.
The set of all possible solutions (note here that a system might have more than one
solution) is called the solution set of the linear system. Two linear systems are called
equivalent if they have the same solution set. That is, each solution of the first system
is a solution of the second system, and each solution of the second system is a solution of
the first.
Finding the solution set of a system could be thought about as the intersection of two
lines. This can be demonstrated on a simple example of a system:
x1 2x2 = 1
x1 + 3x2 = 3.
The graphs of these two equations are. respectively, lines, l1 (dashed line in Figure 4.1)
and l2 (solid line in Figure 4.1). A pair of numbers (x1 , x2 ) (i.e. the solution of the linear
system) satisfies both equations in the system if and only if the point (x1 , x2 ) lies on both
lines. This point is (3, 2) for the system considered.
3
2
4
x1
CIV6115
45
Of course, two lines could be parallel, such as those that correspond to the system:
l1 : x1 2x2 = 1
l2 : x1 + 2x2 = 3.
These lines are presented in Figure 4.2 as dashed and solid line, respectively. Clearly, a
pair of parallel lines does not have the intersection point and therefore the system does
not have a solution.
4
2
4
x1
x2
1
0.5
0
0.5
1
1.5
4
x1
CIV6115
46
Therefore, to summarise, we can say that a system of linear equations has either:
1. no solution, or
2. exactly one solution, or
3. infinitely many solutions.
A system of linear equations is said to be consistent if it has either one solution or
infinitely many solutions; a system is inconsistent if it has no solutions.
4.1.1.1
Matrix Notation
The essential information about a linear system can be recorded compactly in a rectangular array called a matrix. Given the system
x1 2x2 + x3 = 0
2x2 8x3 = 8
4x1 + 5x2 + 9x3 = 9
(4.3)
1 2
1
0
2 8
4
5
9
is called the coefficient matrix (or matrix of coefficients) of the system 4.3, and the
matrix
1 2
1
0
0
2 8
8
4
5
9 9
is called the augmented matrix of the system. An augmented matrix of a system
consists of the coefficient matrix with an added column containing the constants from the
right hand side of the equations.
The size of a matrix tells us how many rows and columns it has. For example, size of
the augmented matrix presented above is 3x4 (read 3 by 4). The number of rows always
comes first. Matrix notation is useful since it simplifies presentation of the calculations.
4.1.1.2
This section describes a systematic procedure for solving linear systems. The basic strategy is to replace one system with an equivalent system (i.e. the system that has the same
solution set as the original system) that is easier to solve.
Three basic operations (elementary row operations) are used to simplify a linear
system:
1. Interchange two equations,
2. Replace one equation by the sum of itself and a multiple of another equation, and
CIV6115
47
SOLUTION
The elimination procedure is shown here with and without matrix notation, and the
results are placed side by side for comparison:
1 2
1
0
x1 2x2 + x3 =
0
0
2 8
8 .
2x2 8x3 =
8
4
5
9 9
4x1 + 5x2 + 9x3 = 9
First let us keep x1 in the first equation and eliminate it from the other two equations.
Since x1 already does not exist in equation 2, our job is reduced to eliminating it from
equation 3 only. To do this, we add 4 times equation 1 to equation 3, and write the result
in place of equation 3:
x1
2x2 +
x3 =
0
2x2 8x3 =
8
3x2 + 13x3 = 9
1 2
1
0
0
8 .
2 8
0 3 13 9
Now, multiply equation 2 by 1/2 in order to obtain 1 as the coefficient for x2 (this will
simplify the arithmetics in the next step):
x1
2x2 +
x3 =
0
x2 4x3 =
4
3x2 + 13x3 = 9
1 2
1
0
0
4 .
1 4
0 3 13 9
Use the x2 in equation 2 to eliminate 3x2 in equation 3. This can be done by multiplying
equation 2 by 3 and summing with equation 3. The result is written in place of equation
3. The new system has a triangular form:
x1 2x2 + x3 = 0
x2 4x3 = 4
x3 = 3
1 2
1 0
0
1 4 4 .
0
0
1 3
Now, x3 can be calculated from equation 3 (x3 = 3). When this is entered in equation 2,
we can get x2 = 16. Finally, when x3 and x2 are placed in equation 1 we get x1 = 29.
Therefore, the solution of the system of equations is (29,16,3). You can verify this by
substituting these values back into the original system of equations and checking if the
left-hand side and right-hand side of each equation are equal.
end of the example
In real world, we normally use computers for solving system of linear equations. MATLAB
is software that has in-built algorithms (of the kind presented in the previous example) for
this purpose. This is why solving the system of equations 4.3 is very simple in MATLAB.
The solution can simply by obtained by typing next line (see also file Example4_1.m).
[1 -2 1; 0 2 -8; -4 5 9]\[0; 8; -9]
CIV6115
48
Therefore, to get the vector of the solution in Matlab the command that has to be issued
has to be in the form: (Matrix) \ (Vector on right-hand side of system of equations).
Finally, we can say that the matrix that is obtained from another matrix by a sequence of
elementary row operations and the original matrix are called row equivalent matrices.
If the augmented matrices of two linear systems are row equivalent, then the
two systems have the same solution set.
4.1.2
Vector Equations
Important properties of linear systems can be described with the concept and notation of
vectors. The term vector appears in a variety of mathematical and physical contexts. In
this section, we will use vector to mean a list of numbers. This simple idea enables us
to get to interesting and important applications as quickly as possible.
4.1.2.1
Vectors in R2
A matrix with only one column is called a column vector, or simply a vector (we also
call a matrix with only one row - a row vector; however, we will stick with column vectors
in further text). Examples of vectors with two entries are
3
0.2
w1
u=
,
v=
,
w=
1
0.3
w2
where w1 and w2 are any real numbers. The set of all vectors with two entries is denoted
by R2 (read R-two). The R stands for the real numbers that appear as entries in the
vectors, and the exponent 2 indicates that each vector contains two entries.
2
The
vectors in R
are equal if and only if their corresponding entries are equal. Thus
7
4
and
are not equal. We say that vectors in R2 are ordered pairs of real
7
4
numbers.
Given two vectors u and v in R2 , their sum is the vector u + v obtained by summing the
corresponding entries of u and v. For example,
1
2
1+2
3
+
=
=
.
2
5
2 + 5
3
Given a vector u and a real number c, the scalar multiple of u byc is the
vector cu
3
obtained by multiplying each entry in u by c. For example, if u =
and c = 5,
1
3
15
then cu = 5
=
.
1
5
The number c in cu is called a scalar; it is written in lightface type to distinguish it from
the bold face vector u.
CIV6115
4.1.2.2
49
Vectors in R3
Vectors in R3 are 3 1 column matrices with three entries. One example is vector
2
3 .
a=
4
4.1.2.3
Vectors in Rn
Rn (read R-N) denotes the collection of all lists (or ordered n-tuples) of n real numbers,
usually written as n 1 column matrices, such as
u
1
u2
u=
.
..
n
The vector whose entries are all zero is called zero vector and is denoted by 0. (The
number of entries in zero vector is usually clear from the context.)
Equality of vectors in Rn and the operations of scalar multiplication and vector addition
in Rn are defined entry by entry just as in R2 . These operations on vectors have the
following algebraic properties:
1. u + v = v + u
2. (u + v) + w = u + (v + w)
3. u + 0 = 0 + u = u
4. u + (u) = u + u = 0 where u denotes (1)u
5. c(u + v) = cu + cv
6. (c + d)u = cu + du
7. c(du) = (cd)(u)
8. 1u = u
where u, v, and w are vectors in Rn and c and d are scalars.
For simplicity of notation, we also use vector subtraction and write u v instead of
u + (1)v.
4.1.2.4
Linear Combinations
Given vectors v1 , v2 , ..., vp in Rn and given scalars c1 , c2 , ..., cp , the vector y defined by
y = c1 v1 + c2 v2 + ... + cp vp
(4.4)
CIV6115
50
1
1
3v1 + v2 , v1 = v1 + 0v2 , and 0 (= 0v1 + 0v2 ).
2
2
EXAMPLE 4.2
1
7
2
4 , determine whether b can be generated
5 , and b =
2 , a2 =
If a1 =
3
6
5
(i.e. written) as a linear combination of a1 and a2 .
EXAMPLE 4.2:
SOLUTION
The problem is equivalent to determining whether there exist x1 and x2 such that
x1 a1 + x2 a2 = b.
(4.5)
1
2 7
2
5
4
x1
+ x2
=
5
6
3
which is the same as:
x1 + 2x2 = 7
2x1 + 5x2 = 4
5x1 + 6x2 = 3.
Therefore, the vector equation 4.5 is now written in form of system of linear equations.
This system can be solved using the procedure explained in Section 4.1.1.2. The operations
leading to triangularisation of the augmented matrix can be presented in this order:
1 2 7
1 2 7
1 2 7
1 2 7
1 2
7
2 5
4 0 9 18 0 1 2 0 1 2 0 1 2 ,
5 6 3
0 16 32
0 16 32
0 1 2
0 0 0
where the symbol between matrices denotes row equivalence.
Third equation 0x1 +0x2 = 0 is satisfied for arbitrary x1 and x2 . From the second equation
0x1 + 1x2 = 2 we get x2 = 2. Replacing this value in first equation x1 + 2x2 = 7 we can
calculate that x1 = 3. (Note that the pervious example can be easily solved in MATLAB
by simply typing [1 2; -2 5; -5 6]\[7;4;-3] on the command line. Note that this
is possible regardless the fact that number of equations (3) is greater than the number of
unknowns (2).)
Therefore, b is a linear combination of a1 and a2 , with weights x1 = 3 and x2 = 2.
Note that the starting augmented matrix in this example
1 2
7
2 5
4
5 6 3
CIV6115
51
is actually composed of the original vectors a1 , a2 , and b written next to each other
a1 a2 b .
end of the example
Based on the previous example we can say that a vector equation
x1 a1 + x2 a2 + ... + xn an = b
has the same solution as the system of linear equations whose augmented matrix is
a1 a2 ... an b .
(4.6)
In particular, b can be generated by a linear combination of a1 , a2 , ..., an if and only if
there exist a solution to the linear system corresponding to 4.6.
4.1.3
Matrix Equation Ax = b
x1
x2
= x1 a1 + x2 a2 + ... + xn an .
Ax = a1 a2 ... an
.
..
x
n
Note that Ax is defined only if the number of columns of A equals the number of entries
in x.
The vector equation from Example 4.2 can be written in matrix form
1 2
where A = 2 5
5 6
Therefore, Equation
Ax = b
7
x1
, b =
4
and x =
.
x2
3
4.7 is called a matrix equation.
(4.7)
a1 a2 ... an b .
(4.9)
This means that we can now view a system of linear equations in three different, but
equivalent ways: as a matrix equation, as a vector equation, or as a system of linear
equations. When we consider a practical problem, we can choose whichever viewpoint
is most natural. Then we may switch from one formulation of a problem to another
whenever it is convenient. In any case, the matrix equation, the vector equation, and
the system of equations could all solved in the same way - by triangularisation of the
augmented matrix.
CIV6115
4.1.3.1
52
Existence of Solutions
The equation Ax = b has a solution if and only if b is a linear combination of the columns
of A.
An interesting problem related to existence of the solution is to determine whether the
equation Ax = b is consistent for all possible b. This is considered in the next example.
EXAMPLE 4.3
1
3
4
b1
2 6 and b =
b2
If A = 4
find out if the equation Ax = b is consistent for
3 2 7
b3
all possible b1 , b2 , b3 ?
EXAMPLE 4.3:
SOLUTION
We will conduct the standard procedure for triangularisation of the augmented matrix:
1
3
4 b1
1 3 4
b1
1 3 4
b1
4
2 6 b2 0 14 10 b2 + 4b1 0 14 10
b2 + 4b1 .
3 2 7 b3
0 7 5 b3 + 3b1
0 0 0 2b3 + b2 2b1
The equation Ax = b is consistent (i.e. has one or infinite number of solutions) if all three
equations are satisfied. Obviously, the last equation (with zeros as coefficients multiplying
x1 , x2 , and x3 ) could be satisfied only if the right-hand side of equation is equal to zero,
i.e. 2b3 + b2 2b1 = 0. When b1 , b2 , and b3 are chosen to satisfy this equation, then the
system considered is consistent.
end of the example
4.1.3.2
Computation of Ax
We have seen that the product Ax can be calculated as a linear combination of columns
of matrix A. In next example we will present this product in another way as well.
EXAMPLE 4.4
2
3
4
x1
5 3 and x =
x2
Compute Ax, where A = 1
.
x3
6 2
8
EXAMPLE 4.4:
SOLUTION
2
3
4 x1
2
3
4
1
1
5
3
5 3 x2
= x1
+ x2
+ x3
=
x3
6
2
8
6 2
8
CIV6115
53
Therefore, the first entry in the product Ax is a sum of products (sometimes called dot
product) obtained using the first row of A and the entries of x. This can be illustrated
as:
x2
=
.
x3
Therefore, the calculation can be done directly, without writing down all intermediate
steps presented in Equation 4.10. Similarly, the second entry in Ax can be calculated by
multiplying the entries in the second row of A by corresponding entries in x and then
summing their products:
x1
1 5 3 x2
x1 + 5x2 3x3
.
=
x3
The third entry can be obtained in similar way using the third row of matrix A.
2
3
4
2
5
5 3 and vector x =
and calculation of their
Defining matrix A = 1
7
6 2
8
product b = Ax can be done in MATLAB in the following way:
1 0 0
I = 0 1 0 .
0 0 1
Multiplying this matrix by any vector x in R3 would produce the result equal to vector x
Ix = x.
This matrix can be generated in MATLAB using:
>> I=eye(3);
On the other hand if matrix A, say of size 3 3 (m = n = 3), contains only zeros it can
be generated in MATLAB as:
>> A=zeros(3);
Multiplying this matrix by any vector x in R3 would produce a zero vector 0:
0 0 0
0
0 0 0 x =
0 .
0 0 0
0
Important properties of matrix-vector product, where A is a m n matrix, u and
v are vectors in Rn , and c is a scalar are:
CIV6115
54
1. A(u + v) = Au + Av;
2. A(cu) = c(Au).
4.1.4
In this section, solution sets for homogeneous and nonhomogeneous systems of linear
equations are considered.
4.1.4.1
EXAMPLE 4.5:
SOLUTION
Let A be the matrix of coefficients of the system. Let us write the augmented matrix for
the system of equations and transform it into a triangular form:
3
5 4 0
3
5 4 0
3 5 4 0
3 2
4 0 0
3
0 0 0 3
0 0 .
6
1 8 0
0 9
0 0
0 0
0 0
It can be seen that the third equation is satisfied for any values of x1 , x2 , and x3 while
x2 can be calculated from the second equation (3x2 = 0), i.e. x2 = 0. Replacing this into
the first equation, we get
3x1 + 5 0 4x3 = 0.
Since this is one equation with two variable, we are allowed to choose a value for one
of the variables freely. Therefore, if we choose that x3 = t, where t is an arbitrary real
number, then we can calculate x1 as
4
3x1 + 5 0 4t = 0, i.e. x1 = t.
3
CIV6115
55
Therefore, the considered system of linear equations has a nontrivial solution. The solution is nontrivial for t 6= 0 and can be presented in the form
4
3
0 t,
x=
1
where t is an arbitrary real number.
end of the example
4.1.4.2
3
5 4
7
1
4 and b =
Describe all solutions of Ax = b where A = 3 2
4
6
1 8
that the matrix A in this example is kept the same as in Example 2.5 related to
homogeneous system of linear equations.
EXAMPLE 4.6:
. Note
solving a
SOLUTION
As in Example 4.5, the augmented matrix can be transformed into its triangular form
3
5 4
3
5 4
3
5 4
7
7
7
3 2
6 0
2
4 1 0
3
0
1
0
6
1 8 4
0 9
0 18
0 9
0 18
3 5 4 7
0 2 .
0 1
0 0
0 0
From the second equation we calculate that x2 = 2. Replacing this in first equation gives
3x1 + 5 2 4x3 = 7, i.e. by choosing, as before, that x3 = t (where t is an arbitrary real
number) we get x1 = 43 t 1. Therefore, the final solution can be written in the form
4
3t 1
2
x=
.
t
This can be presented as a sum of parts:
1 43
2
0
x=
+
t = xp + xh ,
0
1
where the second part is the solution (denoted as xh ) of an equivalent homogeneous system
Ax = 0 of linear equations (see solution of Example 4.5) while the first part (denoted as
xp ) is so called particular solution of system of equations under consideration.
end of the example
CIV6115
56
At the end we can define this more precisely. Namely, suppose the equation Ax = b is
consistent for some given b, and let xp be a solution. Then the solution set of Ax = b is
the set of all vectors of the form x = xp + xh , where xh is any solution of the homogeneous
equation Ax = 0.
Note that if a system is consistent
and has a unique solution (such as the one shown in
0
0
Example 4.1), then xh =
and therefore x = xp .
0
4.1.5
Linear Independence
(4.11)
EXAMPLE 4.7
1
4
2
2 , v2 =
5 , v3 =
1 .
Let v1 =
3
6
0
(a) Determine if the set v1 , v2 , v3 is linearly independent.
(b) If possible, find a linear dependence relation among v1 , v2 , v3 .
EXAMPLE 4.7:
SOLUTION
(a) We will first triangularise the augmented matrix of the homogeneous system:
1
4
2 0
1 4 2 0
1 4 2 0
2 5 1 0 0 3 3 0 0 1 1 0 .
3 6 0 0
0 6 6 0
0 0 0 0
Clearly, the system was reduced to two equations (with three variables), where one variable, say x3 , could be chosen arbitrarily, while the other two variables can be then calculated from second and third equation. Therefore, there exist nontrivial solution of the
system. This means that vectors v1 , v2 , and v3 are linearly dependent.
(b) If we set x3 = t, then from the second equation we can get x2 = t. Now, the first
equation has the form x1 + 4(t) + 2t = 0, i.e. x1 = 2t. Therefore, the linear dependence
of vectors can be shown as:
2tv1 tv2 + tv3 = 0,
where t is an arbitrary real number.
end of the example
CIV6115
4.1.5.1
57
The columns of a matrix A are linearly independent if and only if the equation Ax = 0
has only the trivial solution. Otherwise, the columns are linearly dependent.
EXAMPLE 4.8
0 1
4
Determine if the columns of the matrix A = 1 2 1 are linearly independent.
5 8
0
EXAMPLE 4.8:
SOLUTION
0
1
5
1
2 1 0
1 2 1 0
1
4 0
2 1 0 0
1
4 0 0 1
4 0 .
8
0 0
0 2
5 0
0 0 13 0
Here, it is clear that this equation has only trivial solution (i.e. x3 = 0 from the third
equation, then x2 = 0 from the second, and finally x1 = 0 from the first). Therefore, the
columns of the matrix A are linearly independent.
end of the example
4.1.5.2
1. A set of two vectors {v1 , v2 } is linearly dependent if at least one of the vectors is
a multiple of the other. The set is linearly independent if and only if neither of the
vectors is a multiple of the other.
3
6
For example, vectors v1 =
and v2 =
are linearly dependent since v2
1
2
3
is a multiple of v1 , i.e. v2 = 2v1 . On the other hand, vectors v3 =
and
2
6
v4 =
are linearly independent since they are not multiplies of each other.
2
Therefore, the only way that these vectors satisfy the equation cv3 + dv4 = 0 is that
c = d = 0.
2. A set S = {v1 , v2 , ..., vp } of two or more vectors is linearly dependent if and only if
at least one of the vectors in S is a linear combination of the others.
3. If a set contains more vectors than there are entries in each vector, then the set is
linearly dependent. That is, any set {v1 , v2 , ..., vp } in Rn is linearly dependent if
p > n.
2
4
2
For example, set of vectors
,
,
is linearly dependent because
1
1
2
there are three vectors in the set (p = 3) and there are only two entries in each
vector (n = 2), i.e. p > n.
4. If a set S = {v1 , v2 , ..., vp } in Rn contains the zero vector, then the set is linearly
dependent.
CIV6115
58
This is easy to prove, since if, for example, v1 = 0, then it is always possible to
write the linear combination of vectors in which not all coefficients are equal to zero,
such as: 1v1 + 0v2 + 0v3 + ... + 0vp = 0.
EXAMPLE 4.9
Determine by visual inspection if the given set of vectors
1 2 3 4
2
7 , 0 , 1 , 1
3 ,
(a)
(b)
6
9
5
8
4
4
6
(c)
,
.
6
9
10
15
EXAMPLE 4.9:
is linearly independent.
0 1
0 , 1
0
8
SOLUTION
(a) The set contains four vectors, each of which has only three entries. Therefore, the set
is linearly dependent.
(b) The set contains zero vector, therefore it is linearly dependent.
(c) The set is linearly independent, since neither of the vectors is multiple of the other.
Namely, first three entries in the second vector are equal to 32 times the corresponding
entries in the first vector. However, this is not the case with the last entry.
end of the example
4.2
4.2.1
Matrix Algebra
Matrix Operations
In this section we will review basic matrix operations. To denote a matrix we will again
use a capital letter. An example of a matrix is a m n matrix A :
A = a1 . . . aj . . . an
where the columns are denoted by boldface letters.
To shorten the description of the matrix, we can write it in the form A = [aij ] (or
Amn = [aij ] if we want to emphasise the matrix size m n).
CIV6115
59
The diagonal entries in an m n matrix A = [aij ] are a11 , a22 , a33 , ... and they form the
main diagonal of A.
A diagonal matrix is a square matrix
is the n n identity matrix, In :
1
..
.
In = 0
.
..
0
0
..
.
... 0 .
..
.
... 1
... 0 ...
..
.
... 1
..
.
... 0
An m n matrix whose entries are all zero is called zero matrix and is written as 0.
4.2.1.1
Two matrices are equal if they have the same size (i.e. the same number of rows and
the same number of columns) and if their corresponding columns are equal (which is
equivalent to saying that their corresponding entries are equal).
If A and B are m n matrices, then the sum A + B is the m n matrix which columns
are the sums of the corresponding columns in A and B. The sum A + B can be calculated
only when A and B are the same size.
For example, if we have matrices
4 0 5
1 1 1
2 3
A=
, B=
, C=
1 3 2
3 5 7
0
1
then
A+B =
5 1 6
2 8 9
4 0 5
1 1 1
A 2B = A + (2)B =
+ (2)
=
1 3 2
3 5 7
4 0 5
2 2 2
2 2
3
=
+
=
.
(4.12)
1 3 2
6 10 14
7 7 12
The calculation (where the result is denoted as D) can be performed in MATLAB by
typing:
>> A=[4 0 5; -1 3 2]; B=[1 1 1; 3 5 7];
>> D=A-2*B;
CIV6115
60
Note that we replaced A 2B with A + (2)B in Equation 4.12 because the usual rules
in algebra apply to sums and scalar multiplies of matrices. These rules are defined in a
form of the following theorem.
Let A, B, and C be matrices of the same size, and let r and s be scalars. Then the
following rules apply:
1. A + B = B + A
2. (A + B) + C = A + (B + C)
3. A + 0 = A
4. r(A + B) = rA + rB
5. (r + s)A = rA + sA
6. r(sA) = (rs)A.
4.2.1.2
Matrix Multiplication
When a matrix B multiplies a vector x then we can think about it as a linear transformation of vector x into another vector Bx. If this vector is then multiplied in turn
by a matrix A, the resulting vector is A(Bx). This can again be thought of as a linear
transformation of vector Bx which produces the resulting vector A(Bx).
Therefore, A(Bx) is produced from x by a composition of two linear transformations. This is schematically presented in Figure 4.4a.
However, our goal is to represent this composition as a multiplication by a single
matrix, denoted by AB, so that A(Bx) = (AB)x. This idea is represented in Figure
4.4b.
CIV6115
If A is m n matrix, B n p matrix
b1 . . .
x1
..
x=
.
x
p
bp
61
then
Bx = x1 b1 + x2 b2 + ... + xp bp .
Now we can calculate the resulting vector as
A(Bx) = A(x1 b1 ) + A(x2 b2 ) + ... + A(xp bp ) = x1 Ab1 + x2 Ab2 + ... + xp Abp .
Therefore, the vector A(Bx) is a linear combination of vectors (columns) Ab1 , Ab2 , ..., Abp
using the entries of vector x as weights. This can be rewritten in the form:
This way, we found a matrix (which is Ab1 Ab2 ... Abp ) that transforms the vector
x into A(Bx).
Therefore, instead of applying two transformations on vector x and then Ax one after
another,
we can apply only one transformation on vector x, provided we use the matrix
Ab1 Ab2 ... Abp for this purpose. For this, it is necessary to calculate the matrix
in question, denoted as AB, first.
Now we can define multiplication between two matrices A and B. If A is an m n
matrix, and if B is an n p matrix with columns b1 , b2 , ..., bp , then the product AB is
the m p matrix which columns are Ab1 , Ab2 , ..., Abp . That is,
4
3 6
.
1 2 3
2
3
1 5
and B =
CIV6115
EXAMPLE 4.10:
62
SOLUTION
(AB)13 =
2 3
(AB)22 =
1 5
3
2
6
3
= 2 6 + 3 3 = 12 + 9 = 21.
= 1 3 + (5) (2) = 3 + 10 = 13.
21
-1
13
-9
If we are interested only in elements (AB)13 and (AB)22 we can read them individually
by typing:
>> AB(1,3) or
>> AB(2,2)
end of the example
CIV6115
4.2.1.3
63
2. A(B + C) = AB + AC
3. (B + C)A = BA + CA
5. Im A = A = AIn
8 4
5 2
2 3
,B=
and C =
.
For example check if AB = AC for A =
5 5
3
1
4
6
1 7
although B 6= C.
It can be found that AB = AC =
2 14
Warning 3: If a product AB is the zero matrix, than it is not necessarily true that
A = 0 or B = 0.
4.2.1.4
Powers of a Matrix
Transpose of a Matrix
5
2
5
1
0
T
For example, if A = 1 3 then A =
.
2 3 4
0
4
This corresponds to MATLAB commands:
CIV6115
64
4.2.2
Inverse of a Matrix
3 4
.
5 6
SOLUTION
To calculate the inverse matrix,we can use the fact that AA1 = I. For this purpose we
a b
will assume that A1 =
. By using the rule for multiplication of matrices we can
c d
get:
3 4
a b
3a + 4c 3b + 4d
1
AA =
=
,
5 6
c d
5a + 6c 5b + 6d
and then we can use equality AA1 = I:
3a + 4c 3b + 4d
1 0
=
.
5a + 6c 5b + 6d
0 1
CIV6115
65
3 0
0 3
5 0
0 5
0 4
b
=
6 0
c
0 6
d
3 0 4 0 1
3 0 4 0 1
3
0 3 0 4 0 5 0 6 0 0 0
5 0 6 0 0 0 3 0 4 0 0
0 5 0 6 1
0 5 0 6 1
0
3
0
0
0
0
3
0
0
4
0
2
0
1
0
0
1
to the solution:
0 4 0 1
0 2 0 5
3 0 4 0
5 0 6 1
3
0
0
0
0
3
0
5
4
0
2
0
0
4
0
6
1
0
5
1
0
1
4
0
.
0
5
2 3
Note here that rank(A) = 4, meaning that matrix A is invertible. From the last equation
it follows that 2d = 3, i.e. d = 1.5, while from the third equation c = 2.5. From second
equation 3b + 4(1.5) = 0, i.e. b = 2.0. Finally, from first equation we get 3a + 4(2.5) = 1
i.e. a = 3.0.
Now we can write the final form of matrix A1 :
3.0
2.0
1
A =
.
2.5 1.5
This solution can be easily obtained in MATLAB using this set of commands:
>> A=[3 4; 5 6];
>> A_inverse=A^(-1);
end of the example
However, there is a simpler way of finding the inverse matrix of a 2 2 matrix.
a11 a12
. If a11 a22 a12 a21 6= 0 then A is invertible and
Let A =
a21 a22
1
a22 a12
1
.
A =
a11
a11 a22 a12 a21 a21
If a11 a22 a12 a21 = 0 then A is not invertible.
CIV6115
66
The quantity a11 a22 a12 a21 is called determinant of A, and we write
detA = a11 a22 a12 a21 .
Therefore, a 2 2 matrix is invertible if and only if detA 6= 0.
The previous example can now be solved easily:
1
6 4
6 4
3.0
2.0
1
A =
= 0.5
=
.
3
5
3
2.5 1.5
3 6 4 5 5
The next theorem provides four useful facts about invertible matrices.
1. If A is invertible n n matrix, then for each b in Rn , the equation Ax = b has the
unique solution x = A1 b.
2. If A is an invertible matrix, then A1 is invertible and
(A1 )1 = A.
3. If A and B are n n invertible matrices, then so is AB, and the inverse of AB is
the product of the inverses of A and B in the reverse order. That is
(AB)1 = B 1 A1 .
4. If A is an invertible matrix, then so is AT , and the inverse of AT is the transpose of
A1 . That is
(AT )1 = (A1 )T .
4.2.3
We defined earlier that a non invertible matrix is called a singular matrix, while an
invertible matrix is called a nonsingular matrix. In practical work, we might occasionally encounter a nearly singular matrix or ill-conditioned matrix. This is an
invertible matrix that can become singular if some of its entries are changed ever so
slightly. In this case the matrix is sensitive to roundoff errors, so small change in the
input data can cause the matrix to become singular.
Some matrix programs compute a condition number for a square matrix. The larger the
condition number, the closer the matrix is to being singular. The condition number of
the identity matrix is 1. A singular matrix has an infinite condition number. Condition
number of a matrix can be obtained in MATLAB using command
>> cond(A).
CIV6115
4.3
67
Determinants
In the past when many mathematical problems were dealt with without help of computers (and by using matrices of small size), determinants played a major role in analytic
geometry and other parts of mathematics. Today, determinants are of little numerical value in the large-scale matrix computations that occur so often. Nevertheless,
determinants still give important information about matrices. This is the main
reason why they are briefly being introduced in this section.
In Section 4.2.2 we defined a determinant of a 2 2 matrix. Here we will extend this
definition to matrices of bigger size.
For n 2, the determinant of an n n matrix A = [aij ] is the sum of n terms of the
form a1j detA1j , with plus and minus signs alternating, where the entries a11 , a12 , ..., a1n
are from the first row of A. This can be written as:
detA = a11 detA11 a12 detA12 + ... + (1)
1+n
a1n detA1n
n
X
=
(1)1+j a1j detA1j .
j=1
Aij is a submatrix that is obtained when ith and j th column are removed from matrix
A.
EXAMPLE 4.12
1
5
0
4 1 .
Compute the determinant of A = 2
0 2
0
EXAMPLE 4.12:
SOLUTION
det A = a11 det A11 a12 det A12 + a13 A13
i.e.
4 1
2 1
4
5
+0 2
det A = 1
0
0 2
2
0
0
= 1(02)5(00)+0(40) = 2.
(4.13)
Then
det A = a11 C11 + a12 C12 + ... + a1n C1n .
This formula is called a cofactor expansion across the first row of A. Now we can
write it in more general form.
CIV6115
68
+ + ...
+
+ +
.
..
..
.
.
EXAMPLE 4.13
EXAMPLE 4.13:
3 7
8
9 6
0
2 5
7
3
0
0
1
5
0
.
0
0
2
4 1
0
0
0 2
0
SOLUTION
The cofactor expansion down to the first column of A has all terms equal to zero except
the first. Thus
2 5
7
3
0
1
5
0
det A = 3
0 C21 + 0 C31 0 C41 + 0 C51 .
2
4 1
0
0
0 2
0
Now we will expand the 4 determinant down the first column in order to take advantage
of the zeros in this column.
1
5
0
4 1 .
det A = 3 2 2
0 2
0
This determinant was computed in Example 4.12 and found to be equal -2. Therefore
det A = 3 2 (2) = 12.
If we were using MATLAB for solving Example 4.13, we would need to issue the following
commands:
>> A=[3 -7 8 9 -6; 0 2 -5 7 3; 0 0 1 5 0; 0 0 2 4 -1; 0 0 0 -2 0];
>> det_A=det(A);
end of the example
CIV6115
69
5 2
8
1
4 = 5 1 (3) = 15.
Example: det 0
0
0 3
2. A square matrix is invertible if and only if det A 6= 0.
This property is very useful, since it gives us information if the matrix is singular
(singular matrices are non invertible matrices).
3. If A is an n n matrix, then det AT = det A.
4. If A and B are n n matrices, then det AB = (det A)(det B).
4.4
Vector Spaces
1) Linear Algebra and its Applications, D. C. Lay, Addison Wesley, Boston, 2003.
2) Linear Algebra with Applications, S. J. leon, Prentice Hall, New Jersey, 1998.
A vector space is a nonempty set V of objects, called vectors, on which two operations
(called addition and multiplication by scalars) are defined, and on which the following
ten axioms apply. The axioms must hold for all vectors u, v, and w in V and for all scalars
(real numbers) c and d.
1. The sum of u and v, denoted by u + v, belongs to V .
2. u + v = v + u.
3. (u + v) + w = u + (v + w).
4. There is a zero vector 0 in V such that u + 0 = u.
5. For each u in V , there is a vector u in V such that u + (u) = 0.
6. The scalar multiple of u by c, denoted by cu, is in V .
7. c(u + v) = cu + cv.
8. (c + d)u = cu + du.
9. c(du) = (cd)u.
10. 1u = u.
Using these axioms it is possible to show that zero vector in Axiom 4 is unique, and the
vector u, called the negative of u, in Axiom 5 is unique for each u in V . It is also
possible to prove that for each u in V and scalar c:
0u = 0
c0 = 0
CIV6115
70
u = (1)u.
Given a vector space V , it is often possible to form another vector space by taking a
subset S of V and using the operations defined on V . Since V is a vector space, the
operations of addition and scalar multiplication always produce another vector in V. In
order that the subset S is also a vector space, it is necessary that the set S is closed under
the operations of addition and scalar multiplication. That is, the sum of two elements of
S must always be an element of S and the product of a scalar and an element of S must
always be an element of S. Now we can define subspaces.
4.4.1
Vector Subspaces
SOLUTION
In this example, V = Rn . We have to prove that all vectors xn1 that are solutions of
Ax = 0 form a subspace of vector space Rn . Note that we were told in this example that
Rn is a vector space, so we take it for granted, i.e. we are not required to prove it.
Now, if all solutions of Ax = 0 form a subspace S, then axiom (a) requires that 0 vector is
also one of the solutions. It is easy to see that if we assume that zero vector is a solution,
then
Ax = A0 = 0
i.e. the equation is satisfied. Therefore, 0 S.
Now, let us check if axiom (b) is satisfied, i.e. if x + y is a solution when x and y are.
The fact that x and y are solutions of the equation means that Ax = 0 and Ay = 0.
Using this fact, it is easy to see that
A(x + y) = Ax + Ay = 0 + 0 = 0
i.e. that x + y S when x S and y S.
Finally, if x S, let us check if x is a solution of equation.
A(x) = Ax = 0 = 0
This proves that x S. Therefore, we can say that set of all solutions to the homogeneous system Ax = 0 form a subspace of vector space Rn . This subspace is called the
nullspace of A.
CIV6115
4.4.2
71
This section defines conditions under which a set of vectors in V or S is linearly (in)dependent.
Definitions are similar to those already defined for vectors in Rn .
A set of vectors {v1 , v2 , ..., vp } in V is said to be linearly independent if the vector
equation
c1 v1 + c2 v2 + ... + cp vp = 0
(4.14)
has only the trivial solution c1 = c2 = ... = cp = 0.
The set {v1 , v2 , ..., vp } is said to be linearly dependent if Equation 4.14 has a nontrivial
solution, that is there are some weights c1 , c2 , ..., cp , not all zero, such that Equation
4.14 is satisfied.
Another way of defining linear dependency could be formulated as: A set {v1 , v2 , ..., vp }
of two or more vectors, with v1 6= 0, is linearly dependent if and only if some vj (with
j > 1) is a linear combination of the preceding vectors v1 , v2 , ..., vj1 .
EXAMPLE 4.15
If p1 (t) = 1, p2 (t) = t, and p3 (t) = 4 t, check if the set {p1 , p2 , p3 } is linearly independent.
EXAMPLE 4.15:
SOLUTION
SOLUTION
The set {sin t, cos t} is linearly independent in t [0, 1] because sin t and cos t are not
multiples of one another as vectors for all t [0, 1]. Namely, there is no scalar c such that
cos t = c sin t for all t [0, 1]. However, the set {sin t cos t, sin 2t} is linearly dependent
because of identity: sin 2t = 2 sin t cos t for all t.
end of the example
4.4.3
2
2
For example, vectors b1 =
and b2 =
are linearly independent since
1
2
they are not multiples of each other. If all vectors in R2 could be expressed as linear
CIV6115
72
combinations of these two vectors, then we can say that they form a basis of R2 space.
This is the case, and can be easily seen by graphical presentation of vectors. Namely,
Figure 4.5 shows that any vector in R2 can be obtained by
linear
combination of b1
5
and b2 . In the figure only two examples for vectors s1 =
= 1b1 1.5b2 and
2
3
= 2b1 + 0.5b2 are presented.
s2 =
3
CIV6115
e1 =
73
would be
0
0
1
0
1
0
.. .
.. , . . . , en =
.. , e2 =
.
.
.
1
0
0
Every vector in V can be uniquely defined as a linear combination of vectors that belong to
a basis of space V . The following theorem (called the unique representation theorem)
formalises it:
Let B = {b1 , b2 , ..., bn } be a basis for a vector space V . Then for each x in V , there
exists a unique set of scalars c1 , c2 , ..., cn such that
x = c1 b1 + c2 b2 + ... + cn bn .
4.4.4
(4.15)
1. If a vector space V has a basis B = {b1 , b2 , ..., bn }, then any set in V containing
more than n vectors must be linearly dependent.
2. If a vector space V has a basis of n vectors, then every other basis of V must consist
of exactly n vectors. This theorem means that every basis of a vector space has the
same number of vectors in it.
3. If a basis of a vector space consists of n vectors, then we say that the vector
space is finite-dimensional, with dimension n. Otherwise, the space is infinitedimensional.
4. Let V be a pdimensional vector space, p 1. Any linearly independent set of
exactly p elements in V is automatically a basis for V . This is called the basis
theorem.
4.5
(4.16)
(4.17)
CIV6115
74
conclusions in Section 4.3 the invertible matrix is a matrix which determinant is equal to
zero. Therefore, Equations 4.16 and 4.17 are equivalent to the condition that
|A I| = 0.
(4.18)
5 2
6 1
0
3 8 0
.
Find the eigenvalues of A =
0
0
5 4
0
0
0 1
EXAMPLE 4.17:
SOLUTION
5
2
6
1
0 3
8
0
det(A I) =
0
0 5
4
0
0
0 1
We defined in Section 4.3 that the determinant of a triangular matrix is equal to multiples
of the entries on the main diagonal. Therefore
det(A I) = (5 )(3 )(5 )(1 ) = 0
is the characteristic equation of A. It is clear here that eigenvalues of A are
1 = 1, 2 = 3, 3 = 4 = 5.
Actually, we can say that the eigenvalues of a triangular matrix are the entries on
its main diagonal.
The eigenvalues of the matrix can be obtained in MATLAB in the following way
>> A=[5 -2 6 1; 0 3 -8 0; 0 0 5 4; 0 0 0 1];
>> lambda=eig(A);
end of the example
The previous characteristic equation could be expanded to
4 143 + 682 130 + 75 = 0.
This expansion was done only to show that if A ia an n n matrix, then the characteristic
equation is a polynomial of degree n (often called the characteristic polynomial). In
this example the matrix is of size 4 4 and the characteristic equation is a polynomial of
degree 4. It is also shown in this example that an n n matrix has n eigenvalues. In this
example eigenvalue 5 occurred two times. In this case it could be said that the eigenvalue
= 5 has multiplicity 2.
When calculated the eigenvalues are normally presented in increasing order. Therefore,
if we are talking about the first eigenvalue in the previous example, then we refer to value
= 1.
CIV6115
EXAMPLE 4.18
75
3
2
.
3 2
SOLUTION
3
2
3
2
= 2 12 = 0.
b b2 4ac
x1/2 =
.
2a
In our case this is:
1/2 =
17
1 + 48
=
.
2
2
Therefore, 1 = 3 and 2 = 4.
Now let us find the eigenvector that corresponds to eigenvalue 1 = 3. We know that
this vector has to satisfy equation (A 1 I)x1 = 0, i.e.
3
2
1 0
6 2
x11
0
+3
x1 =
=
.
3 2
0 1
3 1
x12
0
Triangularisation of the augmented matrix leads to:
6 2 0
6 2 0
=
.
3 1 0
0 0 0
Therefore, we get 6x11 +2x12 =0. We are free to choose any value for, say, x12 . If we choose
x12 = 1 then x11 = 1/3. Therefore, the first eigenvector can be written as:
x11
1/3
x1 =
=
.
x12
1
Since, we were free to choose x12 ir is important to notice that any multiple of the
eigenvector found is the eigenvector as well. Namely, the absolute values in the vector are
not important; what is important are the ratios between values in each coordinate. This
= 13 , whatever we choose for
ratio is always the same. In our example it is equal to xx11
12
x12 . Note that the first subscript in xij denoted the eigenvector number, while the second
denotes the coordinate place in the vector itself.
To calculate the second eigenvector, we follow the same procedure.
0
3
2
1 0
1
2
x21
=
.
4
x2 =
x22
0
3 2
0 1
3 6
Triangularisation of the augmented matrix leads to:
1
2 0
1 2 0
=
.
3 6 0
0 0 0
CIV6115
76
Therefore, we get x21 + 2x22 =0. We are free to choose any value for, say, x22 . If we
choose x22 = 1 then x21 = 2. Therefore, the second eigenvector can be written as:
2
x21
x2 =
=
.
1
x22
0
-3
V =
0.8944
0.4472
-0.3162
0.9487
Note that if we multiply the vector in the first column (that corresponds to the eigenvalue
1
equal to 4) by 0.4472
>> V(:,1) * 1/0.4472
then we get:
2.0001
1.0000
which is the same as the vector that we calculated (if we neglect small roundoff error).
Now if we multiply the vector in the second column (that corresponds to the eigenvalue
1
equal to -3) by 0.9487
>> V(:,2) * 1/(0.9487)
then we get:
-0.3333
1.0000
which is the same as the vector that we calculated.
end of the example
You could notice that each eigenvalue has a corresponding eigenvector. Since eigenvectors
are solutions of equation
(A I)x = 0
then we can say that they are the null space (see Section 4.4.1) of the matrix A I. This
space is a subspace of Rn and is called the eigenspace of A. The eigenspace consists of
the zero vector and all the eigenvectors (including all multiples of eigenvectors that we
calculate) corresponding to .
CIV6115
4.5.1
77
Fundamentals of Linear State Space Systems, J. S. Bay, McGraw Hill, Boston, 1999.
If v1 , v2 , ..., vn are eigenvectors of an nn matrix A, all of whose eigenvalues are distinct,
then these eigenvectors are linearly independent.
It could be shown that these linearly independent vectors form a basis of ndimensional
vector space. This means, as we learned before, than any vector in the same vector space
can be written as a linear combination of eigenvectors. This is very important
concept in structural dynamics, buckling theory, and so on and is called the expansion theorem. This theorem will extensively be employed throughout your Vibration
Engineering (CIV6180) module.
4.5.2
Apart from matrices with distinct eigenvalues, there are those where eigenvalues repeat
themselves (as in Example 4.17). However, we will not study those further. It should
also be mentioned that there are eigenvalues and eigenvectors that are complex numbers/vectors (rather then real numbers/vectors) but these also are not subject of this
module.
Chapter 5
Time-Domain Models
Contemporary Linear Systems using Matlab, R. D. Strum, D. E. Kirk, Brooks/Cole, 2000.
This chapter deals with two types of time-domain models of continuous systems. These
are: the differential equation model and the convolution model.
5.1
(5.1)
where m, c, and k are the mass, damping and stiffness of the system, while y(t), y(t),
and y(t) are output of the system and its first and second derivative, respectively (i.e.
in physical terms these are the displacement, velocity and acceleration responses of the
system, respectively).
78
CIV6115
79
In general, linear constant-coefficient Nth -order DEs for SISO systems can be written in
this form:
dy(t)
dx(t)
dN y(t)
dL x(t)
a0 y(t) + a1
+ ... + aN
= b0 x(t) + b1
+ ... + bL
dt
dtN
dt
dtL
where y(t) and x(t) represent the system output and input. A more concise representation
of Nth order DE using finite summations is
N
X
dk y(t) X dk x(t)
ak
=
bk
.
k
k
dt
dt
k=0
k=0
(5.2)
In this text we will consider only cases where the highest derivative of the output is greater
than or equal to the highest input derivative, that is, N > L. Equation 5.1, where N = 2
and L = 0, belongs to this category. This equation is DE of the second order. The order
of a DE is the order of the highest derivative of the output function that appears in the
equation.
Typically, we have input acting on a system defined, and the task is to calculate the
output. Finding the output of the system represented by a DE, is equivalent to finding
the solution y(t) of the DE. The complete solution of a DE includes a component due to
initial conditions (i.e. solution to a corresponding homogeneous DE) and a component
caused by the forcing (i.e. input) function (so called the particular solution). In the rest
of this section we will only consider the first part of the solution, while the particular one
will be considered later in Section 5.2.2.
Initial condition solution of a differential equation is a solution of a, so called,
homogeneous DE, and is consequently called the homogeneous solution. Homogeneous differential equation is equation in which the input (in Equation 5.2) and all
its derivatives are set to zero:
N
X
dk y(t)
ak
= 0.
(5.3)
k
dt
k=0
A trial solution of this equation can be written in the form
y(t) = Cest .
(5.4)
(5.5)
Cest cannot be zero, since it corresponds to the trivial solution y(t) = 0. Therefore, we
can factor it out. The remaining terms must satisfy the algebraic equation:
a0 s0 + a1 S 1 + ... + aN sN = 0
(5.6)
This result is known as the characteristic equation, and can also be written as
N
X
ak sk = 0.
(5.7)
k=0
CIV6115
80
systems described by differential equations with real coefficients, complex roots must
appear in conjugate pairs.
For each characteristic root the solution of homogeneous DE 5.3 has the form given in
Equation 5.4, where constants C are different for each of them. The final solution of the
homogeneous equation (i.e. the homogeneous solution) can be written as
yh (t) = C1 es1 t + C2 es2 t + ... + CN esN t ,
(5.8)
5.2
5.2.1
Homogeneous Solution
Let us consider a second order homogeneous differential equation and let us find its
solution for all possible values of characteristic roots.
For this purpose we will consider the homogeneous form of equation of motion 5.1:
my(t) + cy(t) + ky(t) = 0
(5.9)
that describes the system presented in Figure 5.1 when x(t) = 0. We can implement the
procedure described in Section 5.1 to find the homogeneous solution. First we get the
characteristic equation:
ms2 + cs + k = 0.
The two solutions of this quadratic characteristic equation are:
c c2 4mk
c + c2 4mk
s1 =
and s2 =
.
2m
2m
The two roots of the characteristic equation will take one of the three forms:
two different real numbers,
a pair of complex-conjugate numbers, and
a repeated root which, provided the coefficients m, c and k are real, must be real.
Here we will consider each case separately.
CIV6115
5.2.1.1
81
The solutions of the characteristic equation are real and distinct when c2 4mk > 0. As
we learned in the case of Nth -order differential equation, the homogeneous solution in this
case is a linear combination of the solutions of the form y(t) = Cest :
yh (t) = C1 e
s1 t
s2 t
+ C2 e
= C1 e
c2 4mk
t
2m
+ C2 e
c2 4mk
t
2m
c+
(5.10)
y(t = 0) = y0 .
(5.11)
and
For this specific system, y0 and y0 are actually initial displacement and velocity of the
system, respectively.
5.2.1.2
The solutions of the characteristic equation are complex conjugates when c2 4mk < 0.
In this case
p
c j 4mk c2
c + j 4mk c2
s1 =
and s2 =
2m
2m
and the solution can be written in the form:
s1 t
yh (t) = C1 e
+ C2 e
s2 t
= C1 e
ct
2m
C1 e
cj
4mkc2
t
2m
4mkc2
t
2m
+ C2 e
+ C2 e
c+j
4mkc2
t
2m
4mkc2
t
2m
Using Euler formula ejx = cos x j sin x we can rewrite the solution in the form
ct
4mk c2
4mk c2
t j sin
t +
yh (t) = e 2m C1 cos
2m
2m
4mk c2
4mk c2
C2 cos
t + j sin
t ,
2m
2m
i.e.
yh (t) = e
ct
2m
(C1 + C2 ) cos
4mk c2
t + (C1 + C2 )j sin
2m
4mk c2
t .
2m
ct
4mk c2
4mk c2
yh (t) = e 2m C cos
t + D sin
t .
2m
2m
Constants C and D can again be found from initial conditions 5.10 and 5.11.
CIV6115
5.2.1.3
82
Repeated Roots
Finally, the case when the roots of the characteristic equation are equal occurs when
c2 4km = 0. In this case
c
s1 = s2 =
,
2m
and the solution of the homogeneous equation (given here without formal proof) is
c
yh (t) = (C1 t + C2 )e 2m t .
Again, C1 and C2 can be found from initial conditions of the kind given in Equations 5.10
and 5.11.
5.2.1.4
As mentioned before, digital computers (and therefore any software used, such as MATLAB)
cannot deal with continuous equations. Therefore, instead considering input x(t) as a
continuous signal, we have to make a discrete version of it in chosen, usually equally
spaced, intervals. As a sampling interval we will choose t.
Now we can solve the differential equation using a numerical procedure. As a result,
we will get the output y(t) at the discrete points in time, i.e. at the same point in time
at which the discrete input was defined.
There are many different numerical procedures that deal with solution of second order
differential equation that can be programmed in MATLAB. Some of these are Newmarks
procedure, Fox-Goodwin procedure, Runge-Kutta procedure, etc. Each of them has certain order of accuracy that typically depends on the size of the time step t to be used in
calculation. Information about these procedures, and many others, can easily be found in
textbooks on numerical procedures and on Internet. In this section we concentrate only
on presenting a Matlab algorithm that uses Newmark constant acceleration procedure,
without actually going into the details of derivation of the formula used. This information could be found in the paper written by Newmark in 1959 (N. M. Newmark, 1959, A
Method of Computation for Structural Dynamics, Journal of the Engineering Mechanics
Division, ASCE 85 67-94).
Solving differential equation
my(t) + cy(t) + ky(t) = x(t)
with initial conditions
y(t = 0) = y0 and y(t = 0) = y0
starts with calculation of the initial acceleration y(t = 0) = y0 from the previous equation
for t = 0:
my0 + cy0 + ky0 = x0
i.e.
y0 =
x0 ky0 cy0
.
m
Now in the next time instant t1 = t we can calculate displacement y1 from equation:
Ky1 = Q1
CIV6115
83
Q 1 = x1 + m
4m
2c
+
2
t
t
4y0
4y0
+
+ y0
t2
t
+c
2y0
+ y0 .
t
Next step is to calculate velocity y1 and acceleration yi at time t1 using the following
formulae:
2y1 2y0
y1 =
y0
t
and
4y1 4y0 4y0
y1 =
y0 .
t2
t
Now all the steps conducted for time instant t1 could be repeated for all other time instants
ti (i = 2, 3, ...):
yi = Qi /K
where K is the same as before, while
4yi1 4yi1
2yi1
Q i = xi + m
+
+ yi1 + c
+ yi1 ,
t2
t
t
yi =
and
yi =
2yi 2yi1
yi1
t
yi1 .
t2
t
EXAMPLE 5.1
Solve y(t) + 5.66y(t) + 800y(t) = 0 with initial conditions y(0) = 0.1 and y(0) = 5.0.
EXAMPLE 5.1:
SOLUTION
The code that solves the differential equation by using the procedure described above can
be written as (see Example5_1.m):
clear all
% time step
dt=0.001;
% time vector (lasting, say, 2s)
t=0:dt:2;
% system properties
m=1; c=5.66; k=800;
% initial displacement and velocity
CIV6115
84
d(1)=0.1; v(1)=-5;
% initial acceleration
a(1)=(-k*d(1)-c*v(1))/m;
K=k+4/(dt^2)*m+2/dt*c;
for i=2:length(t)
Q(i)=m*(4/dt^2*d(i-1)+4/dt*v(i-1)+a(i-1))+c*(2/dt*d(i-1)+v(i-1));
d(i)=Q(i)/K;
v(i)=2/dt*d(i)-2/dt*d(i-1)-v(i-1);
a(i)=4/dt^2*d(i)-4/dt^2*d(i-1)-4/dt*v(i-1)-a(i-1);
end
% plot the three outputs
subplot(3,1,1) % divide the figure in three area (3 rows, 1 column)
% and activate first graph for plotting in
plot(t,d)
% plot displacement on the first graph
grid on
% switch on the grid
xlabel(Time [s])
% label for x-axis
ylabel(Displacement [m])
% label for y-axis
subplot(3,1,2) % activate second graph for plotting in
plot(t,v)
% plot velocity on the second graph
grid on
% switch on the grid
xlabel(Time [s])
% label for x-axis
ylabel(Velocity [m/s])
% label for y-axis
subplot(3,1,3) % activate third graph for plotting in
plot(t,a)
% plot acceleration on the third graph
grid on
% switch on the grid
xlabel(Time [s])
% label for x-axis
ylabel(Acceleration [m/s^2])
% label for y-axis
Displacement [m]
CIV6115
0.2
0
0.2
Velocity [m/s]
Acceleration [m/s2]
85
0.5
1
Time [s]
1.5
0.5
1
Time [s]
1.5
0.5
1
Time [s]
1.5
10
0
10
200
0
200
Figure 5.2: Example 5.1: Solution of a differential equation and its first and second
derivatives.
end of the example
5.2.2
Particular Solution
will be presented. For this the second order differential equation will be presented in the
form
y(t) + py(t) + qy(t) = f (t)
where p =
c
,q
m
k
,
m
and f (t) =
x(t)
.
m
The particular solutions for different form of right hand side of the equation will be found.
Instead of dealing with general numbers, we will demonstrate each case on an example.
5.2.2.1
f (t) = eat
CIV6115
86
and
yp = 9Ae3t .
Substituting the expressions for yp , yp , and yp into the differential equation, we obtain
9Ae3t + 3(3Ae3t ) + 2Ae3t = e3t .
The left-hand side of this last expression is 20Ae3t . Comparing the two sides of the
1
. Therefore, the particular solution of the
differential equation, we conclude that A = 20
initial equation is:
1
yp (t) = e3t .
20
The approach for this example is standard for a constant-coefficient differential equations
with exponential nonhomogeneous term. If the nonhomogeneous term is Ceat , where C is
a constant, then the initial guess should again be Aeat , where A is an unknown coefficient
to be determined.
5.2.2.2
f (t) = polynomial
CIV6115
5.2.2.3
87
1 3t
e
20
1
1
yp2 = t .
2
4
Hence the complete particular solution is
1
1
1
yp = e3t + t .
20
2
4
CIV6115
5.3
88
Convolution
So far, the output of a system that can be described by a second order differential equation
has been studied when exposed to either the initial conditions only, or to the initial
conditions and some special inputs (such as sinusoidal signal, exponential signal, and so
on).
In this section the output of the same system exposed to a variety of different inputs (i.e.
more general input functions) is considered. Since the system considered here is linear,
the principle of superposition can be used to calculate the output to various combinations
of inputs based on the individual outputs to a specific input.
Before finding an output of the system due to an arbitrary input, we will define the output
of the system under an input in form of an impulse.
5.3.1
A very common input in the system is the sudden application of a short duration signal,
called the unit impulse, i.e. a signal applied for a very short, or infinitesimal, length of
time. The unit impulse is defined as:
Z
(t t0 )f (t)dt = f (t0 )
(5.12)
CIV6115
89
EXAMPLE 5.2
A continuous-time integrator is defined mathematically by
Z t
x( )d + y(0)
y(t) =
0
where t 0, y(t) is the integrator output, y(0) is the initial value of the integrator output,
and x(t) is the input. Find the unit impulse response model h(t) for this system.
EXAMPLE 5.2:
SOLUTION
First, the initial condition y(0) is set to zero; then with x(t) = (t), we have - by definition
of the impulse function - that
Z t
1, for t 0
y(t) = h(t) =
( )d =
0, for t < 0,
0
which is actually a step function. Therefore, we got that the unit impulse response h(t)
of an integrator, i.e. the response of the integrator to the unit impulse signal is a step
function, shown in Figure 5.4.
CIV6115
90
5.3.2
j
X
i=1
Finding the limit of this discrete sum as the number n of equal divisions t (t = nt )
increases to infinity n (t d ) yields:
Z t
y(t) =
x( )h(t )d.
(5.13)
0
CIV6115
91
EXAMPLE 5.3
For a mass-spring-damper system it can be shown that its impulse response function is equal
to:
p
1
p
y(t) = h(t) =
en t sin(n 1 2 t)
mn 1 2
q
k
where n = m
and = 2ckm . Calculate the output of this mass-spring-damper system to
two sinusoidal forces (lasting 30 s) of different frequencies (2 and 3 Hz, respectively) acting on
the system one at a time:
x1 (t) = 500 sin(2 2 t)
CIV6115
92
and
x2 (t) = 500 sin(2 3 t).
The system in question has the following properties: mass of 60000 kg, damping equal to
16000 N/(m/s) and stiffness of the spring
q equal to 9500000 N/m. Note that the natural
frequency of this system is equal to
EXAMPLE 5.3:
1
2
k
m
= 2 Hz.
SOLUTION
Since it would be time consuming to divide the sinusoidal input in impulses and to calculate the impulse response to each of them and then sum the responses up by hand,
we will use the MATLAB for solving the problem in one step. For this the command
conv(input,impulse_response_function) will be used.
First, we will define the properties of the system under consideration:
% System properties
m=60000; k=9.5*10^6; c=16000;
Then, we decide about the time step to be used for calculation, and define time vector t
on which the input signals are defined:
% time step
dt=0.001;
% [s]
% time vector
t=0:dt:30;
Now, we have to calculate the n and that are required for defining the impulse response
function:
% omegan and zeta
omegan=sqrt(k/m); zeta=c/(2*sqrt(k*m));
We now have all data required for defining the impulse response function:
% impulse response function
h=1/(m*omegan*sqrt(1-zeta^2)) * ...
exp(-zeta*omegan*t) .* sin(omegan*sqrt(1-zeta^2)*t);
We now can plot the impulse response function, just to check how the response to an
impulse looks like:
% impulse response (to one impulse)
figure(1)
plot(t,h)
grid on
xlabel(Time [s])
ylabel(Impulse response)
CIV6115
93
This plot is shown in Figure 5.6. Note that it would be useful to use as much time for
defining h(t) as needed for it to die out. In our example 30 s is enough for this, as can be
seen on the figure.
6
1.5
x 10
Impulse response
0.5
0.5
1.5
10
15
Time [s]
20
25
30
CIV6115
94
Note that the calculated response is defined on longer time than the input function (due
to the nature of definition of convolution, see MATLAB help for conv, for example). Because
of this, we have to redefine time vector to be used for response plotting in the way that
it has the same length as the response vector:
ty=0:dt:dt*(length(y_1)-1);
Now we can plot the two responses:
% plot solution to input 1
figure(2)
plot(ty,y_1)
grid on
title(Resonance)
xlabel(Time [s])
ylabel(Output (displacement) signal [m])
% plot solution to input 2
figure(3)
plot(ty,y_2)
grid on
title(Out-of-resonance)
xlabel(Time [s])
ylabel(Output (displacement) signal [m])
The two responses are presented in Figures 5.7 and 5.8. It is interesting to note here
that the first response is higher since the forcing frequency matches the system frequency
(both are equal to 2 Hz). This is phenomenon called resonance. In the second case, these
two frequencies are different (forcing frequency is 3 Hz wile the system frequency is 2 Hz),
so the response is lower. Note that when the force is removed from the system at t=30 s,
then the system response decreases. This is an inherent property of all damped systems.
The script with the code is available under name Example5_3.m.
CIV6115
2.5
95
Resonance
x 10
2
1.5
1
0.5
0
0.5
1
1.5
2
2.5
10
20
30
Time [s]
40
50
60
Outofresonance
x 10
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
1
10
20
30
Time [s]
40
50
60
Chapter 6
Frequency Response Function of a
System
An Introduction to Random Vibrations, Spectral and Wavelet Analysis, D. E. Newland, Dover
Publications, third edition, 2005.
In this chapter we will present a very convenient way of describing properties of a system
exposed to a time-dependent input x(t). Since the input changes in time then the output
will do the same and we are therefore studying the dynamics of the system. This is
why the properties of this kind of system are often called the dynamic properties.
6.1
Dynamic properties of a system could be described by studying the response of the system
to a sine input (Figure 6.1).
(6.1)
then the steady-state output must also be a sine wave of fixed amplitude (normally different from the input amplitude), the same frequency and phase difference , so that
y(t) = Y sin(t ).
(6.2)
Information about the amplitude (response to input) ratio Y /X and the phase angle
define the transmission characteristics or transfer function of the system or frequency response function (FRF) of the system at the fixed frequency . Therefore,
96
CIV6115
97
EXAMPLE 6.1:
SOLUTION
For a linear spring of stiffness k and a linear viscous damper of coefficient c, the differential
equation of the system could be written as
cy(t) + ky(t) = x(t).
When x(t) is a constant amplitude sine wave described by Equation 6.1 and y(t) is described by Equation 6.2, then the differential equation could be rewritten in this form:
cY cos(t ) + kY sin(t ) = X sin t.
Using known trigonometric formulae:
cos(t ) = cos t cos + sin t sin
and
sin(t ) = sin t cos cos t sin
and collecting the terms multiplying sin t and cos t we get:
X
Y sin t c sin + k cos
Y
CIV6115
98
For this equation to be true, the terms in brackets must be equal to zero:
c sin + k cos
X
=0
Y
and
c cos k sin = 0.
We can further write:
c sin + k cos =
X
Y
and
c cos k sin = 0.
If we square both equation and sum them up we will get:
c2 2 sin2 + k 2 cos2 + 2ck sin cos + c2 2 cos2 + k 2 sin2 2ck sin cos =
and further
c2 2 (sin2 + cos2 ) + k 2 (sin2 + cos2 ) =
X2
Y2
X2
.
Y2
X2
,
Y2
(6.3)
c
,
k
i.e.
= tan1
c
.
k
(6.4)
Therefore, equations 6.3 and 6.4 are the amplitude ratio and phase angle that completely
determine the transfer function of the system shown in Figure 6.2. The transfer function
is normally presented in form of two graphs (Figure 6.3) representing the amplitude ratio
(Figure 6.3a) and the phase (Figure 6.3b) as functions of frequency .
Note that = 0 corresponds to static loading, and therefore the displacement is obtained
as force divided by stiffness k.
CIV6115
99
Figure 6.3: (a) Amplitude ratio and (b) phase for transfer function of system shown in
Figure 6.2.
end of the example
6.2
Instead of thinking of amplitude ratio and phase angle as two separate quantities, it
has become practice in system theory to use a single complex number to represent both
quantities. This is called complex frequency response function H(). This complex
FRF is defined so that its magnitude is equal to the amplitude ratio Y /X and the ratio
of its imaginary part to its real part is equal to he tangent of the phase angle.
If we write the complex function H() via its real A() and imaginary B() part:
H() = A() iB()
where i =
(6.5)
Imaginary part
B()
=
= tan .
Real part
A()
(6.6)
|H()| =
and
Using complex exponential notation and definition eit = cos t + i sin t we can now
write that if the input is a sine wave of amplitude X:
x(t) = X sin t = X (the imaginary part of eit ) = X Im(eit ),
then the corresponding harmonic output y(t) will be
y(t) = X Im(H()eit ).
The proof that this is correct is easily obtained as:
y(t) = X Im {(A() iB())(cos t + i sin t)}
CIV6115
100
i.e.
y(t) = X {A() sin t B() cos t} .
Now we can use alternative representation of the previous equation based on equality:
Q sin(t ) = Q1 sin(t) Q2 cos(t)
if:
q
Q21
Q=
Q22
and = tan
Q2
Q1
Therefore,
y(t) = X {A() sin t B() cos t}
will be
B
A
(6.7)
(6.8)
where H() is the systems complex FRF evaluated at angular frequency . In interpreting Equations 6.7 and 6.8 we mean either the real part or imaginary part of the
right-hand side of equations (but not both) according to the convention we agreed on.
EXAMPLE 6.2
Calculate the complex FRF for the system shown in Figure 6.2.
EXAMPLE 6.2:
SOLUTION
1
.
k + ic
We can easily show that this function is the same as the one in the previous example.
CIV6115
101
First, using
H() =
1
k
ic
k ic
k ic
= 2
2
= A() iB().
= 2
2
2
2
2
k + ic k ic
k +c
k +c
k + c2 2
Y
1
= |H()| = A2 + B 2 =
2
X
k + c2 2
and then the phase angle as
tan =
B()
c
=
A()
k