Sunteți pe pagina 1din 105

Department of Civil & Structural Engineering

University of Sheffield

CIV6115: Linear Systems (and


Structural Analysis)

Aleksandar Pavic
Stana Zivanovic

October 2009

Contents
Contents

1 Introduction to Systems and Signals

1.1

Introduction to Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.2

System Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.3

Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.4

Signal Classification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.4.1

Periodic and Nonperiodic Signals . . . . . . . . . . . . . . . . . . .

1.4.2

Deterministic and Random Signals . . . . . . . . . . . . . . . . . .

Basic Properties of Continuous Systems . . . . . . . . . . . . . . . . . . . .

1.5.1

Linearity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.5.2

Time Invariance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

1.5.3

Linear Time-Invariant Systems . . . . . . . . . . . . . . . . . . . . 11

1.5.4

Causality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

1.5.5

Stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

1.5

2 Introduction to MATLAB
2.1

2.2

13

Starting with MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13


2.1.1

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

Creating Programs with m-script . . . . . . . . . . . . . . . . . . . 17

2.1.7

Looping with FOR loop . . . . . . . . . . . . . . . . . . . . . . . . 18

Matrices and Nested FOR Loops . . . . . . . . . . . . . . . . . . . . . . . 19


2.2.1

Direct Creation of Matrices in MATLAB . . . . . . . . . . . . . . . 19

2.2.2

Automatic Generation of Matrices in MATLAB . . . . . . . . . . . 20

2.2.3

Using FOR Loops to Generate Matrices . . . . . . . . . . . . . . . 21


i

CONTENTS

ii

2.2.4

Matrix Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

2.3

2.4

Control of Program Flow: Relational and Logical Operators and IF Constructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24


2.3.1

Relational and Logical Operators . . . . . . . . . . . . . . . . . . . 24

2.3.2

Program Flow Control: Decision Making with IF constructions

. . 26

Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

3 Numerical Differentiation and Integration

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

Numerical Calculation of First Moment of Area and Centroid . . . 39

4 Linear Algebra
4.1

Linear Equations in Linear Algebra . . . . . . . . . . . . . . . . . . . . . . 43


4.1.1

4.1.2

4.1.3

4.1.4

4.1.5

4.2

43

System of Linear Equations . . . . . . . . . . . . . . . . . . . . . . 43


4.1.1.1

Matrix Notation . . . . . . . . . . . . . . . . . . . . . . . 46

4.1.1.2

Solving a Linear System . . . . . . . . . . . . . . . . . . . 46

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

Solution Sets for Systems of Linear Equations . . . . . . . . . . . . 54


4.1.4.1

Homogeneous Systems of Linear Equations . . . . . . . . . 54

4.1.4.2

Nonhomogeneous Systems of Linear Equations

. . . . . . 55

Linear Independence . . . . . . . . . . . . . . . . . . . . . . . . . . 56
4.1.5.1

Linear Independence of Matrix Columns . . . . . . . . . . 57

4.1.5.2

More Theorems about Linear (In)dependence of Vectors . 57

Matrix Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.2.1

Matrix Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.2.1.1

Sums and Scalar Multiplies . . . . . . . . . . . . . . . . . 59

4.2.1.2

Matrix Multiplication . . . . . . . . . . . . . . . . . . . . 60

CONTENTS

iii
4.2.1.3

Properties of Matrix Multiplication . . . . . . . . . . . . . 63

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

Numerical Note on Calculation of Inverse Matrix . . . . . . . . . . 66

4.3

Determinants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

4.4

Vector Spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

4.5

4.4.1

Vector Subspaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

4.4.2

Linearly Independent Sets . . . . . . . . . . . . . . . . . . . . . . . 71

4.4.3

Basis of Vector (Sub)space . . . . . . . . . . . . . . . . . . . . . . . 71

4.4.4

More Theorems on Basis of Vector Space . . . . . . . . . . . . . . . 73

Eigenvalues and Eigenvectors . . . . . . . . . . . . . . . . . . . . . . . . . 73


4.5.1

Expansion Theorem for Matrices with Distinct Eigenvalues . . . . . 77

4.5.2

Matrices with Non-Distinct Eigenvalues . . . . . . . . . . . . . . . . 77

5 Time-Domain Models

78

5.1

The Nth -Order Differential Equation . . . . . . . . . . . . . . . . . . . . . 78

5.2

The Second Order Differential Equation . . . . . . . . . . . . . . . . . . . 80


5.2.1

5.2.2

5.3

Homogeneous Solution . . . . . . . . . . . . . . . . . . . . . . . . . 80
5.2.1.1

Roots as Real and Distinct Numbers . . . . . . . . . . . . 81

5.2.1.2

Roots as Complex-Conjugate Numbers . . . . . . . . . . . 81

5.2.1.3

Repeated Roots . . . . . . . . . . . . . . . . . . . . . . . . 82

5.2.1.4

Solving Second Order Homogeneous DE using MATLAB . 82

Particular Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
5.2.2.1

f (t) = eat . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

5.2.2.2

f (t) = polynomial . . . . . . . . . . . . . . . . . . . . . . 86

5.2.2.3

f (t) = sine or cosine . . . . . . . . . . . . . . . . . . . . . 87

5.2.2.4

f (t) = sum of various terms . . . . . . . . . . . . . . . . . 87

Convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
5.3.1

Unit Impulse Response Function

. . . . . . . . . . . . . . . . . . . 88

5.3.2

Response to Arbitrary Input . . . . . . . . . . . . . . . . . . . . . . 90

6 Frequency Response Function of a System

96

6.1

Frequency Response Function . . . . . . . . . . . . . . . . . . . . . . . . . 96

6.2

Complex Form of Frequency Response Function . . . . . . . . . . . . . . . 99

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).

Figure 1.1: System with p inputs and q outputs.


There are many different types of systems. Some examples are listed below:
Electrical circuit (input: driving voltage, outputs: voltages at various points in the
circuit);
1

CIV6115

chapter 1 Introduction to Systems and Signals

Communication system (input: signal to be transmitted, outputs: received signals);


Human heart (inputs: electrical stimuli applied to the hearth muscle, output: flow
rate of blood through the heart);
Oil refinery (input: flow rate of oil, output: flow rate of gasoline);
Civil engineering structure (inputs: loads acting on the structure, output: deformation/dislacement of the structure).
The last example is the one which we study in civil engineering, often without referring
to (or thinking about) the structure as a system. For example, in statics we are used to
imposing same load on the structure (such as self-weight) and calculating some outputs
(such as deflection, stresses, bending moments, axial and shear forces, and so on). In
dynamics, we apply some dynamic load (i.e. load that changes with time, such as earthquake or wind) on the structure and calculate the dynamic response of the structure (such
as displacement over time, acceleration over time, stresses over time, etc.). In each case
our structure can be thought of as a system that modifies the input applied to it and
that produces the output. It is known that different systems change the same input in
different ways, that is they produce different outputs. These outputs depend on properties of the system. For example, in statics the property of the system is its stiffness (that
depends on geometry, boundary conditions, material, cross section properties for beams,
thickness of walls and floors, etc.) while in dynamics apart from stiffness, damping and
mass also influence the value of the output.
One could think about input, system and output as integral components of input-systemoutput philosophy that is often used when analysing different systems. In general, having
information about two of these components will allow us to learn about the third one. In
this sense it is possible to divide the analysis into three big parts:
Response calculation: this is what we quite often use in our analysis of civil engineering structure (i.e. systems; we will use word system from now on). Examples
are already mentioned above - having some known load acting on a known (in the
sense of its properties) system, we use different methods from Theory of Structures
to calculate responses (outputs) required.
System identification: Sometimes input and output of a system are known (usually by measuring) and information about them can be used to identify the properties
of the system.
Input identification: The last combination is that the properties of the system
are known and the output could be measured. This information then can be used
to identify the input (such as force) acting on the system. This is used when
information about input is not readily available (i.e. the input cannot easily be
measured). Some examples are forces induced by walking people, moving traffic,
wind, etc.
This module is an introduction to input-system-output analysis, and is supposed to help
understanding of subjects such as Vibration Engineering and Introduction to Earthquake
Engineering, taught later during your MSc studies. This introductory text is devoted
exclusively to linear systems, that will be defined in later sections.

CIV6115

1.2

chapter 1 Introduction to Systems and Signals

System Representation

To take an in-depth study of a system, it is useful to have a mathematical model of


the system. A mathematical model consists of a collection of equations describing the
relationships between the inputs and outputs appearing in the system.
A mathematical model of a system is usually an idealised representation of the system. For example, many physical systems cannot be described exactly by a mathematical
model. However, a sufficiently accurate mathematical model can often be generated so
that system behaviour and properties can be studied in terms of the model. An effort
should always be made to construct the simplest possible model of the system under
study. But the model must also be sufficiently accurate, which means that all primary
characteristics (first-order effects) must be included in the model. Usually, the more characteristics that are put into a model, the more complicated the model becomes. Usually,
a trade-off between simplicity of the model and its accuracy is necessary.
Some possible representations of the system are:
The input/output differential equation or difference equation;
The convolution model;
The transfer function representation;
The Fourier transform representation.
The Fourier transform representation can be viewed as a special case of the transfer
function representation.
The first two representations listed above are referred to as time-domain models since
these representations are given in terms of functions of time. The last two of the representations listed above are referred to as frequency-domain models since they are
specified in terms of functions of a complex variable that is interpreted as a frequency
variable. Both time-domain and frequency-domain models are used in system analysis.
They are often used together to maximise understanding of the behaviour of the system
under study.
A convenient way to describe systems in general terms is by means of a block diagram.
An example of SISO system, where x(t) is the input signal and y(t) is the output signal,
is shown in Figure 1.2. The system itself is shown as a block, or box. However, when a
system is composed of more than one component (subsystems), then it can be represented
by several blocks, connected in an appropriate way (Figure 1.3). The subsystems in Figure
1.3 are identified by symbols T1 , T2 , and T3 . It is convenient to think of each of the blocks
as transforming its input signal to its output signal, that is further transferred to other
blocks. This can be represented mathematically by the operational notation:
y(t) = T1 {x(t)}, z1 (t) = T2 {y(t)}, ...

(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

chapter 1 Introduction to Systems and Signals

Figure 1.2: System block diagram.

Figure 1.3: System consisting of three components (blocks).

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.

Figure 1.4: Continuous system.


However, it is often more convenient to process discrete signals than their continuous
counterparts. For this purpose the continuous signals have to be converted to a discrete
format. This is most often done by simply sampling the continuous signal, such as r(t)
shown in Figure 1.5a, at equally spaced time intervals to obtain a discrete signal r(n)

CIV6115

chapter 1 Introduction to Systems and Signals

(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.

Figure 1.6: Discrete system.

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

chapter 1 Introduction to Systems and Signals

Periodic and Nonperiodic Signals

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)

An example of a periodic signal is shown in Figure 1.7.

Figure 1.7: A periodic signal.

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

chapter 1 Introduction to Systems and Signals

Figure 1.8: A periodic signal.

1.4.2

Deterministic and Random Signals

If the value of a signal can be determined by a mathematical expression, rule, or table


then this signal is called deterministic. These signals are relatively easy to analyse and
we can make accurate assumptions about their past and future behavior. An example of
these signals would be the signal described by Equation 1.5.
Unlike deterministic signals, random (stochastic) signals, are signals that cannot be
characterised by a simple, well-defined mathematical equation and their future values
cannot be predicted. Rather, we must use probability and statistics to analyse their
behavior. Because of their randomness, average values from a collection of signals are
usually studied rather than analysing one individual signal. An example of these signals
presented in Figure 1.9 is the ground acceleration during an earthquake.

Figure 1.9: A random signal.

1.5

Basic Properties of Continuous Systems

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

chapter 1 Introduction to Systems and Signals

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.

Figure 1.10: Principle of homogeneity.

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).

Figure 1.11: Principle of additivity.

3. Principle of superposition: If we have a system such that x1 (t) y1 (t) and


x2 (t) y2 (t), then the new input C1 x1 (t) + C2 x2 (t) applied to the linear system
will produce the output C1 y1 (t) + C2 y2 (t) since linear continuous system satisfies
homogeneity and additivity principles. This is called the principle of superposition
(Figure 1.12). A system that does not satisfy the principle of superposition is called
nonlinear.

CIV6115

chapter 1 Introduction to Systems and Signals

Figure 1.12: Principle of superposition.

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.

Figure 1.13: Output versus input in an ideal amplifier.

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

chapter 1 Introduction to Systems and Signals

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 .

Figure 1.14: Output versus input in an nonideal amplifier.


end of the example
EXAMPLE 1.2
Consider a single-input single-output continuous-time system with the input/output relationship
Z t
y(t) =
h(t )x()d, t t0
(1.6)
t0

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

Using the linearity property of integration gives


Z t
Z t
y(t) = a
h(t )x1 ()d + b
h(t )x2 ()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

chapter 1 Introduction to Systems and Signals

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.

Figure 1.15: Time invariance.

1.5.3

Linear Time-Invariant Systems

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

chapter 1 Introduction to Systems and Signals

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

Starting with MATLAB

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

chapter 2 Introduction to MATLAB

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.

Figure 2.1: MATLAB desktop.

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

chapter 2 Introduction to MATLAB

Table 2.1: Arithmetic


Symbol Operation
+
addition a + b
subtraction a b
*
multiplication a b
/
division a b
^
power ab

operations.
Example
4+3
27-1
18 3
18 3
25

15

MATLAB
4+3
27-1
18*3
18/3
2^5

Table 2.2: Basic arithmetic operation.


Input
3+4*2
(2+3)*4
12/(1+3)
3^2-5-6/(3*2)
4*3^2+1
(4*3)^2+1
((2+1)*2)^2+1
2e6*3.3e3
2e12*3.3e-3

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

chapter 2 Introduction to MATLAB

16

The variable names can contain up to 63 characters.


Punctuation characters and special symbols should not be used in variable names.
The following are all examples of invalid variable names: nice&easy,
its_a_nice_number and cheers!, for which MATLAB would return an error message. If algebraic symbols, such as +, -, * or / are used in variable names, MATLAB
will interpret them as algebraic operators. In cases like hot-dog or fast+furious
MATLAB will attempt to subtract dog from hot and add furious to fast.
In addition to these naming rules, MATLAB has a number of special variables (see
Table 2.3). Always avoid using these as names for your variables.
MATLAB remembers not only the commands you enter, but also the values of any
variables you create. These commands and variables are said to reside in the MATLAB
workspace: they can be recalled whenever you wish.

Table 2.3: Special variables in MATLAB.


Variable name Description
ans
default variable name for result
pi
ratio of circle circumference to diameter
eps
smallest number which, when added to 1, gives >1
inf
infinity
NaN
not
a number (for example 0/0)
i and j
1

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

chapter 2 Introduction to MATLAB

17

SQRT(X) is the square root of the elements of X. Complex


results are produced if X is not positive.
See also sqrtm, realsqrt, hypot.
Reference page in Help browser
doc sqrt
Try typing help in the command window without specifying any topic. MATLAB will display
a list of topics you can ask for help on. For example help matfun will display a list of
matrix functions, whereas help specfun a list of specialised mathematical functions.

2.1.6

Creating Programs with m-script

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

2. Save the file as quadeq_sol.m in your working directory.


3. Enter the values for the coefficients a, b and c, and run the program in the
Command window.
>> a=7; b=-4; c=11;
>> quadeq_sol

CIV6115

chapter 2 Introduction to MATLAB

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

Looping with FOR loop

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

chapter 2 Introduction to MATLAB

19

Matrices and Nested FOR Loops

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

Direct Creation of Matrices in MATLAB

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

12.2 14.3 7.1


A=
2.7 11.6 6.6

CIV6115

chapter 2 Introduction to MATLAB

20

that can be entered in MATLAB as


>> A=[12.2 14.3 7.1; 2.7 11.6 6.6]
The same matrix can be defined by assigning values to every element of the matrix
individually:
>> A(1,1)=12.2; A(1,2)=14.3; A(1,3)=7.1;
>> A(2,1)=2.7; A(2,2)=11.6; A(2,3)=6.6;

2.2.2

Automatic Generation of Matrices in MATLAB

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

chapter 2 Introduction to MATLAB

21

ans = 0.0000 0.5878 0.9511


>> y(1:2:6) % Elements 1 to 6 with step 2 (or elements 1, 3 and 5)
ans = 0 0.9511 0.5878

2.2.3

Using FOR Loops to Generate Matrices

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

chapter 2 Introduction to MATLAB

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

chapter 2 Introduction to MATLAB

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

chapter 2 Introduction to MATLAB

24

Control of Program Flow: Relational and Logical


Operators and IF Constructions

2.3.1

Relational and Logical Operators

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

chapter 2 Introduction to MATLAB

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.

Figure 2.2: Example: relational operators.

Logical operators provide a way of combining relational expressions. MATLAB relation


operators include the following.

Symbol
&
|
~

Table 2.5: Logical operators.


Operator Description
AND
Returns 1 if all relations are TRUE
OR
Returns 1 if at least one relation is TRUE
NOT
Returns 1 if all relations are FALSE

CIV6115

chapter 2 Introduction to MATLAB

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

The resulting plot is shown in Figure 2.3.

Figure 2.3: Example: relational and logical operators


The expression ((z>-2)&(z<2)) is TRUE (returns 1) for all values of z greater than
-2 and less than 2 and FALSE (returning 0) for all values of z outside this range.
ro used in plot command stand for: r=red colour used for plot and o=mark each
point on the graph as a circle.

2.3.2

Program Flow Control: Decision Making with IF constructions

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

chapter 2 Introduction to MATLAB

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

if none of the above expressions are TRUE

CIV6115

chapter 2 Introduction to MATLAB

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.

Figure 2.4: Example: if constructions embedded in a for loop


The solution is ymax=1.1754. Can we find the value of x for which y=ymax by
adding just one line to the program? Try to write a program that will detect both
peaks of the function [hint: one way of doing this is to store y values in a matrix
y(cnt), then compare y(cnt-1) with y(cnt-2) and y(cnt)].

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

chapter 2 Introduction to MATLAB

29

An example of a simple function is provided by this code for calculating roots of a


quadratic function:
function [root1,root2]=quadroot(a,b,c)
% This function returns the two roots to the quadratic equation
% Input:
coefficients a, b and c
% Written by J Backwell
3 October 1989
sqrt_term=sqrt(b^2-4*a*c);
root1=(-b+sqrt_term)/(2*a)
root2=(-b-sqrt_term)/(2*a)
The m-file should be saved as quadroot.m.
The above function can be called from MATLAB Command Window by specifying
the input values:
>>[x1,x2]=quadroot(2,5,10)
Also, the above function can be called from another MATLAB program. For example:
..... % all sorts of MATLAB commands and expressions
..... % for calculating values of very important parameters;
..... % all stored in vector z (as z(1), z(2) ...(z(npar)).
time=sqrt(z(11))/(250*z(21));
money=z(14)^2;
fun=z(23)+z(45);
[x1,x2]=quadroot(time,money,fun)
Note that the output values can be assigned to any variables in the program the
function is called from. In this case the values of the two roots will be assigned to
two new variables x1 and x2 respectively. Also the names of the variables we pass
to the function, do not have to be the same as the ones used within the function.
A function differs from a standard m-script in that the former communicates with
the MATLAB workspace only through the input variables passed to it and through
the output variables it creates. Intermediate variables within the function (such
as sqrt_term in the above example) do not appear in or interact with the MATLAB
workspace.
As can be seen in the above example, the first line of a function m-file (i) defines
the m-file as a MATLAB function, (ii) specifies its name and (iii) identifies its input
and output variable names. The next sequence of three comment lines are the text
displayed in response to the help command (help quadroot). Finally, but most
importantly, the remainder of the function contains the commands that operate on
inputs in order to get outputs.

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

chapter 3 Numerical Differentiation and Integration

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.

Figure 3.1: Approximation of the tangent (i.e. first derivative) at P.


A simple three-point estimation would be to compute the slope at P by using the value
of the function at the point preceding (Q) and at the point following (R) point P (Figure
3.1). In this case the slope can be found as:
x0 (n)

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

chapter 3 Numerical Differentiation and Integration

32

Lk has the form:


Lk (t) =

(t t0 )(t t1 )(t t2 )...(t tk1 )(t tk+1 )...(t tn )


.
(tk t0 )(tk t1 )(tk t2 )...(tk tk1 )(tk tk+1 )...(tk tn )

(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)

Now we can calculate the first derivative of this function:


x0 (t) =

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

chapter 3 Numerical Differentiation and Integration

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

= 2, meaning that the frequency f = 2


= 1 Hz, i.e. the signal makes one oscillation
per second.
To find its derivative numerically, we will implement the formulas given by equations
3.9, 3.10 and 3.11. This example is convenient because we know in advance that the
first derivative of our sinusoidal signal has to be equal to 2 cos(2t). We will use this
knowledge later to check if our numerical differentiation is accurate. Now we will explain
all lines of the script required to conduct the calculation.
First, we clear workspace of any variables present from some other jobs done before. This
is useful to do every time when we do programming.
clear all
Then we specify time step dt and time vector t. We choose dt = 0.001s and time vector
lasting 4 s. It is our free choice here, depending on which accuracy we need and how
long the duration of the signal we want to specify. (If the signal was obtained from
measurements, then its duration would be known, as well as sampling time dt.)
dt=0.001; t=0:dt:4;
We now specify the input sine signal as an array:
x=sin(2*pi*1*t);
Then we proceed with finding the first derivative of the signal x.
First value, as specified in Equation 3.9 can be calculated as:
y(1)=(-3*x(1)+4*x(2)-x(3)) / (2*dt);
Note that we cannot use index 0 in MATLAB, so we had to start from 1.
To get middle values of the signal we form a for loop that will produce an array of y
signal for all values, except first and last one.
for i=2:(length(x)-1)
y(i)=(x(i+1)-x(i-1))/(2*dt);
end
Finally, we calculate the last value of the signal.
last=length(x);
y(last)=(x(last-2)-4*x(last-1)+3*x(last))/(2*dt);
At the end we can plot two signals, in order to check if we got a correct solution. The set
of commands for this is given as following:
plot(t,x)

% plot input signal (default line is solid line)

grid on

% switch on the grid

CIV6115

chapter 3 Numerical Differentiation and Integration

hold on

% keep this graph for the next plot

plot(t,y,-.)

% plot output signal as dot-dashed line

xlabel(Time [s])

% label for x-axis

ylabel(Signals x and y)

% label for y-axis

title(Numerical differentiation)

% title of the graph

legend on

% include legend into the plot

legend(Displacement [m],Velocity [m/s])


hold off

34

% legend content

% switch off the graph

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

Figure 3.2: Example 3.1: Numerical differentiation of a displacement time record.


Complete MATLAB script for this example is available as the MATLAB file Example3_1.m.
Additionally, you can try to get the acceleration signal by differentiating (numerically, i.e.
not analytically, please!) velocity signal calculated. The result should be the same as that
presented in Figure 3.3.
Numerical differentiation
40
Velocity [m/s]
2

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

Figure 3.3: Example 3.1: Numerical differentiation of the velocity signal.


end of the example

CIV6115

3.2

chapter 3 Numerical Differentiation and Integration

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.

Figure 3.4: Approximating area of each vertical strip by a trapezoidal area.


Therefore, the approximate integral is equal to the sum of all trapezoidal areas defined
on each strip:
Z

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

chapter 3 Numerical Differentiation and Integration

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

In ith step it would be

vi = v(t = ti ) = vi1 +
or

vi = v0 +

1
1
ai1 + ai
2
2

1
1
a0 + a1 + a2 + ... + ai1 + ai .
2
2

Therefore, if we were implementing Equation 3.13 without considering initial condition,


we would obtain values that are all shifted for v0 . This is the case because Equation
3.13 is derived under assumption that initial value is equal to 0.
MATLAB command which does this trapezoidal integration on a signal a is cumtrapz(a).
The integration is conducted under assumption that t = 1. Therefore, in order to get
correct values for resulting signal we have to multiply it by t. Also, the function assumes
that v0 = 0.
Based on everything so far, we can write a simple script that will calculate velocity signal
from the acceleration signal specified.
clear all
dt=0.001;
t=0:dt:4;

CIV6115

chapter 3 Numerical Differentiation and Integration

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

Figure 3.5: Example 3.2: Acceleration and velocity signal if v0 = 0.


As we can see, the result for velocity signal is not as we would expect. This is because
we did not take into account the initial velocity (i.e. v0 was taken to be 0). If we defined
the signal as
v=v*dt; v0=2*pi; v=v+v0;
then we would get result as we would expect, shown in Figure 3.6. The code for this
program is available in Example3_2.m file.
Finally, we should notice that command cumtrapz is different from another command
available in MATLAB, called trapz. The latter calculates the total area between the
signal and xaxis, which is, in our case equal to zero, because of having the same positive
and negative area for signal a. The command can be issued as
trapz(a). Try it!

CIV6115

chapter 3 Numerical Differentiation and Integration

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

Figure 3.6: Example 3.2: Acceleration and velocity signal if v0 = 2.

end of the example

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

chapter 3 Numerical Differentiation and Integration

39

Therefore, the total area of two strips is:


2
1
A1 + A2 = (xk p)(2t) + p(2t) =
3
2

2
xk+1 + xk1
1 xk+1 + xk1
t
xk
2t +
(2t) =
(xk1 + 4xk + xk+1 ).
3
2
2
2
3

(3.14)

By summing areas of each two neighbouring strips, we get:


Z b
t
x(t)dt
[(x0 +4x1 +x2 )+(x2 +4x3 +x4 )+(x4 +4x5 +x6 )+...+(xn2 +4xn1 +xn )].
3
a
(3.15)
This finally gives:
Z b
t
x(t)dt
[x0 + 4(x1 + x3 + x5 + ... + xn1 ) + 2(x2 + x4 + x6 + ... + xn2 ) + xn ], (3.16)
3
a
where n is an even number, as explained earlier.

3.2.3

Numerical Calculation of First Moment of Area and Centroid

http://mywebsite.bigpond.com/npajkic/solid mechanics/first moment of area/index.html


By definition, the area of an arbitrarily shaped function is equal to the integral of that
function. Besides the area, the position of a centroid of a plane area is an important
geometric property. In order to obtain formulas for locating the centroid of a shape, we
need to consider an arbitrary shape, such as the one in Figure 3.8.

Figure 3.8: Centroid of an area of arbitrary shape.


If we take a very small piece of that shape (pictured as the square), its differential area
will be dA and coordinates of its centre will be x1 and y1 . The area of the whole shape
may be expressed as:
Z
A=

dA

(3.17)

CIV6115

chapter 3 Numerical Differentiation and Integration

40

where dA is the differential area represented by coordinates x1 and y1 . In other words,


what the above expression is saying is that the area of the whole shape is simply the sum
of all the individual differential areas.
The first or static moment of an area about x-axis Qx and y-axis Qy are respectively
defined by:
Z
Z
Qx = ydA and Qy = xdA.
(3.18)
It is evident from Equations 3.18 that the first moment of an area is the sum of the
products of the differential areas and their respective coordinates.
If we were now to take Qx and Qy and divide them by the area of the whole shape, we
would obtain yc and xc - the coordinates of the centroid. This is expressed as:
R
R
xdA
ydA
Qy
Qx
xc =
=
and yc =
=
.
(3.19)
A
A
A
A
Note that if an area is symmetric about an axis, its centroid must lie on that axis and
therefore its first moment of area will be zero.
Finally, if a shape is defined by a set of discrete points defining its shape, then its area,
first moments of area and centroid can be calculated numerically by replacing integral
operator in Equations 3.17-3.19 with sum operator, i.e.
A

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

the area presented in Figure 3.9. The signal


t2
x(t) is defined analytically as: x(t) = 5 1 64 .
6

Figure 3.9: Example 3.3.

CIV6115

chapter 3 Numerical Differentiation and Integration

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).

Figure 3.10: Example 3.3: Dividing area into vertical strips.


Then we can approximate each strip with a rectangle of width t = 1 and height
equal to the signal value in the ordinate t taken in the centre of the rectangle (Figure 3.11). Note that the array of points along taxis starts at 0.5 s and goes up to
7.5 s with step t = 1s. Therefore, the array of values for t becomes: t=0.5:1:8 (or
t=[0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5]). At each
point tk , the value of xk can be
t2k
found by using analytical function xk = 5 1 64 . These values are shown in Figure
3.11 and can be presented in the array form as:
x=[4.9805 4.8242 4.5117 4.0430 3.4180 2.6367 1.69920.6055].

Figure 3.11: Example 3.3: Rectangles used to approximate the area.

CIV6115

chapter 3 Numerical Differentiation and Integration

42

Now the area of each strip can easily be calculated as Ak = xk t = xk 1.0 = xk .


Summing all these areas it can be found that A = 26.7188. Finally, by using the formulae
given in Equations 3.21 and 3.22 these values of first moments of area and consequently
the coordinates of the centroid could be calculated:
Qt = 53.3340, Qx = 80.6250, tc = 3.0175, xc = 1.9961.
Note that even with this large step t = 1 the results are very close to the exact solution
(written here with four decimal places):
= 2.0000,
= 3.0000, xexact
= 80.0000, texact
= 53.3333, Qexact
Aexact = 26.6667, Qexact
c
c
x
t
with relative percentage error for area equal to
EA =

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

Linear Equations in Linear Algebra


System of Linear Equations

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

chapter 4 Linear Algebra

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

Figure 4.1: Unique (exactly one) solution.

CIV6115

chapter 4 Linear Algebra

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

Figure 4.2: System with no solution.

On the other hand, if a system, such as:


l1 : x1 2x2 = 1
l2 : x1 + 2x2 = 1
consists of the lines that coincide (and therefore intersect at every point on the line) then
every point on the line is a solution, meaning that there are infinitely many solutions of
the system (Figure 4.3).
3
2.5
2
1.5

x2

1
0.5
0
0.5
1
1.5
4

x1

Figure 4.3: System with infinitely many solutions.

CIV6115

chapter 4 Linear Algebra

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)

with the coefficients of each variable aligned in columns, the matrix

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

Solving a Linear System

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

chapter 4 Linear Algebra

47

3. Multiply all the terms in an equation by a nonzero constant.


EXAMPLE 4.1
Solve system 4.3.
EXAMPLE 4.1:

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

chapter 4 Linear Algebra

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

chapter 4 Linear Algebra

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

chapter 4 Linear Algebra

50

is called a linear combination of vectors v1 , v2 , ..., vp with weights c1 , c2 , ..., cp . The


weights in a linear combination can be any real numbers, including zero. For example,
some linear combinations of vectors v1 and v2 are

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)

This can be written in the form of vector equation:

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

chapter 4 Linear Algebra

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

A fundamental idea in linear algebra is to view a linear combination of vectors as the


product of a matrix and a vector. Therefore, if A is an m n matrix (note that we use a
capital letter to denote a matrix), with columns a1 , a2 , ..., an , and if x is in Rn , then the
product of A and x, denoted by Ax, is the linear combination of the columns of A using
the corresponding entries in x as weights; that is,

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)

Now, we can summarise what we learned so far: If A is an m n matrix, with columns


a1 , a2 , ..., an , and if b is in Rm , the matrix equation 4.7 has the same solution set as the
vector equation
x1 a1 + x2 a2 + ... + xn an = b
(4.8)
which, in turn, has the same solution set as the system of linear equations whose augmented matrix is

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

chapter 4 Linear Algebra

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

From the definition that Ax is a linear combination of columns of matrix A we could


calculate the product as:

2
3
4 x1
2
3
4
1
1
5
3
5 3 x2
= x1
+ x2
+ x3
=

x3
6
2
8
6 2
8

2x1 + 3x2 + 4x3


x1 + 5x2 3x3
.
(4.10)
=

6x1 2x2 + 8x3

CIV6115

chapter 4 Linear Algebra

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:

2 3 4 x1 2x1 + 3x2 + 4x3

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:

>> A=[2 3 4; -1 5 -3; 6 -2 8];


>> x=[2; 5; -7];
>> b=A*x;
end of the example
If the matrix A is a square matrix (i.e. the number of rows m is the same as the number of
columns n) with ones placed at the main diagonal, and zeros elsewhere, then this matrix
is called the identity or unit matrix. This kind of matrix is usually denoted by letter
I rather than A. An example of unit matrix when m = n = 3 is

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

chapter 4 Linear Algebra

54

1. A(u + v) = Au + Av;
2. A(cu) = c(Au).

4.1.4

Solution Sets for Systems of Linear Equations

In this section, solution sets for homogeneous and nonhomogeneous systems of linear
equations are considered.
4.1.4.1

Homogeneous Systems of Linear Equations

A system of linear equations is said to be homogeneous if it can be written in the form


Ax = 0, where A is an m n matrix and 0 is the zero vector in Rm . Such a system always
has at least one solution, which is x = 0 (i.e. zero vector in Rm .) This zero solution is
usually called the trivial solution. However, for a given equation Ax = 0, the important
question is whether there exists a nontrivial solution, that is, a nonzero vector x that
satisfies Ax = 0.
EXAMPLE 4.5
Determine if the following homogeneous system has a nontrivial solution. Then describe the
solution set.
3x1 + 5x2 4x3 = 0
3x1 2x2 + 4x3 = 0
6x1 + x2 8x3 = 0.

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

chapter 4 Linear Algebra

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

Nonhomogeneous Systems of Linear Equations

A system of linear equations is said to be nonhomogeneous if it can be written in the


form Ax = b, where A is an m n matrix and b is a non-zero vector in Rm .
EXAMPLE 4.6

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

chapter 4 Linear Algebra

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

An indexed set of vectors v1 , v2 , ..., vp in Rn is said to be linearly independent if the


vector equation
x1 v1 + x2 v2 + ... + xp vp = 0
has only a trivial solution. The same set is said to be linearly dependent if there exist
weights c1 , c2 , ..., cp , not all zero, such that
c1 v1 + c2 v2 + ... + cp vp = 0.

(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

chapter 4 Linear Algebra

57

Linear Independence of Matrix Columns

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

Let us again study

0
1
5

the augmented matrix:



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

More Theorems about Linear (In)dependence of Vectors

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

chapter 4 Linear Algebra

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 :

a11 . . . a1j . . . a1n


..
..
..
.
.
.

A = ai1 . . . aij . . . ain


.
..
..
..
.
.
am1 . . . amj . . . amn
where an entry in the ith row and j th column is called (i, j)entry of A and is denoted
as aij .
The same matrix can be presented by its columns as:

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

chapter 4 Linear Algebra

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

whose nondiagonal entries are zero. An example

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

Sums and Scalar Multiplies

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

while A + C does not exist since A and C have different sizes.


The sum A + B can be calculated in MATLAB as:
>> A=[4 0 5; -1 3 2]; B=[1 1 1; 3 5 7];
>> AB_sum=A+B;
If r is a scalar and A is a matrix, then the scalar multiple rA is the matrix which columns
are r times the corresponding columns in A. To demonstrate this we will calculate A2B,
where A and B are matrices defined above.

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

chapter 4 Linear Algebra

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.

Figure 4.4: (a) Multiplication by B and then by A. (b) Multiplication by AB.

CIV6115

chapter 4 Linear Algebra

If A is m n matrix, B n p matrix

b1 . . .

x1
..
x=
.

x
p

bp

61

and x is a vector of p entries:

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:

A(Bx) = Ab1 Ab2 ... Abp x.

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,

AB = A b1 b2 . . . bp = Ab1 Ab2 . . . Abp .


Note that since the first column of AB is Ab1 , this column is a linear combination of the
columns of A using entries in b1 as weights. A similar statement is true for each column
of AB.
However, for computing purposes, it is more practical to define product of matrices
Amn and Bnp for each entry in the matrix AB. The entry in row i and column j of AB
is the sum of products of corresponding entries from frow i of matrix A and column j of
matrix B. If (AB)ij denotes the (i, j)-entry in AB then
(AB)ij = ai1 b1j + ai2 b2j + ... + ain bnj .
This is called row-column rule for computing AB.
EXAMPLE 4.10
Use the row-column rule to compute (AB)13 and (AB)22 if A =

4
3 6
.
1 2 3

2
3
1 5

and B =

CIV6115

chapter 4 Linear Algebra

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.

Finding (AB)13 in MATLAB could be done by issuing this set of commands:


>> A=[2 3; 1 -5]; B=[4 3 6; 1 -2 3];
>> mult=A(1,:).*B(:,3);
>> AB_13=sum(mult);
Note that first we found individual products (by using multiplication operator .*) of
corresponding entries in first row in matrix A (A(1,:) means: first row of matrix A,
all columns of matrix A) and third column in matrix B (B(:,3) means: all rows, third
column). We acquired these individual products (these are 12 and 9) into the variable
called mult. Then we needed to sum them up to get (AB)13 as shown in third command
line. Note also that we had to transpose the column of matrix B because MATLAB
requires that two vectors which entries are to be multiplied one by one have to be of the
same size (i.e. either both are rows with the same number of elements or both are columns
with the same number of elements).
In a similar way we can find (AB)22 .
>> A=[2 3; 1 -5]; B=[4 3 6; 1 -2 3];
>> mult=A(2,:).*B(:,2);
>> AB_22=sum(mult);
Of course, we could find full product (i.e. not only entries 13 and 22) of matrices A and
B easily in MATLAB by typing:
>> A=[2 3; 1 -5]; B=[4 3 6; 1 -2 3];
>> AB=A*B;
in which case resulting matrix AB is a 2 3 matrix. We can see its elements by typing:
>> AB
The MATLAB then shows the result as:
AB =
11

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

chapter 4 Linear Algebra

63

Properties of Matrix Multiplication

The following are properties of matrix manipulation:


Let A be an m n matrix, and let B and C have sizes for which the indicated sums
and products are defined. Then the standard properties of matrix multiplication can be
defined:
1. A(BC) = (AB)C

(associative law of manipulation)

2. A(B + C) = AB + AC

(left distributive law)

3. (B + C)A = BA + CA

(right distributive law)

4. r(AB) = (rA)B = A(rB)

for any scalar r

5. Im A = A = AIn

(if I is identity matrix of appropriate size)

Warning 1: In general AB 6= BA.


Warning 2: If AB = AC, then it is not true in general that B = C.

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

If A is an n n matrix and if k is a positive integer, then Ak denotes the product of k


copies of A:
Ak = A
A} .
| {z
k
If k = 0 then A0 = I.
In MATLAB, we can calculate for example A3 either by issuing the command
>> A*A*A or
>> A^3
4.2.1.5

Transpose of a Matrix

Given an m n matrix A, the transpose of A is the n m matrix, denoted by AT , which


columns are formed from the corresponding rows of A.

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

chapter 4 Linear Algebra

64

>> A=[-5 2; 1 -3; 0 4];


>> A_transpose=A;
It is possible to prove that the following equalities apply for matrices A and B of appropriate sizes:
1. (AT )T = A
2. (A + B)T = AT + B T
3. (rA)T = rAT , for any scalar r
4. (AB)T = B T AT .

4.2.2

Inverse of a Matrix

An n n matrix A is said to be invertible if there is an n n matrix C such that


CA = I and AC = I
where I = In is n n identity matrix. In this case, C is called an inverse of A. In fact,
C is uniquely determined by A and is often denoted as A1 . Using this notation we can
write
A1 A = I and AA1 = I.
A matrix that is not invertible is sometimes called a singular matrix, while an invertible matrix is called a nonsingular matrix.
An n n matrix A that is invertible has rank(A) = n, where rank(A) is rank of matrix
A, i.e. the number of linearly independent columns in matrix A. This number ca be found
as a number of non-zero rows in a triangularised form of matrix A. If rank(A) < n then
matrix A is not invertible, i.e. it is a singular matrix. The command used in MATLAB
to find the rank of matrix A is rank(A).
EXAMPLE 4.11

Find the inverse of A =


EXAMPLE 4.11:

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

chapter 4 Linear Algebra

65

This is now equivalent to the following system of equations:


3a + 4c = 1
3b + 4d = 0
5a + 6c = 0
5b + 6d = 1.
This system can be written in the

3 0
0 3

5 0
0 5

matrix form as:



4 0
a

0 4
b

=
6 0
c

0 6
d

Triangularisation of the augmented matrix leads



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

chapter 4 Linear Algebra

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

Numerical Note on Calculation of Inverse Matrix

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

chapter 4 Linear Algebra

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.

Note that instead of writing det[ ] we can use notation | |.


end of the example
It is convenient to write the previous definition of the determinant in a slightly different
form. Given A = [aij ], the (i,j )-cofactor of A is the numebr of Cij given by
Cij = (1)i+1 det Aij .

(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

chapter 4 Linear Algebra

68

The determinant of an n n matrix A can be computed by a cofactor expansion


across any row or down any column. The expansion across the ith row using the
cofactors in Equation 4.13 is
det A = ai1 Ci1 + ai2 Ci2 + ... + ain Cin .
The cofactor expansion down the j th column is
det A = a1j C1j + a2j C2j + ... + anj Cnj .
The plus or minus sign in the (i, j)-cofactor depends on the position of aij in the matrix,
regardless of the sign of aij itself. The factor (1)i+j determines the following checkerboard pattern of signs:

+ + ...
+

+ +
.

..
..
.
.
EXAMPLE 4.13

Compute the determinant of A =

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

chapter 4 Linear Algebra

69

In addition we define several theorems related to use of determinants:


1. If A is triangular matrix, then det A is the product of the entries on the main
diagonal.

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

chapter 4 Linear Algebra

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

A subspace of a vector space V is a subset S of V that has the following properties:


(a) The zero vector of V is in S.
(b) S is closed under vector addition. Namely, if x S and y S then x + y S.
(c) S is closed under multiplication by scalars. Namely, if x S and is a scalar, then
x S.
Properties (a), (b) and (c) guarantee that a subspace S is itself a vector space, under
the vector operations already defined in V . Therefore, every subspace is a vector
space.
EXAMPLE 4.14
If A is an m n matrix, prove that set of all solutions to the homogeneous system Ax = 0
is a subspace of Rn .
EXAMPLE 4.14:

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

chapter 4 Linear Algebra

71

Linearly Independent Sets

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

It is easy to notice that p3 is a linear combination of p1 and p2 , since p3 = 4p1 p2 .


Therefore, the set is linearly dependent.
end of the example
EXAMPLE 4.16
Check if the set {sin t, cos t} is linearly independent for t [0, 1].
EXAMPLE 4.16:

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

Basis of Vector (Sub)space

Let S be a subspace of a vector space V . A set of vectors B = {b1 , b2 , ..., bp } in V is a


basis for S if
(i) B is a linearly independent set, and
(ii) all possible linear combinations of vectors in B make the subspace S.

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

chapter 4 Linear Algebra

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

Figure 4.5: Vectors in space R2 .


Although any two linearly independent vectors can form a basis in R2 it is much easier
to use a standard basis in calculations. This basis in R2 is


1
0
e1 =
, e2 =
.
0
1
Therefore, it is important to notice that there are many different sets of vectors that
can be used as a basis of a particular vector space. It is up to the user to choose the
most convenient one. Also, it is possible to transform a set of vectors that form a basis
into another basis in the same vector space.
You should notice that what we call the standard basis is composed of orthogonal
vectors, i.e. vectors which when they are multiplied between each other then the product
is equal to zero:
ei ej = 0, if i 6= j
while multiplied by themselves they give a nonzero product
ei ei 6= 0.
Additionally, if this product is equal to one, i.e.
ei ej = 0, if i 6= j
and
ei ei = 1,
then we say that the vectors in the basis are orthonormal.

CIV6115

chapter 4 Linear Algebra

The standard basis in Rn

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)

More Theorems on Basis of Vector Space

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

Eigenvalues and Eigenvectors

An eigenvector of an n n matrix is a nonzero vector x such that


Ax = x

(4.16)

when is a scalar called eigenvalue of A.


If we recall that multiplication of a vector x by a matrix A can be seen as a transformation
of vector x into the vector Ax, then we can say that eigenvectors are vectors that are
transformed by matrix A into a scalar multiple of themselves.
Equation 4.16 can be written in the form
Ax Ix = (A I)x = 0

(4.17)

where I is a unity (identity) matrix.


By definition, x has to be a nonzero vector. Equations 4.16 and 4.17 have nonzero
solutions only if the matrix A I is singular, i.e. non invertible matrix. Based on

CIV6115

chapter 4 Linear Algebra

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)

This equation is called the characteristic equation of A.


EXAMPLE 4.17

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

First we have to write the characteristic equation:

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

chapter 4 Linear Algebra

EXAMPLE 4.18

Find the eigenvalues and eigenvectors of A =


EXAMPLE 4.18:

75

3
2
.
3 2

SOLUTION

The characteristic equation is

3
2

3
2

= 2 12 = 0.

To solve a quadratic equation ax2 + bx + c = 0 we use the well-known formula:

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

chapter 4 Linear Algebra

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

Eigenvalues and corresponding eigenvectors in MATLAB can be obtained in this way:


>> A=[3 2; 3 -2];
>> [V,D] = eig(A);
MATLAB returns two matrices: D that has eigenvalues on its main diagonal and V that
has eigenvectors as its columns.
For the example presented the MATLAB output is:
D =
4
0

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

chapter 4 Linear Algebra

77

Expansion Theorem for Matrices with Distinct Eigenvalues

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

Matrices with Non-Distinct Eigenvalues

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

The Nth-Order Differential Equation

As we mentioned earlier in Chapter 1, one important way of modelling LTI systems is by


means of linear constant-coefficients differential equations. A differential equation (DE)
is an equation that presents a relationship between a function of time and its derivatives.
An example of a differential equation model would be the model of a mass-spring-damper
system exposed to some force x(t) (i.e. exposed to an input signal x(t), in system theory
terminology), as shown in Figure 5.1. The differential equation for this system (so called
the dynamic equation of motion) can be presented as:
my(t) + cy(t) + ky(t) = x(t),

(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).

Figure 5.1: A linear mass-spring-damper system.

78

CIV6115

chapter 5 Time-Domain Models

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)

When we substitute this solution in the homogeneous equation 5.3 we get:


a0 s0 (Cest ) + a1 s1 (Cest ) + ... + aN sN (Cest ) = 0.

(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

The N roots of this equation s = s1 , s = s2 , ..., s = sN are called characteristic roots.


The characteristic roots s1 , s2 , ..., sN may be real or complex. If we are dealing with

CIV6115

chapter 5 Time-Domain Models

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)

where C1 , C2 , ..., CN can be calculated from the initial conditions set at t = 0:


y(t)|t=0 = y0
dy(t)
dy0
|t=0 =
dt
dt
...
dN 1 y(t)
dN 1 y0
|t=0 =
.
dt
dt
The solution given in Equation 5.8 holds only when characteristic roots are all
different, i.e. when there are no multiple roots of the characteristic equation. This is
usually the case for the systems (structures) we are investigating in this course.

5.2

The Second Order Differential Equation

Modern Engineering Mathematics, G. James, Addison-Wesley Publishing Company, 1994.


In this section, we will find complete solution of the second order differential equation,
including both the homogeneous solution and the particular one.

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

chapter 5 Time-Domain Models

81

Roots as Real and Distinct Numbers

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+

where C1 and C2 can be obtained from the initial conditions:


y(t = 0) = y0

(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

Roots as Complex-Conjugate Numbers

The solutions of the characteristic equation are complex conjugates when c2 4mk < 0.
In this case
p

c2 4mk = (1)(4mk c2 ) = j 4mk c2 ,

where j = 1 is the imaginary unit.


Therefore, the characteristic roots become:

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

Now we can rewrite it as


yh (t) = 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

If we write C1 + C2 = C and j(C1 + C2 ) = D, we have

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

chapter 5 Time-Domain Models

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

Solving Second Order Homogeneous DE using MATLAB

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

chapter 5 Time-Domain Models

83

where K and Q1 could be found from


K =k+
and

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

4yi 4yi1 4yi1

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

% it clears all existing variables from the workspace

% 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

chapter 5 Time-Domain Models

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

The result is shown in Figure 5.2.


You could notice than in this example we chose the time step of 0.001 s. To make sure
that you get a numerical solution with small error, try different step sizes. If the solution
changes noticeably when reducing step size, than it is a sign that the error in your current
solution is unacceptable. Reduce the step size until you are happy with accuracy of the
solution. Of course, smaller step size you choose, generally you get more accurate solution
but also the execution time is longer.

chapter 5 Time-Domain Models

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

A particular solution of a nonhomogeneous differential equation, such as


my(t) + cy(t) + ky(t) = x(t)
is any solution that satisfies this equation. We concentrate here on second order differential equation. The same reasoning applies to differential equations of any order.
The method of undetermined coefficients can be used to find the particular solution for
some frequently used differential equations. In this section the examples taken from
http://www.math.oregonstate.edu/home/programs/undergrad/CalculusQuestStudyGuides/ode/second/so uc/so uc.html

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

Consider the example:


y(t) + 3y(t) + 2y(t) = e3t .
We guess that the particular solution has the form
yp (t) = Ae3t .
Here A is an unknown constant. In this case we have
yp = 3Ae3t

CIV6115

chapter 5 Time-Domain Models

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

Consider the example:


y(t) + 3y(t) + 2y = t + 1.
We guess that the particular solution has the form
yp (t) = At + B,
where A and B are unknowns. In this case we have
yp = A
and
yp = 0.
Substituting the expressions for yp , yp , and yp into the differential equation, we obtain
0 + 3A + 2(At + B) = t + 1.
Rearranging the left-hand side of this equation, we obtain
2At + (3A + 2B) = t + 1.
Comparing the coefficients of t on both sides of the equation, we conclude that 2A = 1.
Comparing the constant terms, we conclude that 3A + 2B = 1. The first equation implies
A = 12 . This fact and the second equation imply that B = 14 . Therefore, the particular
solution is
1
1
yp (t) = t .
2
4
If the nonhomogeneous term is a polynomial of degree n, then an initial guess for the
particular solution should be a polynomial of degree n:
yp (t) = An tn + An1 tn1 + An2 tn2 + ... + A1 t + A0 .

CIV6115
5.2.2.3

chapter 5 Time-Domain Models

87

f (t) = sine or cosine

Consider the example:


y(t) + 3y(t) + 2y = sin(3t).
We guess that the particular solution is
yp = A sin(3t) + B cos(3t).
Note that we have both sine and cosine terms in the solution. Now we calculate:
yp = 3A cos(3t) 3B sin(3t)
yp = 9A sin(3t) 9B cos(3t).
Substituting yp , yp , and yp into the differential equation we obtain:
9A sin(3t) 9B cos(3t) + 3(3A cos(3t) 3B sin(3t)) + 2(A sin(3t) + B cos(3t)) = sin(3t).
Rearranging the left-hand side of this equation, we obtain:
(7A 9B) sin(3t) + (9A 7B) cos(3t) = sin(3t).
Comparing the coefficients of sin(3t) on both sides of the equation, we conclude 7A
9B = 1. The right-hand side has no cosine terms. This means that the coefficient of
cosine on the left-hand side must be 0 - that is, 9A 7B = 0. Solving these equations we
7
9
conclude A = 130
and B = 130
. Therefore, the particular solution of the equation is:
9
7
sin(3t)
cos(3t).
yp =
130
130
In general if the nonhomogeneous term is of the form a sin(ct) + b cos(ct), where a and
b are constants, then an initial guess for the particular solution is again
yp = A sin(ct) + B cos(ct),
where A and B are coefficients to be determined.
5.2.2.4

f (t) = sum of various terms

Consider the differential equation


y(t) + 3y(t) + 2y = e3t + t + 1.
If the nonhomogeneous term is a sum of two terms, then the particular solution is
yp = yp1 + yp2 ,
where yp1 is a particular solution of
y + 3y + 2y = e3t
and yp2 is a particular solution
y + 3y + 2y = t + 1.
From our discussion above, we know
yp1 =
and that

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

chapter 5 Time-Domain Models

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

Unit Impulse Response Function

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)

where f (t) is assumed to be continuous at t = t0 . The unit impulse is actually a function


defined in terms of its area. One representation of it is given in Figure 5.3a, representing
a very tall and narrow pulse p(t) that has unit area. Thus, the impulse function is:
(t t0 ) = lim p(t) as 0.
Using the definition given in Equation 5.12 we can represent the product function on the
left hand side of the equation as shown in Figure 5.3b. The value of this integral then is
f (t0 )
= f (t0 ).

The response of an LTI (linear time-invariant) system to an input of a unit impulse


function, x(t) = (t), is called the unit impulse response. It is common practice to
designate the output y(t) as h(t) when the input is a unit impulse (t). This is illustrated
in Figure 5.3c, where we see that
an input x(t) = (t) the output y(t) = h(t).
When determining the unit impulse response h(t) of an LTI system, it is necessary to
make all initial conditions zero. That is, we must be certain that the response is due
entirely to the input x(t) = (t) and not due to any energy that might be stored in the
system. In general, it is not easy to find an analytical form for the h(t) without the
use of transforms. The simple system (continuous-time integrator) illustrated in the next
example is an exception.

CIV6115

chapter 5 Time-Domain Models

89

Figure 5.3: Impulse function and response.

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

chapter 5 Time-Domain Models

90

Figure 5.4: Example 5.2: Step function.


end of the example

5.3.2

Response to Arbitrary Input

Lecture notes for CIV6180: Vibration Engineering, A. Pavic, 2006.


Thanks to the principle of superposition, the output of an LTI system to an arbitrary
time-varying input x(t) can be calculated as a sum of responses to a series of short impulses
of which the original input is composed, as shown in Figure 5.5.
Therefore, if we are to calculate an output y(t) of the system at time tj , it is necessary
to add up contributions of all impulses (for a short period t impulses can be assumed
to be constant) applied at times ti before time tj . Therefore,
y(tj ) =

j
X

x(ti )h(tj ti )t.

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

Equation 5.13 is also known as a convolution or Duhamel integral.

CIV6115

chapter 5 Time-Domain Models

91

Figure 5.5: Schematic explanation of a convolution integral.

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

chapter 5 Time-Domain Models

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

chapter 5 Time-Domain Models

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

Figure 5.6: Example 5.3: Impulse response function.


We proceed with defining the input signals:
% input 1
x_1=500*sin(2*pi*2*t);
% input 2
x_2=500*sin(2*pi*3*t);
Having defined both the impulse response function and the input signals, we can calculate
the output signals (responses) by using conv command in MATLAB:
% solution by convolution to input 1
y_1=conv(x_1,h); y_1=y_1*dt;
% solution by convolution to input 1
y_2=conv(x_2,h); y_2=y_2*dt;
Note that we had to multiply the response calculated in MATLAB by dt because definition
of convolution in MATLAB does not take into account the time step dt that appears on
the right-hand side of the convolution integral calculated in Equation 5.13.

CIV6115

chapter 5 Time-Domain Models

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

chapter 5 Time-Domain Models

2.5

95

Resonance

x 10

Output (displacement) signal [m]

2
1.5
1
0.5
0
0.5
1
1.5
2
2.5

10

20

30
Time [s]

40

50

60

Figure 5.7: Example 5.3: Response to input 1.

Outofresonance

x 10

Output (displacement) signal [m]

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

Figure 5.8: Example 5.3: Response to input 2.

end of the example

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

Frequency Response Function

Dynamic properties of a system could be described by studying the response of the system
to a sine input (Figure 6.1).

Figure 6.1: Sine response of a system to a sine input.

Namely, if the input is a constant amplitude sine wave of fixed frequency :


x(t) = X sin t

(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

chapter 6 Frequency Response Function

97

this function can be thought of as a system property (independent on input and


output) that transforms a sine input into a sine output of different amplitude and phase,
but of the same frequency.
By making measurements of the output magnitude and phase (for inputs of known magnitude and frequency) at a series of closely spaced frequencies, the amplitude ratio Y /X
and phase can be plotted as a function of frequency. In theory if the frequency range
extends from zero to infinity then the dynamic characteristics of the system are completely defined. In practice, the frequency range could be limited to a finite range that is
of practical importance for problem considered.
EXAMPLE 6.1
Determine the amplitude ratio and phase angle for the transmission of sine wave excitation
through the spring-damper system shown in Figure 6.2.

Figure 6.2: Spring-damper system.

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

+ Y cos t(c cos k sin ) = 0.

CIV6115

chapter 6 Frequency Response Function

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

It is well known that sin2 + cos2 = 1, so we get:


c2 2 + k 2 =

X2
,
Y2

which also can be written in the form:


Y
1
=
X
k 2 + c2 2 .

(6.3)

From the previous equation c cos k sin = 0 we can get


tan =

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

chapter 6 Frequency Response Function

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

Complex Form of Frequency Response Function

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 =

1 and A() and B() are real functions of , then by definition


p
Y
A()2 + B()2 =
X

(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

chapter 6 Frequency Response Function

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

y(t) = X A2 + B 2 sin t tan

B
A

i.e. using Equations 6.5 and 6.6


y(t) = X|H()| sin(t ) = Y sin(t ).
Therefore, to summarise, if a constant amplitude harmonic input given by
x(t) = Xeit

(6.7)

is applied to a linear system, the corresponding output y(t) will be given by


y(t) = H()Xeit

(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

The differential equation for the system is


cy(t) + ky(t) = x(t).
Putting x(t) = Xeit and y(t) = H()Xeit into the equation gives:
(ci + k)H()Xeit = Xeit
i.e. our complex FRF is
H() =

1
.
k + ic

We can easily show that this function is the same as the one in the previous example.

CIV6115

chapter 6 Frequency Response Function

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

we can find the amplitude ratio as

Y
1
= |H()| = A2 + B 2 =
2
X
k + c2 2
and then the phase angle as
tan =

B()
c
=
A()
k

which is the same as in the previous example.


end of the example

S-ar putea să vă placă și