Вы находитесь на странице: 1из 247

MATH2118

Haw Ming Seow’s Custom Edition


MATH2118 Lecture Notes
Further Engineering Mathematics C

Matrices

Dr Eddie Ly

School of Mathematical & Geospatial Sciences (SMGS)


College of Sciences, Engineering & Health (SEH)
RMIT University, Melbourne, Australia

Summer Course 2015

1
2 Matrices

Contents
1 Introduction 3

1.1 Equality of Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

1.2 Addition of Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

1.3 Scalar Multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

1.4 Matrix Multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

1.5 Tranpose of a Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2 Some Special Matrices 8

2.1 Zero Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

2.2 Unit (Identity) Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2.3 Diagonal Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2.4 Triangular Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2.5 Symmetric and Antisymmetric Matrices . . . . . . . . . . . . . . . . . . . . . . . 10

2.6 Orthogonal Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

2.7 Invertible Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

2.8 Diagonalisation of Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

3 Gaussian Elimination 12

4 Inverse of a Matrix 14

5 Determinant of a Matrix 16

5.1 Properties of Determinants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

6 Eigenvalues and Eigenvectors 18

7 Review Questions 24

8 Answers to Review Questions 26


Lecture Notes – MATH2118 Further Engineering Mathematics C 3

1 Introduction

We define any rectangular arrangement of elements to be a matrix. Generally, square


brackets [ ] are used to denote a matrix. For example,

[ ]
x y z is a row matrix or row vector,
 
x
 
y is a column matrix or column vector, and
 
z
 
a11 a12 a13
 
 a21 a22 a23  is a 3 × 3 matrix (3 rows and 3 columns).
 
a31 a32 a33

A square matrix has an equal number of rows and columns. The general m × n matrix is
 
a11 a12 a13 · · · · · · a1n
 ( ) 
 a21 a22 a23 · · · · · · a2n 
[ ]  
 
A = aij mn =  a31 a32 a33 · · · · · · a3n .
 .. 
 .. .. .. .. ..
.
 . . . . . 
am1 am2 am3 · · · · · · amn

The element a23 is the element in second row and third column of matrix A. The
dimension (or order) of a matrix is the number of rows by the number of columns.

1.1 Equality of Matrices

Two matrices are said to be equal if they have the same order and all corresponding
elements are equal. For example,
[ ] [ ]
a11 a12 b11 b12
A= and B =
a21 a22 b21 b22

both have the same order (i.e. 2×2 matrix) and are equal if a11 = b11 , a12 = b12 , a21 = b21
and a22 = b22 , or aij = bij for i, j = 1, 2.
4 Matrices

1.2 Addition of Matrices

If A = [aij ]mn and B = [bij ]mn (both matrices must have the same order) then
[ ] [ ]
A + B = aij + bij mn = bij + aij mn = B + A.

That is, matrices commute under addition,

A+B =B+A and A + (B + C) = (A + B) + C.


[ ] [ ]
a11 a12 b11 b12
For example, if A = and B = , then
a21 a22 b21 b22
[ ] [ ]
a11 + b11 a12 + b12 b11 + a11 b12 + a12
A+B = = = B + A.
a21 + b21 a22 + b22 b21 + a21 b22 + a22

1.3 Scalar Multiplication

If A is a matrix and k is a scalar (real or complex number) then


[ ] [ ]
kA = k aij mn = kaij mn .
[ ]
a11 a12
Thus, A − B = A + (−1)B. For example, if A = , then
a21 a22
[ ]
ka11 ka12
kA = .
ka21 ka22

1.4 Matrix Multiplication


[ ] [ ]
If A = aij mn and B = bjk rs , then the product C = AB is defined only if n = r. That
is, the number of columns in A equals the number of rows in B. The order of matrix C
[ ] [ ] [ ]
is m × s, i.e. aij mn bjk rs = cik ms , where

n
cik = aij bjk
j=1

= ai1 b1k + ai2 b2k + ai3 b3k + · · · + ain bnk


= dot product of the ith row of A with the kth column of B.
Lecture Notes – MATH2118 Further Engineering Mathematics C 5

In general, matrices are non-commutative under multiplication,

AB ̸= BA.

If two matrices are not conformable (not able to be multiplied), then their product is
undefined.

EXAMPLE   
1 2 0 a
   
If A = 
 2 −1 2 , find all solutions x =  b  of Ax = −3x.
  
0 2 1 c
solution
    
1 2 0 a a
    
Ax = −3x ⇒
 2 −1 2  b  = −3 b .
   
0 2 1 c c

Expanding this system of equations gives

a + 2b = −3a ⇒ 2a + b = 0
2a − b + 2c = −3b ⇒ a+b+c=0
2b + c = −3c ⇒ b + 2c = 0

The first and third equations give a = c = − 21 b, and inserting into the second
equation gives − 21 b + b − 12 b = 0, which is true for all real values of b. Hence,
   
− 12 1
   
x = b 1  = − b  −2 .
  2 
−2 1
1

note:
If all operations are defined, then

A(B + C) = AB + AC,
(B + C)A = BA + CA,
A(BC) = (AB)C.
6 Matrices

Since AB ̸= BA, in general, we have

(A − B)(A + B) = A2 + AB − BA − B 2
̸= A2 − B 2 ,

(A + B)2 = (A + B)(A + B)
= A2 + AB + BA + B 2
̸= A2 + 2AB + B 2 ,

(AB)2 = ABAB
̸= A2 B 2 .

1.5 Tranpose of a Matrix


[ ]
If A is an m × n matrix aij mn , then the transpose of A, denoted by AT , is the n × m
[ ]
matrix aji nm obtained by interchanging the rows and columns of A.
[ ]
1 2 3
For example, if A = , then
4 5 6
 
1 4
 
A =2 5

T
.
3 6

The ith row of AT is the ith column of A, and the jth column of AT is the jth row of
A.

note:
(A + B)T = AT + B T if A and B have the same order,
( T )T
A = A,

(AB)T = B T AT provided AB is defined (A and B are conformable).


Lecture Notes – MATH2118 Further Engineering Mathematics C 7

EXAMPLE [ ] [ ] [ ]
1 2 0 −1 5 1
Given A = ,B= and C = , show that
3 4 2 1 1 3

(a) (A + B)C = AC + BC,


(b) (AB)C = A(BC),
(c) (AB)T = B T AT .

solution
[ ] [ ] [ ]
1 2 0 −1 1 1
A+B = + , =
3 4 2 1 5 5
[ ][ ] [ ]
1 1 5 1 6 4
(A + B)C = = ,
5 5 1 3 30 20
[ ][ ] [ ]
1 2 5 1 7 7
AC = = ,
3 4 1 3 19 15
[ ][ ] [ ]
0 −1 5 1 −1 −3
BC = = ,
2 1 1 3 11 5
[ ] [ ] [ ]
7 7 −1 −3 6 4
⇒ AC + BC = + =
19 15 11 5 30 20
= (A + B)C.
[ ][ ] [ ]
1 2 0 −1 4 1
AB = = ,
3 4 2 1 8 1
[ ][ ] [ ]
4 1 5 1 21 7
(AB)C = = ,
8 1 1 3 41 11
[ ][ ] [ ]
1 2 −1 −3 21 7
⇒ A(BC) = =
3 4 11 5 41 11
= (AB)C.
[ ]T [ ]
T 4 1 4 8
(AB) = = ,
8 1 1 1
[ ]T[ ]T [ ][ ] [ ]
0 −1 1 2 0 2 1 3 4 8
⇒ B T AT = = =
2 1 3 4 −1 1 2 4 1 1
= (AB)T .
8 Matrices

2 Some Special Matrices

2.1 Zero Matrix

A matrix of any order contains only zero elements. For example,


 
0 0 ··· ··· ··· 0
 
0 0 ··· ··· ··· 0 
 
 .. ... .
. ··· · · · · · · .. 
0=  ..

. .
. · · · .. 
..
. ··· ··· 
. 
. . . .. 
. ··· ··· ··· . .
0 0 ··· ··· ··· 0

Note that
A + 0 = 0 + A = A (identity under matrix addition)

and
A0 = 0A = 0.

Unlike ordinary algebra, AB = 0 does not imply that A = 0 or B = 0.

EXAMPLE    
2 −3 −5 −1 3 5
   
Given A = 
 −1 4 5 and B =  1 −3 −5 , we have
 
1 −3 −4 −1 3 5
  
2 −3 −5 −1 3 5
  

AB =  −1 4 5  1 −3 −5 


1 −3 −4 −1 3 5
 
0 0 0
 
= 0 0 0 

0 0 0
= 0.

Even though A ̸= 0 and B ̸= 0, we obtain AB = 0.


Lecture Notes – MATH2118 Further Engineering Mathematics C 9

2.2 Unit (Identity) Matrix

The unit matrix I n (or I when the order is known) is a square matrix of order n × n with
entries of 1’s down the main diagonal and 0’s everywhere else. For example,
 
1 0 0 0 0 0
 
0 1 0 ··· 0···
 
 
0 0 1 ··· ··· 0 
In = 

.
. ··· 0 
..
0 0 ··· 
 
0 0 ··· ···
...
0
 
0 0 0 0 0 1

For any square matrix A,


AI = IA = A.

2.3 Diagonal Matrices

A square matrix in which all off-diagonal elements are zero. If both A and B are diagonal
matrices of the same order, then A + B and AB are also diagonal, and AB = BA.
For example,
 
a11 0 0
 
A=
 0 a22 0  where a11 , a22 , a33 ̸= 0.
0 0 a33

2.4 Triangular Matrices

A lower triangular matrix is a square matrix where all elements above the main diagonal
are zero, such as
 
ℓ11 0 0
 
L=
 ℓ21 ℓ22 0 .
ℓ31 ℓ32 ℓ33
10 Matrices

An upper triangular matrix is a square matrix where all elements below the main diagonal
are zero. For example,  
u11 u12 u13
 
U =
 0 u22 u23 
.
0 0 u33

2.5 Symmetric and Antisymmetric Matrices

A square matrix A is symmetric if AT = A, i.e. aij = aji , displaying symmetry about


the main diagonal. Matrix A is anti-symmetric (or skew-symmetric) if AT = −A, i.e.
aij = −aji , displaying anti-symmetry about the main diagonal (the diagonal will consist
solely of zero elements).

EXAMPLE
Matrix A is anti-symmetric, since
   
0 1 2 0 −1 −2
   
A=  −1 0 3 and A T
= 1
 0 −3  = −A.

−2 −3 0 2 3 0

2.6 Orthogonal Matrices

A square matrix P is said to be orthogonal if

P P T = P T P = I.

The columns (rows) of an orthogonal matrix are mutually orthogonal unit vectors. For
example,  
1 −2 −2
1 
P =  2 2 −1 .
3 
2 −1 2

2.7 Invertible Matrices

A square matrix A is said to be invertible (or non-singular ) if there exists a square matrix
B such that
AB = BA = I.
The matrix B is then called the inverse of A, denoted by A−1 , and its inverse is unique.
Lecture Notes – MATH2118 Further Engineering Mathematics C 11

EXAMPLE [ ]
2 −5
Consider matrix A = . The inverse of A is
−1 −3
[ ]
−1 3/11 −5/11
A = ,
−1/11 −2/11

since
[ ][ ]
2 −5 3/11 −5/11
AA−1 =
−1 −3 −1/11 −2/11
[ ]
1 0
=
0 1
= I.

remarks:

Note that not every square matrix has an inverse. If |A| = 0 then A−1 cannot exist, since

|AB| = |A| × |B|,

and if |A| = 0, then |AB| = 0, while |I| = 1. Hence, it is impossible for AB = I,


because |AB| ̸= |I|. If both A and B are non-singular matrices of the same order, then
( )−1
A−1 = A,
( T )−1 ( −1 )T
A = A ,
(AB)−1 = B −1 A−1 .

2.8 Diagonalisation of Matrix

Square matrix P diagonalises matrix A if

P −1 AP = I.
12 Matrices

3 Gaussian Elimination

Consider the following system of equations:

x1 + 2x2 + x3 = 0,
2x1 + 2x2 + 3x3 = 3,
−x1 − 3x2 = 2.

The coefficients of the unknowns (the symbols used for the unknowns are not important)
together with the right-hand-side constants are all that is needed when determining the
solution. Rewrite the system of equations in an augmented matrix form shown below,
 
1 2 1 0 R1
 
 2 2 3 3 
 R2
−1 −3 0 2 R3

step 1:
Eliminate x1 from R2 and R3 . We define multipliers,
a21 2 a31 −1
m21 = = = 2 and m31 = = = −1,
a11 1 a11 1
and substract m21 R1 from R2 , and substract m31 R1 from R3 :
 
1 2 1 0
 
 0 −2 1 3 R2 − 2R1
 
0 −1 1 2 R3 + R1
step 2:
Eliminate x2 from R3 by substracting 12 R2 from R3 :
 
1 2 1 0
 
 0 −2 1 3 
 
0 0 21 12 R3 − 12 R2
All elements below the main diagonal are zero, this matrix is said to be in row-echelon
form.
step 3:
Work backwards from the last to first equation:
1
x
2 3
= 1
2
⇒ x3 = 1
−2x2 + x3 = 3 ⇒ x2 = −1
x1 + 2x2 + x3 = 0 ⇒ x1 = 1

Gaussian elimination is the most efficient means of solving a system of linear equations.
Lecture Notes – MATH2118 Further Engineering Mathematics C 13

EXAMPLE
Determine the solutions (if they exist) of the following system of equations,

x1 + 2x2 + 3x3 = 2,
4x1 + 5x2 + 6x3 = 8,
7x1 + 8x2 + 9x3 = 13.

solution
Write this system of equations in an augmented matrix form,
   
1 2 3 2 1 2 3 2
   
 4 5 6 8 ∼ 0 −3 −6 0 
   R2 − 4R1
7 8 9 13 0 −6 −12 −1 R3 − 7R1
 
1 2 3 2
 
∼
 0 1 2 0 
− 3 R2
1

0 0 0 −1 R3 − 2R2

The last row of this matrix implies 0x1 + 0x2 + 0x3 = −1, which is clearly impos-
sible. Hence, this system has no solution; such systems of equations are said to be
inconsistent.

EXAMPLE
Determine the solutions (if they exist) of the following system of equations,

x1 + 2x2 + 3x3 = 2,
4x1 + 5x2 + 6x3 = 8,
7x1 + 8x2 + 9x3 = 14.

solution

   
1 2 3 2 1 2 3 2
   
 4 5 6 8 ∼ 0 −3 −6 0 
   R2 − 4R1
7 8 9 14 0 −6 −12 0 R3 − 7R1
 
1 2 3 2
 

∼ 0 1 2 0 
− 3 R2
1

0 0 0 0 R3 − 2R2
14 Matrices

The last row of zeros indicates that the last equation in the system is redundant.
Working backward from R2 to R1 , where x3 can take any value, we have

x2 + 2x3 = 0 ⇒ x2 = −2x3
x1 + 2x2 + 3x3 = 2 ⇒ x1 = 2 − 2x2 − 3x3 = 2 + x3

For instance, if x3 = α (any real value), the general solution is


     
x1 = 2 + α x1 2 1
     
x2 = −2α ⇒ x  =  0  + α −2 ,
   
2  
x3 = α x3 0 1

or
(x1 , x2 , x3 ) = (2, 0, 0) + α(1, −2, 1); α ∈ R.

4 Inverse of a Matrix

If the matrix A is non-singular, i.e. |A| ̸= 0, then its inverse A−1 may be found in the
following way:

[ ]
(1) Write down A with the unit matrix I in an augmented matrix form, i.e. A| I .
[ ]
(2) Perform a sequence of elementary row operations on A | I until A becomes I.
[ ]
(3) By then matrix I will have been converted into the inverse matrix A−1 , i.e. I | A−1 .

note:
[ ]
a b
For a 2 × 2 matrix, A = , its matrix inverse can be found using the following
c d
formula [ ]
1 d −b
A−1 = where |A| = ad − bc.
|A| −c a
This is only for a 2 × 2 matrix.
Lecture Notes – MATH2118 Further Engineering Mathematics C 15

EXAMPLE 
1 1 0
 
If A = 
 1 0 1 , find A−1 using elementary row operations.

0 1 1

solution
 
1 1 0 1 0 0
 
1 0 1 0 1 0
 
0 1 1 0 0 1
 
1 1 0 1 0 0
 
∼  0 −1 1 −1 1 0
 R2 − R1
0 1 1 0 0 1
 
1 0 1 0 1 0 R1 + R2
 
∼  0 −1 1 −1 1 0

0 0 2 −1 1 1 R3 + R2
 
2 0 0 1 1 −1 2R1 − R3
 
∼  0 −2 0 −1 1 −1   2R2 − R3
0 0 2 −1 1 1
 1
1 0 0 1 1
− 12 2 R1
 2 2 

∼0 1 0 1
− 12 1  − 1 R2
2 2  2
0 0 1 − 12 1
2
1
2
1
R
2 3

Inverse of A:  
1 1 −1
1 
A −1
=  1 −1 1
.
2
−1 1 1

Check: Show AA−1 = I holds for A:


  
1 1 0 1 1 −1
1



−1
AA =  1 0 1  1 −1 1
2
0 1 1 −1 1 1
 
2 0 0
1 
=  0 2 0
2 
0 0 2
= I.
16 Matrices

5 Determinant of a Matrix

To each square matrix there is associated a number called the determinant of a matrix.
For example, for n × n matrix A,

a11 a12 ··· a1n
···


a21 a22 · · · · · · a2n
. .. ...

..
det A = A = .. . ··· . .
. ..
. .. ..
. . ··· . .

an1 an2 · · · · · · ann
[ ]
a11 a12
For a 2 × 2 matrix, A = , the 2 × 2 determinant is
a21 a22

a
11 12
a
detA = = a11 a22 − a21 a12 .
a21 a22

A 3 × 3 determinant is defined in terms of 2 × 2 determinants,




a11 a12 a13 a a a

a21 a22 a23 = a11 22 23 −a12 21 23 +a13 21 22 .
a a a
a32 a33 a31 a33 a31 a32

a31 a32 a33 | {z } | {z } | {z }
minor of a11 minor of a12 minor of a13

The minor of a11 is obtained from the original determinant by deleting the row and column
which contains a1 , etc. Note the sequence of signs + − + associated with the coefficients
a11 , a12 and a13 , respectively. Alternatively, we can expand the determinant across the
second or third rows, or even down any of the columns.

For example, expanding down the first column gives




11 12 13
a a a a a a
a a a
a21 a22 a23 = a11 22 23
−a21
12 13
+a31
12 13
.
a32 a33 a32 a33 a22 a23

a31 a32 a33 | {z } | {z } | {z }
minor of a11 minor of a21 minor of a31

Note the following pattern of signs when expanding a 3 × 3 determinant,

+ − +
− + −
+ − +
Lecture Notes – MATH2118 Further Engineering Mathematics C 17

High-order determinants can be expanded in terms of lower-order determinants in a similar


manner to 3 × 3 determinants where the pattern of signs extends naturally as follows,
+ − + − ···
− + − + ···
+ − + − ···
− + − + ···
.. .. .. .. . .
. . . . .

5.1 Properties of Determinants

For square matrices A, B, C and a scalar k:

(1) If A = BC then |A| = |B||C|.

However, if A = B + C, then |A| ̸= |B| + |C|.

(2) If two columns (rows) of A are identical then |A| = 0.

(3) If one column (row) of A is the zero vector, then |A| = 0.

For example,


0 0 0 a a a

a21 a22 a23 = 0 22 a 23
− 0


21 a 23
+ 0


21 a22
= 0.

a32 a33 a31 a33 a31 a32
a31 a32 a33

(4) Interchanging two columns (rows) of a determinant changes the sign of the deter-
minant.

(5) The determinant is unaltered if a scalar multiple of one row (column) is added to
another row (column).

(6) Interchanging the rows and columns of a determinant does not alter its value,
T
A = |A|.

(7) If A is the matrix obtained from matrix A by replacing the jth column (row), vector
Aj , by kAj , then |Ā| = k |A|. For example,

ka
11 ka 12
= ka11 a22 − ka12 a21
a21 a22

= k(a11 a22 − a12 a21 )



a
11 a12
= k .
a21 a22
18 Matrices

EXAMPLE
2 −3

= (2 × 3) − (−4 × −3)
−4 3
= 6 − 12
= −6.

EXAMPLE
Expanding along the last column gives


−1 3 1 2 5 −1 3 −1 3

2 5 0 = 1 + 0 − 1
3 2 3 2 2 5

3 2 −1
= (4 − 15) + 0 − (−5 − 6)
= 0.

6 Eigenvalues and Eigenvectors

Consider any linear transformation A, which operates on the column vector v. If the
condition
Av = λv
is satisfied for λ (a scalar), then we have a situation where the transformation A does not change
the direction of v. The vector V is called an eigenvector of A, and the scalar λ is called
an eigenvalue of A; λ may be zero, real or complex value.

Note that if v is an eigenvector, then so is kv for some constant k. Thus, an eigenvector is


simply a vector which maps on a scalar multiple of itself, while eigenvalue gives a measure
of how the eigenvector is “stretched”. Note that

Av = λv = λIv,

where I is the identity matrix (same dimension as A), then


( )
A − λI v = 0 and |A − λI||v| = 0.

Since v ̸= 0, so |v| ̸= 0, it follows that


( )
det A − λI = |A − λI| = 0,

which is the characteristic equation of the matrix A (nth degree polynomial for n × n
matrix A). Hence, there are n real or complex eigenvalues (roots of its characteristic
equation) for an n × n matrix including repeated roots.
Lecture Notes – MATH2118 Further Engineering Mathematics C 19

EXAMPLE  
1 −2 7
 
Determine the eigenvalues and eigenvectors of A = 
 0 −1 3 .

0 0 2
solution
Computing A − λI:
   
1 −2 7 1 0 0
   

A − λI =  0 −1 
3  − λ 0 1 0 


0 0 2 0 0 1
 
1−λ −2 7
 
= 0 −1 − λ 3.
0 0 2−λ
Characteristic equation:


1 − λ −2 7

A − λI = 0 −1 − λ 3


0 0 2−λ

1−λ −2

= 0 − 0 + (2 − λ)
0 −1 − λ
[ ]
= (2 − λ) (1 − λ)(−1 − λ) − 0
= −(2 − λ)(1 − λ)(1 + λ).

Setting |A − λI| = 0 gives the eigenvalues λ = 2, 1, −1.

Eigenvector for λ = −1:

Find all non-zero vectors, v = [a b c]T , which satisfy


( )
Av = λv or A − λI v = 0.

For λ = −1,
      

1−λ −2 7 a 2 −2 7 a 0
       
 0 −1 − λ 3   0 3    
  b  =  0  b  =  0 .
0 0 2−λ c 0 0 3 c 0
Expanding this matrix equation gives

2a − 2b + 7c = 0,
3c = 0,
3c = 0.
20 Matrices

Thus, c = 0 and a = b,  
1
 
v = a 
 1 .
0
A possible eigenvector is (1, 1, 0).

Eigenvector for λ = 1:
       
1−λ −2 7 a 0 −2 7 a 0
       
 0 −1 − λ 3       
  b  =  0 −2 3  b  =  0 
0 0 2−λ c 0 0 1 c 0

Expanding this matrix equation gives

−2b + 7c = 0,
−2b + 3c = 0,
c = 0.

Thus, for b = c = 0, we have  


1
 
v = a 
 0 ,
0
and a possible eigenvector is (1, 0, 0).

Eigenvector for λ = 2:
       
1−λ −2 7 a −1 −2 7 a 0
       
 0 −1 − λ 3  b  =  0 −3 3  b  =  0 
     
 .
0 0 2−λ c 0 0 0 c 0

This gives

−a − 2b + 7c = 0,
−3b + 3c = 0,
0 = 0.

Thus, for b = c and a = −2b + 7c = 5c,


 
5
 
v = c 1 

,
1

and a possible eigenvector is (5, 1, 1).


Lecture Notes – MATH2118 Further Engineering Mathematics C 21

note:

If we construct a non-singular matrix, P , whose columns are eigenvectors (xi ), corre-


sponding to the distinct eigenvalues, λi , of matrix A, respectively,
[ ]
P = x1 , x2 , . . . , xn ,

then P −1 AP is a diagonal matrix, D, consists of λi values only,


 
λ1 0 0 0 0
 
 0 λ2 . . . . . . . . . 
 
 
P −1 AP = D =  . . . . . . λi . . . . . . .
 
 . . . . . . . . . ... . . . 
 
0 0 0 0 λn

The λi appear in the same order along the diagonal as the order of the eigenvector xi in
the column of P . Note that P is singular if A does not have distinct eigenvalues.

EXAMPLE
The eigenvectors of the last example are
     
1 1 5
     
x1 =  
 1 , x2 = 
0
 and x3 = 
1

0 0 1

correspond to λ1 = −1, λ2 = 1 and λ3 = 2, respectively. Show that P −1 AP = D


is valid for the matrix P given below,
 
1 1 5
  [ ]
 
P =  1 0 1  = x1 , x2 , x3 .
0 0 1

solution  
1 −2 7
 
Recalling that A =  0 −1 3 

. Computing inverse of P as follows,
0 0 2
   
1 1 5 1 0 0 R2 → R1
1 0 1 0 1 0
   
   
 1 0 1 0 1 0  ∼  1 1 5 1 0 0  R1 → R2
   
0 0 1 0 0 1 0 0 1 0 0 1
22 Matrices

 
1 0 1 0 1 0
 
 
∼0 1 4 1 −1 0  R2 − R1
 
0 0 1 0 0 1
 
1 0 0 0 1 −1 R1 − R3
 
 
∼0 1 0 1 −1 −4  R2 − 4R3
 
0 0 1 0 0 1
 
0 1 −1
 
Thus, the inverse is P −1 = 
 1 −1 −4 .

0 0 1

Check: Verifying P P −1 = I,
    
1 1 5 0 1 −1 1 0 0
    
P P =  1 0 1  1 −1 −4  =  0 1 0 
−1    
 = I.
0 0 1 0 0 1 0 0 1

Hence,
   
0 1 −1 1 −2 7 1 1 5
   
P −1 AP = 
 1 −1 −4   0 −1 3  1 0 1 
  
0 0 1 0 0 2 0 0 1
  
0 −1 1 1 1 5
  
= 1 −1 −4   
 1 0 1 
0 0 2 0 0 1
 
−1 0 0
 
= 0 1 0
0 0 2
 
λ1 0 0
 
= 0 λ2 0 
0 0 λ3
= D.
Lecture Notes – MATH2118 Further Engineering Mathematics C 23

EXAMPLE [ ]
1 2
Find the eigenvalues of A = .
2 −2
solution

Evaluating A − λI first,

1 − λ 2

A − λI =
2 −2 − λ

= (1 − λ)(−2 − λ) − 4
= −2 − λ + 2λ + λ2 − 4
= λ2 + λ − 6
= (λ + 3)(λ − 2).

Setting A − λI = 0 gives the eigenvalues of A,

λ1 = −3 and λ2 = 2.
24 Matrices

7 Review Questions

[1] Determine the solutions of the systems of equations:

(a)

x1 − 2x2 + 3x3 = 5,
2x1 + x2 − 5x3 = −7,
4x1 − 3x2 + 2x3 = 5.

(b)

2x1 − x2 + 7x3 = 18,


x1 + x2 + x3 = 3,
5x1 + 2x2 + 3x3 = 6.

[2] Find the general solution of the system of equations:

(a)

x1 + x2 + x3 + 2x4 − x5 = 0,
2x1 − x2 − x3 + x4 + 2x5 = 0,
x1 + 3x2 − 2x3 + x4 + x5 = 0.

(b)

x1 − 2x2 + x3 − x4 = 0,
2x1 + 4x2 − 3x3 = 0,
3x1 + 2x2 + 2x3 − x4 = 0.
 
3 2 −2
 
[3] If A = 
 −1 −4 1
, show that A + 2A − A − 2I = 0.
3 2

2 −4 −1

[4] Determine the inverse (if it exists) of each of the following matrices:
 
0 1 1
 
(a)  1 0 1 

;
1 1 0
 
1 2 3
 
(b)  4 5 6 ;

7 8 9
Lecture Notes – MATH2118 Further Engineering Mathematics C 25

 
−1 1 1 1
 
 1 −1 11
(c) 

.
 1 1 −1 1
1 1 1 −1

[5] By solving [ ][ ] [ ]
a b x y 1 0
=
c d z w 0 1
(where ad − bc ̸= 0) for x, y, z and w, show that
[ ]−1 [ ]
a b 1 d −b
= .
c d ad − bc −c a
[ ]
−3 −7
Hence, write down the inverse of A = .
2 8

[6] Determine the eigenvalues and a set of three linearly independent eigenvectors for
each of the following matrices A:
 
1 −2 7
 
(a) 
 0 −1 3 ;

0 0 2
 
3 2 4
 
(b) 
 2 0 2 .

4 2 3
26 Matrices

8 Answers to Review Questions


   
x1 1
   
[1] (a)    
 x2  =  1 
x3 2
   
x1 −1
   
(b)  x 
 2  =  1 

x3 3
     
x1 −5 −5
     
 x2   −2   6
     
     
[2] (a)  x3  = α −3  + β  14 
     
x   5  0
 4    
x5 0 15
   
x1 −2
   
 x2   1 
 
(b)   = α  

 x3   0 
x4 −4

[3] Not available.


 
−1 1 1
1 
[4] (a)  1 −1 1 
2 
1 1 −1
(b) No inverse exists.
 
−1 1 1 1
 
1 1 −1 1 1 
(c)  
4
 1 1 −1 1 

1 1 1 −1
[ ]
−4/5 −7/10
[5]
1/5 3/10

[6] (a) Eigenvalues 1, −1 and 2 with the corresponding eigenvectors,


     
1 1 5
     
 0 ,  1  and  1 , respectively.
     
0 0 1
Lecture Notes – MATH2118 Further Engineering Mathematics C 27

(b) Eigenvalues −1, −1 and 8 with the corresponding eigenvectors,


     
1 1 2
     
 0 ,  −2  and  1 , respectively.
     
−1 0 2
MATH2118 Lecture Notes
Further Engineering Mathematics C

Vector Calculus

Dr Eddie Ly

School of Mathematical & Geospatial Sciences (SMGS)


College of Sciences, Engineering & Health (SEH)
RMIT University, Melbourne, Australia

Summer Course 2015

1
2 Vector Calculus

Contents
1 Introduction 3

2 Gradient and Gradient Operator 3

2.1 Directional Derivative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

3 Vector Fields 7

3.1 Divergence of a Vector Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

3.2 Divergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

3.3 Physical Interpretation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

4 Curl of a Vector Field 13

4.1 Physical Interpretation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

5 Identities Involving Divergence and Curl 16

6 Scalar Potential 18

6.1 Existence of a Scalar Potential . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

6.2 Finding the Scalar Potential . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

6.3 Laplace’s Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

6.4 Physical Interpretation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

7 Review Questions 24

8 Answers to Review Questions 27


Lecture Notes – MATH2118 Further Engineering Mathematics C 3

1 Introduction

Physical quantities such as temperature, pressure, density, electric field and magnetic field
are functions of position in that they vary throughout space (and time). A scalar function
defined throughout some region is called a scalar field, while a vector function defined
throughout some region is called a vector field.

2 Gradient and Gradient Operator

The gradient of a scalar function ϕ(x, y, z) is defined by

∂ϕ ∂ϕ ∂ϕ
grad ϕ = ∇ϕ = i+ j+ k,
∂x ∂y ∂z

where i, j and k are unit vectors in the x, y and z-direction, respectively. Note that
∇ϕ, which is often written as grad ϕ, is a vector function, and ∂
, ∂
∂x ∂y
and ∂
∂z
are partial
derivative operators with respect to the variable x, y and z, respectively. For example, if
∂f
f (x, y, z) = x2 yz, then ∂x
= fx = (2x)yz; that is, differentiating function f with respect
to x only while keeping all other variables fixed.

EXAMPLE
If ϕ(x, y, z) = x2 + 3xyz − y 2 , determine ∇ϕ at the point P (1, −2, 5).
solution
Gradient of the scalar function ϕ(x, y, z),

∂ϕ ∂ϕ ∂ϕ
∇ϕ = i+ j+ k
∂x ∂y ∂z
= (2x + 3yz)i + (3xz − 2y)j + 3xyk.

Thus, at the point P (1, −2, 5), we have



∇ϕ P = −28i + 19j − 6k.
4 Vector Calculus

EXAMPLE
Determine

(1) ∇r3 ,
(2) ∇(1/r) and
(3) ∇ ln r.

solution

Note that r = r(x, y, z) = xi + yj + zk and r = |r| = x2 + y 2 + z 2 .

(1) Firstly, we compute


( ) ∂ ( 3) ∂ ( 3) ∂ ( 3)
∇ r3 = r i+ r j+ r k.
∂x ∂y ∂z
Utilising the chain rule, we obtain for the first term on the right side of the
above expression,
∂ ( 3) ∂ ( 3 ) ∂r
r = r
∂x ∂r ∂x
∂r
= 3r2 .
∂x
Since r2 = x2 + y 2 + z 2 , we have upon differentiating both sides (partially) with
respect to the variable x (keeping both variables y and z fixed),
∂ ( 2) ∂ ( 2 )
r = x + y2 + z2
∂x ∂x
∂r
⇒ 2r = 2x
∂x
∂r x
⇒ = .
∂x r

Alternatively, since r = x2 + y 2 + z 2 , it follows that
∂r ∂ ( 2 )1/2
= x + y2 + z2
∂x ∂x
1( )−1/2 ∂ ( 2 )
= x2 + y 2 + z 2 x
2 ∂x
2x
= √
2 x + y2 + z2
2

x
= .
r
∂r y ∂r z
Similarly, = and = . Thus,
∂y r ∂z r
( ) ∂ ( 3) ∂ ( 3) ∂ ( 3)
∇ r3 = r i+ r j+ r k
∂x ∂y ∂z
∂r ∂r ∂r
= 3r2 i + 3r2 j + 3r2 k
∂x ∂y ∂z
Lecture Notes – MATH2118 Further Engineering Mathematics C 5

x y z
= 3r2 i + 3r2 j + 3r2 k
r r r
( )
xi + yj + zk
= 3r2
r
r
= 3r2
r
= 3rr
= 3|r|r since r = |r|.

(2) Using the method similar for Question (1), we obtain

∂ ∂ ∂
∇(1/r) = (1/r)i + (1/r)j + (1/r)k
∂x ∂y ∂z
( ) ( ) ( )
∂ 1 ∂r ∂ 1 ∂r ∂ 1 ∂r
= i+ j+ k
∂r r ∂x ∂r r ∂y ∂r r ∂z
1x 1y 1z
=− i − j − k
r2 r r2 r r2 r
−(xi + yj + zk)
=
r3
r
=− 3
r
1 r
=− 2
r r

= − 2,
|r|
r
where r̂ = is an unit vector of r.
|r|
(3) Applying the chain rule provides

∂ ( ) ∂ ( ) ∂ ( )
∇(ln r) = ln r i + ln r j + ln r k
∂x ∂y ∂z
( ) ( ) ( )
∂ ∂r ∂ ∂r ∂ ∂r
= ln r i+ ln r j+ ln r k
∂r ∂x ∂r ∂y ∂r ∂z
1 x 1 y 1 z
= · i+ · j+ · k
r r r r r r
xi + yj + zk
=
r2
r 1
= ·
r r

= .
|r|
6 Vector Calculus

2.1 Directional Derivative

If ϕ(x, y, z) is a scalar function, then


= ∇ϕ · û
du

is the directional derivative of ϕ(x, y, z) in the direction specified by the vector u. If θ is


the angle between ∇ϕ and u, we have

= ∇ϕ · û
du

= ∇ϕ û cos θ

= ∇ϕ cos θ since û = 1.

In the above expressions, û is an unit vector of u and the operator “ · ” represents the
dot product operation. Since the maximum value of cos θ is one, and occurs when θ = 0,
we can conclude that


• At any given point, ∇ϕ is the maximum directional derivative ;

• At any given point, the directional derivative is greatest in the direction of ∇ϕ


(since θ = 0).

EXAMPLE
If the temperature of a body at the point (x, y, z) is

T (x, y, z) = 120 − x2 + 3xyz − y 2 + 4y,

determine the direction in which the temperature increases most rapidly at the point
P (1, 2, 1).
solution
The temperature increases most rapidly in the direction of ∇T . Now,
∂T ∂T ∂T
∇T = i+ j+ k
∂x ∂y ∂z

= (−2x + 3yz)i + (3xz − 2y + 4)j + 3xyk,



⇒ ∇T P = (4, 3, 6).
Lecture Notes – MATH2118 Further Engineering Mathematics C 7

3 Vector Fields

A general vector function has the form

v(x, y, z) = v1 (x, y, z)i + v2 (x, y, z)j + v3 (x, y, z)k.

If v(x, y, z) is defined at each point of a region R, then v is said to form a vector field
over R. Some examples of vector field are

• motion of a wind or fluid, since a vector (both speed and direction) can be assigned
at each point representing the velocity of a particle at the point;

• electric intensity and magnetic intensity are vector functions, which depend on time
as well as position;

• laminar flow of blood in an artery, where cylindrical layers of blood flow faster near
the centre of the artery.

3.1 Divergence of a Vector Field

Recalling that the gradient of a scalar function ϕ is defined by


∂ϕ ∂ϕ ∂ϕ
∇ϕ = i+ j+ k.
∂x ∂y ∂z
dy d d
Note that the ordinary derivative can be written as (y), where is the ordinary
dx dx dx
derivative operator. In a similar way, ∇ϕ can be interpreted as
( )
∂ ∂ ∂
∇ϕ = i +j +k ϕ.
∂x ∂y ∂z
| {z }
=∇

Here ∇ is called the gradient operator (or del operator),

∂ ∂ ∂
∇=i +j +k
∂x ∂y ∂z

and it behaves both like a “vector” and a “differential operator”.


8 Vector Calculus

3.2 Divergence

The dot (scalar) product of the gradient operator ∇ and a vector function F is called the
divergence of F (or div F ). To be specific, if

F (x, y, z) = F1 (x, y, z)i + F2 (x, y, z)j + F3 (x, y, z)k,

then the divergence of F is defined by

div F = ∇ · F
( )
∂ ∂ ∂ ( )
= i +j +k · F1 i + F2 j + F3 k
∂x ∂y ∂z
∂F1 ∂F2 ∂F3
= + + .
∂x ∂y ∂z
Note that div F produces a scalar function as a result.

EXAMPLE
Determine the divergence of
( )
(1) F = e3x yzi + x sin yj + z 2 + 5 k ;
(2) F = yzi + xzj + xyk ;
xi + yj
(3) F = 2 .
x + y2

solution

(1) Using div F = ∇ · F gives

div F = ∇ · F
( ) (
∂ ∂ ∂ ( ) )
= i +j +k · e3x yzi + x sin yj + z 2 + 5 k
∂x ∂y ∂z
∂ ( 3x ) ∂ ( ) ∂ ( 2 )
= e yz + x sin y + z +5
∂x ∂y ∂z
= 3e3x yz + x cos y + 2z.
Lecture Notes – MATH2118 Further Engineering Mathematics C 9

(2) For F = yzi + xzj + xyk, we have

div F = ∇ · F
( )
∂ ∂ ∂ ( )
= i +j +k · yzi + xzj + xyk
∂x ∂y ∂z
∂ ∂ ∂
= (yz) + (xz) + (xy)
∂x ∂y ∂z
=0+0+0
= 0.

The vector function F = yzi + xzj + xyk is said to be solenoidal, because it


has the property that div F = 0.
(3) Here, F represents the effect of a point source located at the origin in fluid
mechanics,

div F = ∇ · F
( ) ( )
∂ ∂ ∂ x y
= i +j +k · 2 i+ 2 j + 0k
∂x ∂y ∂z x + y2 x + y2
( ) ( )
∂ x ∂ y
= +
∂x x2 + y 2 ∂y x2 + y 2
( ) ( )
(1) x2 + y 2 − x(2x) (1) x2 + y 2 − y(2y)
= +
(x2 + y 2 )2 (x2 + y 2 )2
( 2 ) ( )
y − x2 + x2 − y 2
=
(x2 + y 2 )2
= 0 provided (x, y) ̸= (0, 0).

This F is also solenoidal, except at the origin.

EXAMPLE
Determine the divergence of F = r2 r.
solution

Let r = xi + yj + zk, then r = |r| = x2 + y 2 + z 2 . Then,

div F = ∇ · F
( )
= ∇ · r2 r
( )
∂ ∂ ∂ ( )
= i +j +k · xr2 i + yr2 j + zr2 k
∂x ∂y ∂z
∂ (( 2 2 2
)) ∂ (( 2 2 2
)) ∂ (( 2 2 2
))
= x x +y +z + y x +y +z + z x +y +z
∂x ∂y ∂z
10 Vector Calculus

( ) ( ) ( )
= x2 + y 2 + z 2 + x(2x) + x2 + y 2 + z 2 + y(2y) + x2 + y 2 + z 2 + z(2z)
( ) ( )
= 3 x2 + y 2 + z 2 + 2 x2 + y 2 + z 2
( )
= 5 x2 + y 2 + z 2
= 5r2
= 5r · r

Alternatively, we can find divergence of F = r2 r by first writing F as

F = r2 xi + r2 yj + r2 zk.

Divergence of F :
( )
∂ ∂ ∂ ( )
div F = i +j +k · r2 xi + r2 yj + r2 zk
∂x ∂y ∂z
∂ ( 2 ) ∂ ( 2 ) ∂ ( 2 )
= r x + r y + r z .
∂x ∂y ∂z
Appling the product rule to the above relation gives
∂ ( 2 ) ∂ ( 2) ∂
r x =x r + r2 (x)
∂x ∂x ∂x
∂r
= x(2r) + r2 (1)
∂x
x ∂r ∂ √ 2 x
= 2xr + r2 since = x + y2 + z2 =
r ∂x ∂x r
2 2
= 2x + r .

By symmetry, the other terms are


∂ ( 2 ) ∂ ( 2 )
r y = 2y 2 + r2 and r z = 2z 2 + r2 .
∂y ∂z
Hence,
∂ ( 2 ) ∂ ( 2 ) ∂ ( 2 )
div F = r x + r y + r z
∂x ∂y ∂z
( ) ( ) ( )
= 2x2 + r2 + 2y 2 + r2 + 2z 2 + r2
( )
= 2 x2 + y 2 + z 2 + 3r2
= 5r2
= 5r · r.
Lecture Notes – MATH2118 Further Engineering Mathematics C 11

remarks

The last example describes a special case of the “product” rule for the divergence operator.
If ϕ(x, y, z) is a scalar function and

F (x, y, z) = F1 (x, y, z)i + F2 (x, y, z)j + F3 (x, y, z)k

is a general vector function, then

div ϕF = ∇ · ϕF
( )
∂ ∂ ∂ ( )
= i +j +k · ϕF1 i + ϕF2 j + ϕF3 k
∂x ∂y ∂z
∂ ( ) ∂ ( ) ∂ ( )
= ϕF1 + ϕF2 + ϕF3
∂x ∂y ∂z
( ) ( ) ( )
∂F1 ∂ϕ ∂F2 ∂ϕ ∂F3 ∂ϕ
= ϕ + F1 + ϕ + F2 + ϕ + F3
∂x ∂x ∂y ∂y ∂z ∂z
( ) ( )
∂ϕ ∂ϕ ∂ϕ ∂F1 ∂F2 ∂F3
= F1 + F2 + F3 +ϕ + +
∂x ∂y ∂z ∂x ∂y ∂z
| {z } | {z }
= F ·∇ϕ = ϕ∇·F

= F · ∇ϕ + ϕ∇ · F .

For example, in the last example, let ϕ = r2 (scalar function) and F = r. Since the
divergence is a derivative operator, rules of differentiation must be obeyed. Thus,

div ϕF ̸= ϕ div F ,

except when ϕ is constant (since ∇ϕ = 0).

3.3 Physical Interpretation

In the modelling of fluid flow, we let

v = u(x, y, z)i + v(x, y, z)j + w(x, y, z)k

be the steady fluid velocity at any point P (x, y, z). Then, for per unit volume and per
unit time at point P ,

• div v represents the net volume outflow ;

• div (ρv) represents the net mass outflow, where ρ(x, y, z) is the fluid density.

Considering the net mass outflow through a small box of infinitesimal length ∆x, ∆y and
∆z (control volume) containing point P in the x-direction as shown below,
12 Vector Calculus

P
∆z z
y
∆y
x
x − 12 ∆x ∆x x + 12 ∆x

we have

∆Mx ≈ M xOUT − M xIN



≈ ρu x+ ∆x (∆y∆z) − ρu x− ∆x (∆y∆z)
( )
2 2

ρu x+ ∆x − ρu x− ∆x
≈ 2 2
(∆x∆y∆z)
∆x


→ (ρu)(∆x∆y∆z) as ∆x → 0.
∂x
Combining this with the net mass outflow in the y and z-direction, and letting

∆V = ∆x ∆y ∆z,

we have the total mass outflow per unit time,

∆M = ∆Mx + ∆My + ∆Mz


( )
∂ ∂ ∂
→ (ρu) + (ρv) + (ρw) ∆V as (∆x, ∆y, ∆z) → 0.
∂x ∂y ∂z
| {z }
= ∇·(ρv)

Thus, the net mass outflow per unit time, per unit volume at P is represented by
∆M
= ∇ · (ρv)
∆V
= div (ρv).

In steady case, provided there is no net change in mass at P , that is ∆M = 0, conservation


of mass requires that
div (ρv) = 0.
If the fluid is incompressible (ρ is constant), this relation reduces to

div v = 0 ←− v is solenoidal for incompressible fluid!


Lecture Notes – MATH2118 Further Engineering Mathematics C 13

4 Curl of a Vector Field

The cross (vector) product of ∇ and a vector function F is called the curl of F (or
curl F ). If
F (x, y, z) = F1 (x, y, z)i + F2 (x, y, z)j + F3 (x, y, z)k,

then the curl of F is defined by

curl F = ∇ × F


i j k

= ∂x
∂ ∂
∂y

∂z

F1 F2 F3
( ) ( ) ( )
∂F3 ∂F2 ∂F3 ∂F1 ∂F2 ∂F1
= − i− − j+ − k.
∂y ∂z ∂x ∂z ∂x ∂y

Note that curl F produces a vector function as a result.

EXAMPLE
Determine the curl of

(1) F = 2xyi + yz 2 j + x3 zk ;
(2) F = yzi + xzj + xyk ;
(3) F = r2 r.

solution

(1) Giving F = 2xyi + yz 2 j + x3 zk, curl of F is

curl F = ∇ × F


i j k

= ∂x ∂ ∂
∂y

∂z

2xy yz 2 x3 z

∂ ∂ ∂ ∂ ∂ ∂

= i ∂y2 3∂z − j ∂x 3∂z + k ∂x ∂y2
yz x z 2xy x z 2xy yz

= (0 − 2yz)i − (3x2 z − 0)j + (0 − 2x)k


= −2yzi − 3x2 zj − 2xk.
14 Vector Calculus

(2) Giving F = yzi + xzj + xyk, curl of F is

curl F = ∇ × F


i j k

= ∂x
∂ ∂
∂y

∂z

yz xz xy

∂ ∂ ∂ ∂ ∂ ∂

= i ∂y ∂z − j ∂x ∂z + k ∂x ∂y
xz xy yz xy yz xz

= (x − x)i − (y − y)j + (z − z)k


= 0i + 0j + 0k
= 0.

This is a irrotational vector field, since curl of F is a zero vector; that is,
∇ × F = 0.

(3) Giving F = r2 r = r2 xi + r2 yj + r2 zk, curl of F is

curl F = ∇ × F


i j k

= ∂x∂ ∂
∂y

∂z
2
r x r y r2 z
2


∂ ∂ ∂ ∂ ∂ ∂

= i 2∂y 2∂z − j 2∂x 2∂z + k 2∂x 2∂y
r y r z r x r z r x r y

= (2yz − 2zy)i − (2xz − 2zx)j + (2xy − 2yx)k


= 0.

This F is also irrotational.


Lecture Notes – MATH2118 Further Engineering Mathematics C 15

4.1 Physical Interpretation

The curl of a vector function v is related to the amount of rotation associated with v.
Consider a particle P rotating about O in the xy-plane at constant radius a and angular
speed ω (rad/sec) as shown below,

y
O
r
a
P
x

The angular velocity of P is ω = ωk. The position of P is given by

r(t) = a cos(ωt) i + a sin(ωt) j + |{z}


0 k
| {z } | {z }
=x =y =z

from which we obtain the velocity of P as


dr
v(x, y, z) =
dt
= −aω sin(ωt)i + aω cos(ωt)j
= −ωyi + ωxj.

Now, the curl of v is given by

curl v = ∇ × v


i j k


= ∂x∂ ∂ ∂
∂y ∂z

−ωy ωx 0

∂ ∂ ∂ ∂ ∂ ∂
∂y ∂z ∂x ∂y
= i − j ∂x ∂z
+k
ωx 0 −ωy 0 −ωy ωx

= 0i − 0j + (ω + ω)k
= 2ωk
= 2ω.
16 Vector Calculus

The result, curl v = ∇ × v = 2ω indicates that curl v is twice the angular velocity vector.
In general, curl v measures the amount of rotation or vorticity of v. Hence, the term
irrotational is used for vector fields having curl v = 0.

5 Identities Involving Divergence and Curl

Let F (x, y, z) and G(x, y, z) be vector functions, and ϕ(x, y, z) a scalar function. Assum-
ing all of the derivatives implied below exist, we have the following indentities involving
divergence and curl operations,

(1) ∇ · ∇ × F = 0 ;

(2) ∇ × ∇ϕ = 0 ;

(3) ∇ · (F + G) = ∇ · F + ∇ · G ;

(4) ∇ × (F + G) = ∇ × F + ∇ × G ;

(5) ∇ · ϕF = ϕ∇ · F + F · ∇ϕ ;

(6) ∇ × ϕF = ϕ∇ × F + ∇ϕ × F ;

(7) ∇ · (F × G) = G · ∇ × F − F · ∇ × G ;

(8) ∇ × (F × G) = (G · ∇)F − G(∇ · F ) − (F · ∇)G + F (∇ · G) ;

(9) ∇(F · G) = (G · ∇)F + (F · ∇)G + G × (∇ × F ) + F × (∇ × G) ;

(10) ∇ · ∇ϕ = ∇2 ϕ (by definition) ;

(11) ∇ × (∇ × F ) = ∇(∇ · F ) − ∇2 F .

Note that ∇2 = ∇ · ∇ is a scalar operator known as a Laplacian operator,

∇2 = ∇ · ∇
( ) ( )
∂ ∂ ∂ ∂ ∂ ∂
= i+ j+ k · i+ j+ k
∂x ∂y ∂z ∂x ∂y ∂z

∂ ∂ ∂ ∂ ∂ ∂
= + +
∂x ∂x ∂y ∂y ∂z ∂z
∂2 ∂2 ∂2
= + + .
∂x2 ∂y 2 ∂z 2
Lecture Notes – MATH2118 Further Engineering Mathematics C 17

EXAMPLE
Verify Identity (1): ∇ · ∇ × F = 0 (divergence of the curl of a vector function is
always zero).
solution
Let
F (x, y, z) = F1 (x, y, z)i + F2 (x, y, z)j + F3 (x, y, z)k,

then

curl F = ∇ × F


i j k

= ∂x
∂ ∂
∂y

∂z

F1 F2 F3
( ) ( ) ( )
∂F3 ∂F2 ∂F3 ∂F1 ∂F2 ∂F1
=i − −j − +k − ,
∂y ∂z ∂x ∂z ∂x ∂y

⇒ div curl F = ∇ · ∇ × F
( ) ( ) ( )
∂ ∂F3 ∂F2 ∂ ∂F3 ∂F1 ∂ ∂F2 ∂F1
= − − − + −
∂x ∂y ∂z ∂y ∂x ∂z ∂z ∂x ∂y
∂ 2 F3 ∂ 2 F2 ∂ 2 F3 ∂ 2 F1 ∂ 2 F2 ∂ 2 F1
= − − + + −
∂x∂y ∂x∂z ∂y∂x ∂y∂z ∂z∂x ∂z∂y
= 0,

assuming pairs of mixed partial derivatives are equal.

EXAMPLE
Verify Identity (2): ∇ × ∇ϕ = 0 (curl of the gradient of a scalar function is always
zero).
solution
If ϕ(x, y, z) is a scalar function, then
∂ϕ ∂ϕ ∂ϕ
∇ϕ = i+ j+ k,
∂x ∂y ∂z
and

curl ∇ϕ = ∇ × ∇ϕ


i j k

= ∂x
∂ ∂
∂y

∂z
∂ϕ ∂ϕ ∂ϕ
∂x ∂y ∂z

18 Vector Calculus

( ) ( 2 ) ( 2 )
∂ 2ϕ ∂ 2ϕ ∂ ϕ ∂ 2ϕ ∂ ϕ ∂ 2ϕ
=i − −j − +k −
∂y∂z ∂z∂y ∂x∂z ∂z∂x ∂x∂y ∂y∂x
= 0,

assuming pairs of mixed partial derivatives are equal. Thus, if F is the gradient of
a scalar function, F = ∇ϕ, then ∇ × F = 0 (irrotational).

6 Scalar Potential

6.1 Existence of a Scalar Potential

Suppose that F (x, y, z) is a vector function which is continuous in a simply connected


region R in space. Then the following are equivalent (see Identity 2):

• ∇ × F = 0 (irrotational) ;

• F = ∇ϕ for some scalar function ϕ(x, y, z).

That is, if
∇ × F = 0,
then there will exist a scalar potential function ϕ associated with F , and F is said to be
conservative or irrotational in the region R.

If a scalar potential for F exists, it means that the information contained in the three
components of F actually derives from a single scalar function ϕ. This property leads
to significant saving in computational cost for certain problems. For example, potential
flows over an aircraft wing in subsonic, transonic and supersonic speed regime.

6.2 Finding the Scalar Potential

To find the scalar potential associated with F , we must first check that

curl F = ∇ × F = 0,

and then integrate the three equations represented by

∇ϕ = F

to find a consistent solution for ϕ(x, y, z).


Lecture Notes – MATH2118 Further Engineering Mathematics C 19

EXAMPLE
Verify that the vector field
( )
F = (2x + sin y)i + x cos y + z 2 j + 2yzk

is conservative, and find a scalar potential ϕ(x, y, z).


solution
Verifying curl F = 0:


i j k

∇ × F = ∂
∂x

∂y

∂z

2x + sin y x cos y + z 2 2yz

∂ ∂ ∂ ∂ ∂ ∂
∂z ∂z ∂y
= i ∂y
−j ∂x
+k ∂x

x cos y + z 2yz
2 2x + sin y 2yz 2x + sin y x cos y + z 2

= (2z − 2z)i − (0 − 0)j + (cos y − cos y)k


= 0.

Since F is conservative, ϕ(x, y, z) exists. Now, equate ∇ϕ to F :

∂ϕ
= 2x + sin y,
∂x
∂ϕ
= x cos y + z 2 ,
∂y
∂ϕ
= 2yz.
∂z
Integrating the above relations provides

ϕ = x2 + x sin y + f (y, z),


ϕ = x sin y + yz 2 + g(x, z),
ϕ = yz 2 + h(x, y),

where f , g and h are arbitrary functions. A consistent solution for ϕ cannot be


obtained without suitably choosing these functions. Comparing the three equations,
we can see that a consistent solution is

ϕ(x, y, z) = x2 + x sin y + yz 2 + c,

where c is an arbitrary constant.


20 Vector Calculus

EXAMPLE
Verify that the vector field,

F = (y + z)i + (z + x)j + (x + y)k,

is conservative, and find a scalar potential ϕ.


solution
The vector field F is conservative if curl F = 0 :


i j k

∇ × F = ∂
∂x

∂y

∂z

y+z z+x x+y

= (1 − 1)i − (1 − 1)j + (1 − 1)k


= 0.

Equating ∇ϕ to F :
∂ϕ
= y + z,
∂x
∂ϕ
= z + x,
∂y
∂ϕ
= x + y.
∂z
There are two ways of proceeding from here.

method 1:
As usual, we integrate to get

ϕ = xy + xz + f (y, z),
ϕ = yz + xy + g(x, z),
ϕ = xz + yz + h(x, y).

By inspection, a consistent solution is

ϕ(x, y, z) = xy + xz + yz + c,

where c is an arbitrary constant.

method 2:
∂ϕ
Integrating the first equation, ∂x
= y + z, gives

ϕ = xy + xz + f (y, z),
Lecture Notes – MATH2118 Further Engineering Mathematics C 21

where f (y, z) is an arbitrary function not depending on the variable x. That is,
∂f
∂x
= 0. Differentiating this relation with respect to the variable y provides
∂ϕ ∂f
=x+ .
∂y ∂y
Comparing this equation with the second equation yields
∂ϕ ∂f ∂f
=z+x=x+ ⇒z= ,
∂y ∂y ∂y
which means that f (y, z) = yz + g(z). Thus,

ϕ = xy + xz + yz + g(z).

Differentiating this relation with respect to z gives


∂ϕ dg
=x+y+ ,
∂z dz
which on comparison with the third equation yields
∂ϕ dg dg
=x+y+ =x+y ⇒ = 0.
∂z dz dz
That is,
g = c (constant).
Finally, the solution is

ϕ(x, y, z) = xy + xz + yz + c.

6.3 Laplace’s Equation

If F is a vector function which is both irrotational

∇ × F = 0 with F = ∇ϕ,

and solenoidal,
∇ · F = 0,
then the associated scalar potential function ϕ satisfies

∇ · F = ∇ · ∇ϕ
= ∇2 ϕ
∂2ϕ ∂2ϕ ∂2ϕ
= + + 2
∂x2 ∂y 2 ∂z
= 0.

This is the famous Laplace’s equation. Any function ϕ satisfies Laplace’s equation is a
harmonic function.
22 Vector Calculus

EXAMPLE
Find a scalar function f (x, y, z) such that the vector function,

F = (2z + 6xy)i + f (x, y, z)j + (2x − 6yz)k,

is both irrotational and solenoidal. Find a scalar potential ϕ(x, y, z) such that
F = ∇ϕ.
solution
Requiring F to be solenoidal,
∂f ∂f
div F = 6y + − 6y = = 0.
∂y ∂y
Hence, f must be a function of x and z only. Next, requiring F to be irrotational,


i j k

∇ × F = ∂
∂x

∂y

∂z

2z + 6xy f (x, z) 2x − 6yz
( ) ( )
∂f ( ) ∂f
= i −6z − −j 2−2 +k − 6x
∂z ∂x
= 0.
∂f ∂f
Thus, = 6x and = −6z. Integrating these two relations provides
∂x ∂z
f (x, z) = 3x2 + g(z),
f (x, z) = −3z 2 + h(x).

Thus, f = 3x2 − 3z 2 + c0 , where c0 is a constant. For convenience, we can set c0 = 0,


hence
( )
F = (2z + 6xy)i + 3x2 − 3z 2 j + (2x − 6yz)k.
Equating ∇ϕ to F , we have that
∂ϕ
= 2z + 6xy,
∂x
∂ϕ
= 3x2 − 3z 2 ,
∂y
∂ϕ
= 2x − 6yz.
∂z
Therefore,

ϕ = 2xz + 3x2 y + f1 (y, z),


ϕ = 3x2 y − 3yz 2 + f2 (x, z),
ϕ = 2xz − 3yz 2 + f3 (x, y).
Lecture Notes – MATH2118 Further Engineering Mathematics C 23

A consistent solution for ϕ is

ϕ(x, y, z) = 2xz + 3x2 y − 3yz 2 + c,

where c is a constant.

6.4 Physical Interpretation

If F (x, y, z) represents a force field, then the scalar potential ϕ(x, y, z) has the dimensions
of energy, and is related to the potential energy V (x, y, z) by

V = −ϕ.

For example, the force due to gravity acting on a body of mass m near to the earth’s
surface is governed by
F = −mgk.

Since F is constant, it is clear that curl F = 0, so that a scalar potential ϕ exists. Equating
∇ϕ to F , we have
∂ϕ ∂ϕ ∂ϕ
= 0, = 0 and = −mg.
∂x ∂y ∂z
A consistent solution is
ϕ(x, y, z) = −mgz + constant.

Since the gravitational potential energy of such a body is given by V = mgz + c, then
V = −ϕ (up to an additive constant).
24 Vector Calculus

7 Review Questions

[1] (a) Find the divergence and curl of the vector field,
( ) ( )
V (x, y, z) = 2xeyz i + x2 zeyz + 3y 2 z j + y 3 + x2 yeyz k.

(b) Is V solenoidal? Is V irrotational? Would you expect a scalar potential


function ϕ to exist for V ? Briefly explain each of your answers.

[2] (a) Verify that the following vector field,


( )
z3 ( √ )
F (x, y, z) = 2x sin(y + z)i + x cos(y + z) + √ j + x2 cos(y + z) + 6z 2 y k
2
y

is irrotational.
(b) Find a scalar potential function for this field.

[3] (a) Verify that the vector field,


( ) ( ) ( )
y x xy
F (x, y, z) = 2
+x i+ − sin y j + cos z − 2 k,
z z z
is irrotational.
(b) Find a scalar potential function for this field.

[4] The vector field G is defined by


( ) ( ) ( )
G(x, y, z) = 3x2 − 3y 2 i + 12y 2 z − 6xy − 4z 3 j + 4y 3 − 12yz 2 k.

(a) Determine ∇ · G.
(b) Determine ∇ × G.
(c) Is G solenoidal? is G irrotational?

[5] Determine the unit vector which is normal to the surface,



z =5− x2 + y 2 ,

at the point P (4, 3, 0) and is directed away from the origin.

[6] Find the directional derivative of ϕ = z 4 +x2 y 3 at the point (2, −1, 1) in the direction
6i + 2j + 3k.

[7] Consider the vector field F defined by


( ) ( ) ( )
F = 1 + 2xyz 3 i + 2y + x2 z 3 j + αx2 yz 2 k.
Lecture Notes – MATH2118 Further Engineering Mathematics C 25

(a) Determine the value of α for which F is a conservative field.


(b) Assuming α takes the value found in part (a), determine a scalar potential ϕ
for F ; that is, determine a scalar field ϕ such that F = ∇ϕ.

[8] If r = xi + yj + zk, so that |r| = r = x2 + y 2 + z 2 :
∂r
(a) Find , and write the answer in terms of r and x. Hence, write down
∂x
∂r ∂r
and .
∂y ∂z

(b) Using the results obtained in part (a), or otherwise, evaluate div (r/r).

[9] Find a unit normal vector to the paraboloid defined by z(x, y) = 4x2 + y 2 at the
point (2, 3, 25).

[10] The vector field G and the scalar field ϕ are defined by
( ) ( )2 ( )
G = 4zy 2 + 2x − 5 i + 2z 2 − 3x + y j + 3xy + 2z k

and
ϕ(x, y, z) = xz 2 − 4xy 2 ,

respectively. Compute

(a) ∇ · G ;
(b) ∇ × G ;
(c) ∇ϕ ;
(d) curl grad ϕ.

[11] Consider the vector field H defined by


( ) ( )
H = (2 + 2xyz)i + 4 + x2 z j + 2z + x2 y k.

(a) Show that H is a conservative field.


(b) Determine a scalar potential ϕ(x, y, z) for H; that is, determine a scalar field
ϕ such that H = ∇ϕ.
(c) Determine curl (ϕH), where H and ϕ are as above.
Hint: Use the identity,
( )
curl ϕH = ϕ∇ × H + ∇ϕ × H.

[12] If r = xi + yj + zk, so that r = x2 + y 2 + z 2 :
26 Vector Calculus

(a) Show that ∇r4 = 4r2 r ;


(b) Using the identity,
div (ϕF ) = ϕ∇ · F + ∇ϕ · F ,

together with the result from part (a), show that


( )
div r4 r = 7r4 .

[13] A vector field A is said to be a vector potential for a vector field V if

V = ∇ × A.

Verify that the vector field,

A(x, y, z) = x2 y 2 ez i + xyez j + x2 y 3 z 4 k

is a vector potential for the vector field,


( ) ( ) ( )
V (x, y, z) = 3x2 y 2 z 4 − xyez i + x2 y 2 ez − 2xy 3 z 4 j + yez − 2x2 yez k.
Lecture Notes – MATH2118 Further Engineering Mathematics C 27

8 Answers to Review Questions


( )
[1] (a) div V = ∇ · V = 2eyz + x2 z 2 eyz + 6yz + x2 y 2 eyz .
( )
curl V = ∇ × V = 3y 2 + x2 eyz (1 + yz) i.

(b) V is not solenoidal, since div V ̸= 0. V is not irrotational, since curl V ̸= 0.


Since curl V is not zero, a scalar potential function ϕ(x, y, z) will not exist.

[2] (a) curl F : ( )


3z 2 3z 2
∇ × F = −x sin(y + z) + √ + x sin(y + z) − √ i
2 2

( y) ( y )
− 2x cos(y + z) − 2x cos(y + z) j + 2x cos(y + z) − 2x cos(y + z) k
= 0.

(b) ϕ(x, y, z) = x2 sin(y + z) + 2z 3 y + c, where c is a constant.
( ) ( ) ( )
x x y y 1 1
[3] (a) ∇F = − 2 + 2 i − − 2 + 2 j + − k=0
z z z z z z
xy x3
(b) ϕ(x, y, z) = + + cos y + sin z + c, where c is a constant.
z 3
[4] (a) ∇ · G = 0

(b) ∇ × G = 0

(c) G is solenoidal and irrotational.

[5] Let F (x, y, z) = x2 + y 2 − z 2 + 10z − 25. Normal vector is

n = ∇F
= 2xi + 2yj + (10 − 2z)k
= 8i + 6j + 10k at point P.

n 1
Thus, n̂ = = √ (4i + 3j + 5k).
|n| 50
[6] ∇ϕ = 2xy 3 i + 3x2 y 2 j + 4z 3 k = −4i + 12j + 4k at point (2, −1, 1).
Directional derivative is ∇ϕ · û = 12/7.

[7] (a) Curl of F :


( ) ( ) ( )
∇ × F = αx2 z 2 − 3x2 z 2 i − 2αxyz 2 − 6xyz 2 j + 2xz 3 − 2xz 3 k = 0 if α = 3.
∂ϕ ∂ϕ ∂ϕ
(b) = 1 + 2xyz 3 ; = 2y + x2 z 3 ; = 3x2 yz 2 .
∂x ∂y ∂z
Scalar potential function, ϕ(x, y, z) = x + y 2 + x2 yz 3 + c, where c is a constant.
∂r x ∂r y ∂r z
[8] (a) = ; = ; = .
∂x r ∂y r ∂z r
28 Vector Calculus

(b) Divergence of r/r:


( )
xi + yj + zk
div (r/r) = ∇ ·
r
( ) ( ) ( )
∂ x ∂ y ∂ z
= + +
∂x r ∂y r ∂z r
r2 − x2 r2 − y 2 r2 − z 2
= + +
r3 r3 r3
3r2 − r2
=
r3
2
= .
r

[9] Let ϕ = 4x2 + y 2 − z.


Normal vector: n = ∇ϕ = 16i + 6j − k at point (2, 3, 25).
(16, 6, −1)
Unit normal vector: n̂ = ± √ .
293
( )
[10] (a) ∇ · G = 4 + 2 2z 2 − 3x + y
( ) ( ) ( )
(b) ∇ × G = 3x − 16z 3 + 24xz − 8yz i − 3y − 4y 2 j + −12z 2 + 18x − 6y − 8yz k
( ) ( ) ( )
(c) ∇ϕ = z 2 − 4y 2 i + −8xy j + 2xz k
(d) curl grad ϕ = ∇ × ∇ = 0

[11] (a) ∇ × H = 0
∂ϕ ∂ϕ ∂ϕ
(b) = 2 + 2xyz ; = 4 + x2 z ; = 2z + x2 y.
∂x ∂y ∂z
Scalar potential function: ϕ(x, y, z) = 2x + 4y + z 2 + x2 yz + c, where c is a
constant.
( )
(c) curl ϕH = ϕ∇ × H + ∇ϕ × H = ϕ 0 + H × H = 0.

[12] (a) ∇r4 = 4r2 xi + 4r2 yj + 4r2 zk = 4r2 r.


( )
(b) div r4 r = r4 ∇ · r + ∇r4 · r = 3r4 + 4r2 r · r = 7r4 .

[13] Not available.


MATH2118 Lecture Notes
Further Engineering Mathematics C

Ordinary Differential Equations

Dr Eddie Ly

School of Mathematical & Geospatial Sciences (SMGS)


College of Sciences, Engineering & Health (SEH)
RMIT University, Melbourne, Australia

Summer Course 2015

1
2 Ordinary Differential Equations

Contents
1 Introduction 3

2 First-Order Differential Equations 4

2.1 Separable Differential Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

2.2 First-Order Linear Differential Equations . . . . . . . . . . . . . . . . . . . . . . 6

3 Second-Order Differential Equations 9

3.1 Homogeneous Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

3.2 Nonhomogeneous Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

4 Review Questions 19

5 Answers to Review Questions 22


Lecture Notes – MATH2118 Further Engineering Mathematics C 3

1 Introduction

A differential equation is an equation containing the derivatives (or differentials) of one


or more dependent variables, with respect to one or more independent variables.

EXAMPLE

• Current i(t) flowing in a circuit with applied e.m.f. E(t):

di
L + Ri = E(t)
dt

• Angular displacement θ(t) of a rigid body pendulum:

d2 θ
I + mgh · sin θ = 0
dt2

• Mechanical vibrations:
d2 x dx
m 2
+ c + kx = 0
dt dt

Differential equations are classified according to type, order and linearity. If an equation
contains any ordinary derivatives of one or more dependent variables, with respect to a
single independent variable, it is then said to be an ordinary differential equation. The
order of the highest derivative in a differential equations is called the order of the equation.

A differential equation is said to be linear if it has the form

dn y dn−1 y dy
an (x) n
+ an−1 (x) n−1
+ · · · + a1 (x) + a0 (x)y = g(x).
dx dx dx

Note the power of each term involving y is one, and each coefficient an depends only on
the independent variable x. An equation that is not linear is said to be nonlinear.

EXAMPLE

(1) x dy + y dx = 0 ←− first-order, linear


(2) y ′′ − 2y ′ + y = 0 ←− second-order, linear
(3) yy ′′ − 2y ′ = x ←− second-order, nonlinear
d3 y
(4) + y2 = 0 ←− third-order, nonlinear
dx3
4 Ordinary Differential Equations

2 First-Order Differential Equations

The most general first-order differential equation has the form


( )
f x, y, y ′ = 0.

Two common classes of such equations are

• Separable type:
dy
= F (x) · G(y)
dx
• First-order linear type:
dy
+ p(x)y = q(x)
dx

2.1 Separable Differential Equations


dy
The differential = f (x, y) is said to be separable if the right-hand-side terms can be
dx
written as a product of two factors:
dy
= f (x, y) = F (x) · G(y)
dx
dy
⇒ = F (x) dx provided G(y) ̸= 0
G(y)
∫ ∫
dy
⇒ = F (x) dx
G(y)
Here F (x) contains x only, and G(y) contains y only.

EXAMPLE
Solve yy ′ = x.
solution
dy x
= provided y ̸= 0
dx y
⇒ y dy = x dx

Integrating both sides:


∫ ∫
y dy = x dx

1 2 1 2
⇒ y = x + c0
2 2
⇒ y = x2 + c
2
(putting c = 2c0 )
Lecture Notes – MATH2118 Further Engineering Mathematics C 5

This is the general solution, since c is an arbitrary constant.


note:

∗ first-order ode produces 1 arbitrary constant

∗ second-order ode produces 2 arbitrary constants

∗ nth -order ode produces n arbitrary constants

EXAMPLE
Solve y ′ + 2y = 4 subject to y(0) = 0.
solution
dy
= 4 − 2y
dx
∫ ∫
dy
⇒ = dx
4 − 2y
1
⇒ − ln|4 − 2y| = x + c
2
⇒ ln|4 − 2y| = −2(x + c)
⇒ 4 − 2y = e−2(x+c) since e−(x+c) > 0
1
⇒ y = 2 − e−2(x+c)
2
1
= 2 + Ae−2x with A = − e−2c
2
Applying the condition y(0) = 0:

0 = 2 + Ae0 ⇒ A = −2

Thus, the particular solution is


( )
y(x) = 2 1 − e−2x .

EXAMPLE
The mass M of a radioactive substance is initially 10 g, and 20 years later its mass
is 9.6 g. Given that the rate of decay of a radioactive substance is proportional to
the mass of that substance present at any time t, in how many years will the mass
be halved (half-life) ?
Governing equation:
−dM
∝M (M in grams and t in years)
dt
dM
⇒ = −kM where k is a proportionality constant.
dt
6 Ordinary Differential Equations

Separating the variables and integrating both sides:


∫ ∫
dM
= −k dt
M

⇒ ln|M | = −kt + c
⇒ M (t) = e−kt+c
= Ae−kt where A = ec = constant.

Two constants (A, k) require two known conditions:

when t = 0, M = 10: 10 = Ae0 = A


⇒ M = 10e−kt
when t = 20, M = 9.6: 9.6 = 10e−20k
⇒ ln 0.96 = −20k
⇒ −k = 0.05 ln 0.96
⇒ M (t) = 10e0.05t ln 0.96
when M = 5, t = ?: 5 = 10e0.05t ln 0.96
⇒ ln 0.5 = 0.05t ln 0.96
20 ln 0.5
⇒ t=
ln 0.96
≈ 340 years.

2.2 First-Order Linear Differential Equations

General form of n-order linear differential equation:


dn y dn−1 y dy
an (x) n
+ an−1 (x) n−1
+ · · · + a1 (x) + a0 (x)y = g(x).
dx dx dx
When n = 1, we obtain the first-order linear differential equation:

dy
a1 (x) + a0 (x)y = g(x).
dx
Rewriting this equation as
dy a0 (x) g(x)
+ y= provided a1 (x) ̸= 0
dx a1 (x) a (x)
| {z } | 1{z }
= p(x) = q(x)
dy
⇒ + p(x)y = q(x) ←− linear in both y & y ′ , coefficient of y ′ is 1. (1)
dx
Lecture Notes – MATH2118 Further Engineering Mathematics C 7

To solve this differential equation, we multiply both sides of (1) by some function I(x),
such that the left-hand-side term becomes an exact derivative,
dy
I(x) + I(x)p(x)y = I(x)q(x), (2)
dx
and
d( ) dy dI
Iy = I +y . (3)
dx dx dx
We want the left-hand-side of (2) same as the left-hand-side of (3):
d( ) dy dI dy
Iy = I +y =I + Ipy
dx dx dx dx
dI
⇒ = Ip
dx
dI
⇒ = p dx
I
Thus,
∫ ∫
dI
= p(x) dx
I(x)



⇒ ln I(x) = p(x) dx

⇒ I(x) = e p(x) dx
∫ ∫
⇒ I(x) = e p(x) dx
since e p(x) dx
> 0 for all x (4)
= integrating factor

With I(x) given by (4), Equation (1) can then be solved as


d[ ]
I(x)y(x) = I(x)q(x)
dx

1
⇒ y(x) = I(x)q(x) dx ←− coefficient of y ′ is 1
I(x)

EXAMPLE
Solve xy ′ − 4y = x6 ex .
solution
Rewrite this equation such that the coefficient of y ′ is 1:
dy 4
− y = x5 ex ←− p(x) = −4/x, q(x) = x5 ex
dx x
Integrating factor I(x):

p(x) dx
I(x) = e

= e−
4
x
dx
8 Ordinary Differential Equations

= e−4 ln|x|
−4
= eln|x|
1
= 4 provided x ̸= 0.
x
d
Thus, (Iy) = Iq becomes
dx
( )
d y x5 ex
=
dx x4 x4
= xex

y
⇒ 4
= xex dx
x

⇒ y = x xex dx
4

Applying integration by parts method to the above integral by letting u = x,


du = dx, dv = ex dx and v = ex , we obtain
∫ ∫
xe dx = uv − v du
x


= xe − ex dx
x

= xex − ex + c.

General solution:
( )
y(x) = x4 xex − ex + c
= x4 (x − 1)ex + cx4 .

EXAMPLE
Salt solution containing 2 g/lt of salt flows into a tank initially filled with 50 lt
of water containing 10 g of salt. If the solution enters the tank at 5 lt/min, the
concentration is kept uniform by stirring, and the mixture flows out at the same
rate, find the amount of salt in the tank after 10 mins.
solution
Suppose there are Q g of salt in the tank after t mins. Since 5 lt of salt solution
enter and leave the tank each minute, the tank will contain 50 lt of solution at any
Q
time t. Therefore, the solution concentration will be 50
g/lt, and since it flows out
at 5 lt/min, the rate of outflow is Q
50
×5 = Q
10
g/min, while the inflow rate is 2 g/lt
× 5 lt/min = 10 g/min.
Lecture Notes – MATH2118 Further Engineering Mathematics C 9

Rate of increase of Q(t):


dQ
= inflow rate − outflow rate
dt
Q
= 10 −
10
dQ Q
⇒ + = 10
dt 10
Solve for Q(t):
∫ 1
I = e 10 dt = et/10
d ( t/10 )
⇒ e Q = 10et/10
dt ∫
⇒ et/10 Q = 10 et/10 dt

= 100et/10 + c
⇒ Q = 100 + ce−t/10

When t = 0, Q = 10 g:

10 = 100 + ce0 ⇒ c = −90.

Thus,
Q(t) = 100 − 90e−t/10 .
After 10 mins (t = 10):

Q(t = 10) = 100 − 90e−10/10


= 100 − 90/e
≈ 66.9 g of salt.

3 Second-Order Differential Equations

A nth -order linear differential equation,


dn y dn−1 y dy
an (x) + a n−1 (x) + · · · + a1 (x) + a0 (x)y = g(x)
dxn dxn−1 dx
is said to be nonhomogeneous if g(x) ̸= 0 for some x values. If g(x) = 0 for every x,
then the differential equation is said to be homogeneous. We only concerned with finding
solutions of second-order linear differential equation with real constant coefficients,
d2 y dy
a + b + cy = g(x)
dx2 dx
where a, b, c are real constants.
10 Ordinary Differential Equations

3.1 Homogeneous Equation

Homogeneous equation:
d2 y dy
a 2
+ b + cy = 0
dx dx

Let y1 (x) and y2 (x) be solutions of this equation. According to the superposition principle,
the linear combination,
y(x) = C1 y1 (x) + C2 y2 (x),

where C1 and C2 are arbitrary constants, is also a solution of such homogeneous equation.

All solutions are either exponential functions, or are constructed out of exponential func-
tions. If we try a solution of the form

y(x) = emx

where m is a constant, then y ′ = memx , y ′′ = m2 emx :

am2 emx + bmemx + cemx = 0


⇒ am2 + bm + c = 0 since emx ̸= 0 ←− characteristic equation

−b ± b2 − 4ac
⇒ m=
2a

Three cases to be considered (C1 , C2 , C3 , C4 are constants):

• b2 − 4ac > 0 ;

Characteristic equation has two distinct real roots m1 and m2 giving

y(x) = C1 em1 x + C2 em2 x

• b2 − 4ac < 0 ;

Characteristic equation has complex conjugate roots m1 , m2 = α ± iβ where



i = −1, giving
y(x) = C3 e(α+iβ)x + C4 e(α−iβ)x

Utilising the Euler’s formula,

e±iθ = cos θ ± i sin θ,


Lecture Notes – MATH2118 Further Engineering Mathematics C 11

solution y(x) can be expressed as


[ ]
αx iβx −iβx
y(x) = e C3 e + C4 e
[ ( ) ( )]
= eαx C3 cos(βx) + i sin(βx) + C4 cos βx − i sin βx
[ ]
= eαx (C3 + C4 ) cos(βx) + i(C3 − C4 ) sin(βx)
| {z } | {z }
= C1 = C2
[ ]
= eαx C1 cos βx + C2 sin βx

• b2 − 4ac = 0 ;
b
Characteristic equation has two equal real roots m1 = m2 = − giving
2a

y(x) = (C1 x + C2 )em1 x

EXAMPLE
Solve 2y ′′ − 5y ′ − 3y = 0.
solution
Solve for the characteristic equation:

2m2 − 5m − 3 = 0
⇒ (2m + 1)(m − 3) = 0
⇒ m = −1/2, 3

General solution:
y(x) = C1 e−x/2 + C2 e3x .

EXAMPLE
Solve y ′′ − 10y ′ + 25y = 0.
solution
From the characteristic equation:

m2 − 10m + 25 = (m − 5)2 = 0 ⇒ m1 = m2 = 5,

we have repeated roots, thus the general solution is

y(x) = (C1 x + C2 )e5x .


12 Ordinary Differential Equations

EXAMPLE
Solve y ′′ + y ′ + y = 0.
solution
Characteristic equation:

m2 + m + 1 = 0

−1 ± 1 − 4(1)(1)
⇒ m=
√2
−1 ± i 3
=
2
= α ± iβ.

1 3
Identifying α = − and β = , the general solution is
2 2
[ (√ ) ( √ )]
−x/2
y(x) = e C1 cos 2 x + C2 sin 23 x .
3

EXAMPLE
Solve y ′′ − 4y ′ + 13y = 0, subject to y(0) = −1 and y ′ (0) = 2.
solution
Characteristic equation:

m2 − 4m + 13 = 0

4± 16 − 52
⇒ m=
2
4 ± 6i
=
2
= 2 ± 3i

General solution: [ ]
y(x) = e2x C1 cos(3x) + C2 sin(3x)
The condition y(0) = −1 implies that

−1 = e0 (C1 · 1 + C2 · 0)
= C1
[ ]
⇒ y(x) = e2x C2 sin(3x) − cos(3x)

Differentiating this equation with respect to x, and using y ′ (0) = 2 gives


dy [ ] [ ]
= e 3C2 cos(3x) + 3 sin(3x) + 2e C2 sin(3x) − cos(3x)
2x 2x
dx
⇒ 2 = e0 (3C2 + 0) + 2e0 (0 − 1)
= 3C2 − 2
Lecture Notes – MATH2118 Further Engineering Mathematics C 13

⇒ C2 = 4/3

Particular solution: [ ]
4
y(x) = e 2x
sin(3x) − cos(3x) .
3

3.2 Nonhomogeneous Equation

Any function yp (x), free of arbitrary parameters, that satisfies

d2 y dy
a 2
+ b + cy = g(x),
dx dx
where a, b, c are constants, and g(x) is continuous is said to be a particular integral of
the equation.

We solve the nonhomogeneous equation in three steps:

(1) Solve the associated homogeneous equation to get the complementary function,
denoted by yC (x),
d2 yC dyC
a 2
+b + cyC = 0.
dx dx
(2) Find the particular integral, yP (x), of the nonhomogeneous equation.

(3) Add yC (x) and yP (x) to form the general solution of the nonhomogeneous equation,

y(x) = yC (x) + yP (x).

When g(x) consists of

(i) a constant k,

(ii) a polynomial in x,

(iii) an exponential function eαx ,

(iv) trigonometric functions sin(βx) and cos(βx),

or finite sums and products of these functions, it is usually possible to find yP (x) by the
method of undetermined coefficients. Other techniques, such as variation of parameters,
are available for more general g(x).
14 Ordinary Differential Equations

EXAMPLE
Solve y ′′ + 8y ′ = 24.
solution
Solving yC′′ + 8yC′ = 0 for the complementary function:

m2 + 8m = m(m + 8) = 0 ←− characteristic equation


⇒ m = 0, −8
⇒ yC = C1 e0·x + C2 e−8x
= C1 + C2 e−8x

Solving yP′′ + 8yP′ = 24 for the particular integral:

Try yP = A (constant),
yP′ = 0,
yP′′ = 0,
⇒ yP′′ + 8yP′ = 0 + 0 = 24 −→ No solution!

Since there is a constant in yC , namely C1 , and there is also a constant term (A) in
the proposed yP , this will not work! Instead, multiple yP by x, and try again,

Try yP = Ax,
yP′ = A,
yP′′ = 0,
⇒ yP′′ + 8yP′ = 0 + 8A = 24
⇒ A=3
⇒ yP = 3x.

General solution:

y(x) = yC + yP
= C1 + C2 e−8x + 3x

check:

y = C1 + C2 e−8x + 3x,
y ′ = −8C2 e−8x + 3,
y ′′ = 64C2 e−8x ,
( )
⇒ y ′′ + 8y ′ = 64C2 e−8x + 8 −8C2 e−8x + 3
= 64C2 e−8x − 64C2 e−8x + 24
Lecture Notes – MATH2118 Further Engineering Mathematics C 15

= 24
= g(x) as required!

Note that if yp = Ax fail to work, try yP = Ax2 (multiply yP by x again).


Repeat this step until you can solve for yP .

EXAMPLE
Determine the solution of y ′′ − 2y ′ − 3y = 8e3x , subject to y(0) = y ′ (0) = 0.
solution
Characteristic equation:

m2 − 2m − 3 = 0
⇒ (m − 3)(m + 1) = 0
⇒ m = −1, 3.

Complementary function:
yC = C1 e−x + C2 e3x .

Particular integral:

Try yP = Ae3x ←− This will not work!


Try yP = Axe3x ,
yP′ = Ae3x + 3Axe3x
= A(1 + 3x)e3x ,
yP′′ = A(3)e3x + 3A(1 + 3x)e3x
= A(6 + 9x)e3x ,
⇒ yP′′ − 2yP′ − 3yP = A(6 + 9x)e3x − 2A(1 + 3x)e3x − 3Axe3x
= A(6 + 9x − 2 − 6x − 3x)e3x
= 4Ae3x .

Equating 4Ae3x = 8e3x yields A = 2. Hence, yP (x) = 2xe3x .


General solution:

y(x) = C1 e−x + C2 e3x + 2xe3x


= C1 e−x + (C2 + 2x)e3x .

Also,

y ′ (x) = −C1 e−x + 2e3x + 3(C2 + 2x)e3x


16 Ordinary Differential Equations

= −C1 e−x + (2 + 6x + 3C2 )e3x .

Applying condition, x = 0, y = 0:

0 = C1 + C2 ⇒ C2 = −C1 .

Applying condition, x = 0, y ′ = 0:
1 1
0 = −C1 + (2 + 3C2 ) = 2 + 4C2 ⇒ C2 = − , C1 = −C2 = .
2 2
Particular solution:
1 1( )
y(x) = e−x + 4x − 1 e3x .
2 2

EXAMPLE
Solve y ′′ − 2y ′ − 3y = sin x.
solution
Complementary function (from previous example):

yC = C1 e−x + C2 e3x .

Particular integral:

Try yP = A sin x ←− This will not work!


Try yP = A cos x ←− This will not work either!
Try yP = A sin x + B cos x ←− Need both circular functions to work.
yP′ = A cos x − B sin x,
yP′′ = −A sin x − B cos x,
⇒ yP′′ − 2yP′ − 3yP = −A sin x − B cos x − 2(A cos x − B sin x) − 3(A sin x + B cos x)
= (−4A + 2B) sin x + (−2A − 4B) cos x
= sin x.

This requires

−4A + 2B = 1 ⇒B= 1
2
+ 2A
−2A − 4B = 0 ⇒ 2A = −4B = −2 − 8A ⇒ 10A = −2

Hence, A = −1/5 and B = 1/10.


General solution:
1 1
y(x) = C1 e−x + C2 e3x − sin x + cos x.
5 10
Lecture Notes – MATH2118 Further Engineering Mathematics C 17

EXAMPLE
Solve y ′′ + 2y ′ + 2y = −10xex + 5 sin x.
solution
Characteristic equation:

m2 + 2m + 2 = 0

−2 ±
4−8
⇒ m=
2
−2 ± 2i
=
2

= −1 ± i where i = −1.

Complementary function:

yC = e−x (C1 cos x + C2 sin x).

Here
g(x) = −10xex + 5 sin x,
and
g ′ (x) = −10ex − 10xex + 5 cos x,
indicates that the particular integral should take the following form,

yP (x) = Axex + Bex + C sin x + D cos x,

where A, B, C and D are constants. Thence.

yP′ = Aex + Axex + Bex + C cos x − D sin x


= (A + Ax + B)ex + C cos x − D sin x,

yP′′ = Aex + (A + Ax + B)ex − C sin x − D cos x


= (2A + Ax + B)ex − C sin x − D cos x,

⇒ yP′′ + 2yP′ + 2yP = (2A + Ax + B + 2A + 2Ax + 2B + 2Ax + 2B)ex


+ (−C − 2D + 2C) sin x + (−D + 2C + 2D) cos x
= (4A + 5B)ex + 5Axex + (C − 2D) sin x + (2C + D) cos x.

This requires that

5A = −10 ⇒ A = −2,
4A + 5B = 0 ⇒ 5B = −4A = 8 ⇒ B = 8/5,
C − 2D = 5 ⇒ C = 5 + 2D,
2C + D = 0 ⇒ D = −2C = −10 − 4D ⇒ D = −2, C = 1.
18 Ordinary Differential Equations

Particular integral is
8
yP (x) = −2xex + ex + sin x − 2 cos x.
5
General solution is
( )
y(x) = e−x (C1 cos x + C2 sin x) + sin x − 2 cos x + 8/5 − 2x ex .
Lecture Notes – MATH2118 Further Engineering Mathematics C 19

4 Review Questions

[1] Find the general solutions of the following differential equations:


dy
(a) − 2xy = 0 ;
dx
(b) xyy ′ = 1 + x ;
(c) y ′ − 2y = x ;
(d) y ′ cos x − y sin x = sin x.

[2] Determine the solution of y ′ + 2y = 4 with y(0) = 0.


dy x2 + y 2
[3] Find the solution of = by putting y = vx.
dx 2xy
[4] A body is cooling in surroundings maintained at 10◦ C. Its temperature θ◦ C after t
minutes is given by

= −k(θ − 10),
dt
where k is a constant. If the temperature of the body is initially 70◦ C and 10
minutes later is 40◦ C,
1
(a) show that k = 10
log 2 ;
(b) find the body’s temperature after a further 15 minutes.

[5] An e.m.f. E(t) is applied to an electrical circuit containing a resistance R in series


with an inductance L. The current i(t) at time t in the circuit is given by the
solution of
di
L
+ Ri = E(t),
dt
where i(0) = 0. Determine i(t) when E(t) = E0 sin(ωt), where E0 and ω are
constants.

[6] Determine the solution of the differential equation,


dy 2 cos x
+ y= 2 ,
dx x x
which satisfies y(π) = 1.

[7] Determine the general solution of each of the following differential equations:

(a) y ′′ − y ′ − 6y = 0,
(b) y ′′ + 2y ′ + 10y = 0,
(c) y ′′ − 9y = 0,
20 Ordinary Differential Equations

(d) y ′′ − 9y ′ = 0.

[8] Determine the solution of y ′′ − 2y ′ − 3y = 8e3x , subject to y(0) = y ′ (0) = 3.

[9] Determine the general solution of each of the following differential equations:

(a) y ′′ − y ′ − 2y = 4 cosh(2x),
(b) y ′′ + 2y ′ + y = ex cos x,
(c) y ′′ − 3y ′ + 2y = 6xe−x .

[10] A constant e.m.f. E0 volts is applied to a circuit containing, in series, a resistance R


ohms, an inductance L henries and a condenser having capacitance C farads. The
charge q(t) in the condenser (which is initially uncharged) is given by
d2 q dq q
L 2
+ R + = E0 .
dt dt C
If the values of resistance, conductance and capacitance take the values, R = 100,
L = 1/200, C = 10−6 and E0 = 103 , show that
( )
q(t) = 10−3 + e−αt A cos(αt) + B sin(αt) where α = 104 .

[11] A body of unit mass moves along the x-axis under the action of

• a force of magnitude ω 2 x directed towards the origin,


• a driving force governed by e−λt cos(bt),
• a frictional resistance defined by 2λẋ, where ẋ is the speed of the body.

The displacement x(t) at time t is given by

ẍ + 2λẋ + ω 2 x = e−λt cos(bt).

If the body starts from rest at the origin, and ω > λ, obtain x(t) for the following
two cases:

(a) b = ω 2 − λ2 ,

(b) b ̸= ω 2 − λ2 .

[12] The angular displacement θ(t) of a rigid body pendulum oscillating about a fixed
axis is governed by
d2 θ
= −mgh · sin θ,
I
dt2
where m, g, h and I are constants. For small oscillations (that is, when θ is small),
we can use sin θ ≈ θ. Show that for small oscillations, the motion is simple harmonic

in nature with period 2π I/(mgh).
Lecture Notes – MATH2118 Further Engineering Mathematics C 21

[13] An e.m.f. E0 sin(ωt) is applied to an electrical circuit comprising a resistance R, an


inductance L and a capacitance C in series. The current i(t) in the circuit at time
t satisfies the following differential equation,

d2 i di i
L 2
+ R + = E0 ω cos(ωt).
dt dt C
di
If R2 C < 4L, determine i(t) for the case when i(0) = 0 and dt
(0) = 0.

[14] Determine the solution of the differential equation,

dy
− 3y = e5x + e3x cos(2x),
dx
which satisfies y(0) = 0.

[15] (a) Determine the general solution of y ′′ − 4y ′ = 0.


(b) Using the result from (a), determine the general solutions of
(i) y ′′ − 4y ′ = 8e2x ;
(ii) y ′′ − 4y ′ = 3e4x ;
(iii) y ′′ − 4y ′ = −16x .

[16] A model for the growth of a population of size N is governed by

dN
= kN − Q,
dt
where k is the difference between the birth and death rates, and Q is the emigration
rate. Both k and Q are assumed to be positive constants.

(a) Solve this differential equation subject to the initial condition N (0) = N0 .
(b) Show that in the case Q > kN0 , the population crashes (i.e. N = 0) at time
( )
1 Q
t = log .
k Q − kN0
22 Ordinary Differential Equations

5 Answers to Review Questions


2
[1] (a) y(x) = cex
(b) y 2 = 2 log x + 2x + c
(c) y(x) = ae2x − 12 x − 1
4

(d) y(x) = c · sec x − 1

[2] y(x) = 2 − 2e−2x

[3] y 2 = x2 + cx

[4] θ ≈ 20.6◦ C
E0 ( )
−Rt/L
[5] i(t) = 2 2 ωLe + R sin(ωt) − ωL cos(ωt)
ω L + R2
sin x
[6] y(x) = +1
x2
[7] (a) y(x) = ae3x + be−2x
( )
(b) y(x) = e−x a cos(3x) + b sin(3x)
(c) y(x) = ae3x + be−3x
(d) y(x) = a + be9x

[8] y(x) = (2x + 1)e3x + 2e−x

[9] (a) y(x) = ae2x + be−x + 12 e−2x + 23 xe2x


(b) y(x) = (ax + b)e−x + 25
1 x
e (3 cos x + 4 sin x)
( )
(c) y(x) = ae2x + bex + x + 56 e−x

[10] Not available.


t −λt
[11] (a) x(t) = e sin(bt)
2b
e−λt [ (√ )]
(b) x(t) = 2 cos(bt) − cos ω 2 − λ2 t
ω − λ2 − b 2
[12] Not available.

[13] Steady-state solution is


[ ]
E0 ωC 2 1( )
ωR sin(ωt) + 1 − ω LC cos(ωt)
2
(1 − ω 2 LC)2 + (ωRC)2 C

1
[14] y(x) = 2
+ 12 e5x + 12 e3x sin(2x)
Lecture Notes – MATH2118 Further Engineering Mathematics C 23

[15] (a) y(x) = a + be4x


(b) (i) y(x) = a + be4x − 2e2x
( )
(ii) y(x) = a + b + 34 x e4x
(iii) y(x) = a + be4x + 2x2 + x
( )
[16] (a) N (t) = Q/k + N0 − Q/k ekt
(b) Put N = 0 and solves for t, noting that kN0 − Q < 0.
MATH2118 Lecture Notes
Further Engineering Mathematics C

Infinite Series

Dr Eddie Ly

School of Mathematical & Geospatial Sciences (SMGS)


College of Sciences, Engineering & Health (SEH)
RMIT University, Melbourne, Australia

Summer Course 2015

1
2 Infinite Series

Contents
1 Introduction 3

2 Convergent Series 3

2.1 Geometric Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2.2 A Test for Divergent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

3 Positive Term Series 8

3.1 Comparison Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

3.2 Limit Comparison Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

3.3 Ratio Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

4 Alternating Series 15

4.1 Alternating Series Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

4.2 Error in Approximating the Sum of an Alternating Series . . . . . . . . . . . . . 17

4.3 Absolute Convergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

4.4 Conditionally Convergent Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . 19

5 Review Questions 20

6 Answers to Review Questions 23


Lecture Notes – MATH2118 Further Engineering Mathematics C 3

1 Introduction

If {an } is the sequence a1 , a2 , a3 , . . . , an , . . ., then the sum



an = a1 + a2 + a3 + · · · + an + an+1 + · · ·
n=1

∑∞ ∑
is called an infinite series, or simply a series. Often, we can write n=1 an as an ).
The an , n = 1, 2, 3, . . ., are called the terms of the series; an is called the general term.

Associated with every infinite series an , there is a sequence of partial sums {Sn } whose
terms are defined by

S1 = a 1 ,
S2 = a1 +a2 = S1 + a2 ,
|{z}
= S1

S3 = a1 + a2 +a3 = S2 + a3 ,
| {z }
= S2

n
Sn = am
m=1

= a1 + a2 + a3 + · · · + an−1 +an
| {z }
= Sn−1

= Sn−1 + an , and so on.


∑n
The term Sn = m=1 am = a1 + a2 + · · · + an of this sequence is called the nth partial
sum of the series.

2 Convergent Series
∑∞
An infinite series n=1 an is said to be convergent if the sequence of partial sums {Sn }
converges. That is,

n
lim Sn = lim am = L.
n→∞ n→∞
m=1

The number L is the sum of the series. If lim Sn = L does not exist, the series is said to
n→∞
be divergent.
4 Infinite Series

EXAMPLE
∑ 1
Show that the series is convergent.
(n + 4)(n + 5)
solution
Considering the general term of the series:
1
an =
(n + 4)(n + 5)
1 1
= − .
n+4 n+5
The nth partial sum of the series is
[ ] [ ] [ ] [ ]
1 1 1 1 1 1 1 1
Sn = − + − + − +···+ −
5 6 6 7 7 8 n+4 n+5
| {z } | {z } |{z} | {z }
1 1
= − .
5 n+5
Since
( )
1 1
lim Sn = lim −
n→∞ n→∞ 5 n+5
= 1/5
= L,

the series converges, and we write


∑ 1 1
= .
(n + 4)(n + 5) 5

remark:
Because of the manner in which the general term of this sequence of partial sums “col-
lapses” to two terms, this series known as a telescoping series.

EXAMPLE
∑ ( )
Show that the series ln 1 + 1/n is divergent.
solution
Partial sum:
∑n ( )
1
Sn = ln 1 +
m=1
m
∑n ( )
m+1
= ln
m=1
m
∑n ( )
= ln(m + 1) − ln m
m=1
Lecture Notes – MATH2118 Further Engineering Mathematics C 5

( )
= (ln 2 − ln 1) + (ln 3 − ln 2) + (ln 4 − ln 3) + · · · + ln(n) − ln(n − 1)
( )
+ ln(n + 1) − ln n
= − ln 1 + ln(n + 1)
= ln(n + 1) since ln 1 = 0.

As n → ∞, n + 1 → ∞, so Sn = ln(n + 1) → ∞. Hence, lim Sn = L does not exist,


n→∞
and the series diverges.

EXAMPLE
∑ 3
If Sn denotes the nth partial sum of , show that
(3n − 2)(3n + 1)
1
Sn = 1 − .
3n + 1
Deduce that the series converges. What is its sum ?
solution
Partial sum:

n
3
Sn =
m=1
(3m − 2)(3m + 1)
∑n ( )
1 1
= −
3m − 2 3m + 1
(
m=1
) ( ) ( ) ( )
1 1 1 1 1 1 1 1
= − + − + − + − +···
1 4 4 7 7 10 10 13
| {z } | {z } | {z } | {z }
( ) ( )
1 1 1 1
+ − + −
3n − 5 3n − 2 3n − 2 3n + 1
| {z } | {z }
1
=1− .
3n + 1
As n → ∞, Sn → 1 since 1
3n+1
→ 0. Hence, the series converges to the sum of

L = lim Sn = 1.
n→∞
6 Infinite Series

2.1 Geometric Series

A geometric series is a series having the form



arn = a + ar + ar2 + ar3 + · · · + arn−1 + arn + · · ·
n=0

and its sum,


n−1
Sn = arm
m=0

= a + ar + ar2 + + · · · + arn−1
( )
1 − rn
=a if r ̸= 1,
1−r
a
where r is the common ratio. The series converges for |r| < 1 since lim Sn = . Note
n→∞ 1−r
that rn → 0 as n → ∞ for |r| < 1, and diverges for |r| ≥ 1.

EXAMPLE

Determine the nth partial sum of (3/4)n+1 , and determine if the series converges.
solution
Series:
∞ ( )n+1
∑ ( )2 ( )3 ( )4 ( )n
3 3 3 3 3 3
= + + + + ··· + + ··· .
n=0
4 4 4 4 4 4

This is a geometric series with a = 3/4 and r = 3/4 < 1. Thus,


( )
3 1 − (3/4)n
Sn =
4 1 − 3/4
( )
= 3 1 − (3/4)n .

As n → ∞, (3/4)n → 0 (since 3n < 4n ), so

lim Sn = L = 3.
n→∞

The series converges with the sum of 3.


Lecture Notes – MATH2118 Further Engineering Mathematics C 7

2.2 A Test for Divergent

If an is the general terms of a series, and Sn is the corresponding sequence of partial sums,
then an = Sn − Sn−1 (since Sn = Sn−1 + an ).

Now, if the series converges to a number L, we have lim Sn = L, and lim Sn−1 = L.
n→∞ n→∞
This implies that
( )
lim an = lim Sn − Sn−1
n→∞ n→∞

= lim Sn − lim Sn−1


n→∞ n→∞

=L−L
= 0.

That is,


if an converges, then lim an = 0.
n→∞
n=1

On the other hand, if lim an = 0, we cannot deduce that the series an converges. We
n→∞
can at least say that if lim an ̸= 0, then the series must diverge.
n→∞

Test for a divergence series:




If lim an ̸= 0 then an diverges.
n→∞
n=1

EXAMPLE
∑ n
Consider the series . Rewriting the general term of the series as
n−1
n
an =
n−1
(n − 1) + 1
=
n−1
1
=1+ .
n−1
Since
( )
1
lim an = lim 1 +
n→∞ n→∞ n−1
=1
̸= 0,

the series diverges by the nth term test for divergence.


8 Infinite Series

EXAMPLE
∑ 4n − 1
Consider the infinite series .
5n + 3
4n − 1
Here an = . It follows from the test for a divergent series that this series
5n + 3
must diverge, since
4n − 1 4 − 1/n
lim an = lim = lim = 4/5 ̸= 0.
n→∞ n→∞ 5n + 3 n→∞ 5 + 3/n

EXAMPLE
∑ 1
Consider the p-series, . Since
n4
1
lim an = lim
n→∞ n→∞ n4

= 0,

we cannot conclude whether this series converges or diverges by the nth term test
for divergence.

3 Positive Term Series


∑∞
A series of the form an , where every an > 0, is called positive term series. The
n=1

sequence of partial sums, Sn = nm=1 am (all am > 0), is monotonically increasing. That
is, Sn−1 < Sn < Sn+1 for all n.

There are only two possibilities to consider:

(1) Sn increases without bound. That is, Sn → ∞ as n → ∞, and the series must
diverge.

Sn

(2) The partial sums are bounded above by some constant K, such that Sn < K for
all n. Hence, Sn must approach to some limit (≤ K), and the series must converge
(monotonic convergence theorem).
Lecture Notes – MATH2118 Further Engineering Mathematics C 9

Sn
K

3.1 Comparison Test



It is often possible to determine convergence or divergence of a series an by comparing

its terms with the terms of a “test series” bn that is known to be convergent or divergent.
∑ ∑
Suppose an (represents a “smaller series”) and bn (“larger series”) are two positive
term series, such that

0 ≤ a n ≤ bn for all n (or at least for sufficiently large n.)

∑∞ ∑∞
• If n=1 bn converges, then n=1 an converges.
(If the larger series converges, the smaller series must converge).

K X
bn
X
an

∑∞ ∑∞
• If n=1 an diverges, then n=1 bn diverges.
(If the smaller series diverges, the larger series must diverge).

X
bn

X
an

n
10 Infinite Series

Common standard series used for comparison:

• Geometric series:
∑ a
arn converges to if |r| < 1, and diverges if |r| ≥ 1.
1−r
• p-series:
∑ 1 1 1 1
p
= 1 + p + p + ··· + p + ···
n 2 3 n
converges if p > 1, and diverges if p ≤ 1.
∑1
If p = 1, the divergent series is called harmonic series.
n

EXAMPLE
∑ n
Test for convergence of .
n3 +4
solution
We observe that
n n 1
< 3 = 2 since n3 + 4 > n3 for all n.
n3 +4 n n
∑ 1
Because the larger series (p-series, p = 2 > 1) converges, then the smaller
∑ n n2
series must converge by the comparison test.
n3 + 4

EXAMPLE
∑ ln(n + 2)
Test for convergence of .
n
solution
Since ln(n + 2) > 1 for n ≥ 1, we have

ln(n + 2) 1
> .
n n
∑1
Since the smaller series (p-series, n = 1) is a divergent harmonic series, then
n
∑ ln(n + 2)
by the comparison test the larger series must diverge.
n
Lecture Notes – MATH2118 Further Engineering Mathematics C 11

EXAMPLE
∑ 100 + cos(5n)
Consider the series .
n3
solution
Since cos(5n) ≤ 1, we have

100 + cos(5n) ≤ 101


100 + cos(5n) 101
⇒ 3
≤ 3
n n
Since the larger series
∑ 101 ∑ 1
= 101 ,
n3 n3
∑ 100 + cos(5n)
which is a p-series with p = 3 > 1, is a convergent series, then
n3
also converges.

3.2 Limit Comparison Test


∑ ∑
Suppose an and bn are positive term series, and that
an
lim = c.
n→∞ bn

Then,

• if c > 0, then both series either convergent or divergent.


∑ ∑
• if c = 0 and bn converges, then an converges.
∑ ∑
• if c = ∞ and bn diverges, then an diverges.

The limit comparison test is often applicable to series for which the comparison test is
inconvenient.

EXAMPLE
∑ n
Test for convergence of .
(8n5 + 7)1/3
solution
n
For large n values, the general term of this series an = “behaves” like
(8n5 + 7)1/3
n n 1
= = 2/3 .
(n5 )1/3 n 5/3 n
12 Infinite Series

∑ ∑ 1
Let bn = be the test series, we have
n2/3
( )
an n n2/3
lim = lim ×
n→∞ bn n→∞ (8n5 + 7)1/3 1
n5/3
= lim
n→∞ (8n5 + 7)1/3
( )1/3
n5
= lim
n→∞ 8n5 + 7
( )1/3
1
= lim
n→∞ 8 + 75
n
( )1/3
= 1/8
= 1/2.

Here, c = 1/2 > 0, and both series either converge or diverge. Since bn =
∑ 1 ∑ n
is a divergent p-series (p = 2/3 < 1), then must diverge
n2/3 (8n5 + 7)1/3
by the limit comparison test.

∑ n3 + 5n − √n + 2
EXAMPLE

Test for convergence of .


n5 + 5
solution
For large n values, the general term of this series behaves like

n3 + 5n − n + 2 n3 1
5
∼ 5
= 2.
n +5 n n
∑ ∑ 1
Let bn = be the test series (convergent p-series), we have
n2
( 3 √ )
an n + 5n − n + 2 n2
lim = lim ×
n→∞ bn n→∞ n5 + 5 1
n5 + 5n3 − n5/2 + 2n2
= lim
n→∞ n5 + 5
1+ 5
n2
− n5/2
1
+ 2
n3
= lim 5
n→∞ 1 + n5
= 1.
∑ ∑ 1
Here c = 1 > 0, and both series converge or diverge. Since bn = con-

∑ n + 5n − n + 2
3
n2
verges, then the series also converges by the limit comparison
n5 + 5
test.
Lecture Notes – MATH2118 Further Engineering Mathematics C 13

3.3 Ratio Test

Ratio test is useful when an involves factorials and nth powers of a constant or n.

Suppose an is a positive term series, such that

an+1
lim = L.
n→∞ an

Then,

• if L < 1, the series converges;

• if L > 1, the series diverges;

• if L = 1, the ratio test is inconclusive (no indication of whether the series converges
or diverges).

EXAMPLE
∑ 5n
Test for convergence of .
n!
solution
5n
Here an = , then
n!
5n+1
an+1 =
(n + 1)!
5n 5
= ,
(n + 1) n!
( )
an+1 5n 5 n!
⇒ lim = lim × n
n→∞ an n→∞ (n + 1) n! 5
5
= lim
n→∞ n + 1

=0
= L.

Since L = 0 < 1, this series must converge by the ratio test.


14 Infinite Series

EXAMPLE
∑ nn
Test for convergent of .
n!
solution
nn
Here an = . Then,
n!
(n + 1)n+1
an+1 =
(n + 1)!
(n + 1)(n + 1)n
=
(n + 1) n!
(n + 1)n
= ,
n!
( )
an+1 (n + 1)n n!
⇒ lim = lim × n
n→∞ an n→∞ n! n
( n + 1 )n
= lim
n→∞ n
( )n
= lim 1 + 1/n
n→∞

= e.

Since L = e > 1, this series must diverge by the ratio test.

EXAMPLE
∑ 2n
Test for convergence of .
(2n)!
solution
2n
Here an = . Then,
(2n)!
2n+1
an+1 =
(2n + 2)!
2n+1
=
(2n + 2)(2n + 1)(2n)!
2n
= ,
(n + 1)(2n + 1)(2n)!
( )
an+1 2n (2n)!
⇒ lim = lim × n
n→∞ an n→∞ (n + 1)(2n + 1)(2n)! 2
1
= lim
n→∞ (n + 1)(2n + 1)

= 0.

Since L = 0 < 1, this series converges by the ratio test.


Lecture Notes – MATH2118 Further Engineering Mathematics C 15

EXAMPLE
∑ 1
The ratio test will give inconclusive answer when applied to a p-series :
np
an+1 np
lim = lim
n→∞ an n→∞ (n + 1)p
( )p
n
= lim
n→∞ n + 1
( )p
1
= lim 1 −
n→∞ n+1
= 1p
= 1 = L for all p values.

4 Alternating Series

A series having either form,




a1 − a2 + a3 − a4 + · · · + (−1)n+1 an + · · · = (−1)n+1 an ,
n=1


−a1 + a2 − a3 + a4 − · · · + (−1)n an + · · · = (−1)n an ,
n=1

where an > 0 for n = 1, 2, 3, . . ., and the terms are alternately positive and negative, is
said to be an alternating series. For example,


(−1)n+1 1 1 1
=1− + − + ··· ;
n=1
n 2 3 4



ln n ln 2 ln 3 ln 4 ln 5
(−1)n n
= − + − + ··· ;
n=2
2 4 8 16 32



cos(nπ) ∑∞
(−1)n 1 1 1 1
2
= 2
=1− + − + + ··· .
n=0
n +1 n=0
n +1 2 5 10 17

4.1 Alternating Series Test



Consider the series (−1)n+1 an , where each an > 0.

If lim an = 0 and an+1 < an for all n, then the series converges.
n→∞
16 Infinite Series

EXAMPLE
∑ (−1)n+1
Show that the alternating harmonic series converges.
n
solution
1 1
Here an = , and an+1 = . We have
n n+1
1
lim an = lim = 0,
n→∞ n→∞ n

and
1 1
< ⇒ an+1 < an for all n.
n+1 n
Since lim an = 0 and an+1 < an for all n (an is monotonically decreasing to zero),
n→∞
it follows that the alternating harmonic series converges.

EXAMPLE
∑ √
n+1 n
Test for convergence of (−1) .
n+1
solution
√ √
n n+1
Here an = and an+1 = . To show that the terms of the series satisfy
n+1 n+2 √
n
the condition an+1 < an , we let f (n) = an = . From
n+1
( √ )
′ df d n
f (n) = =
dn dn n + 1

√1
2 n
(n + 1) − n (1)
=
(n + 1)2
1
(n + 1) − n
= 2√
n(n + 1)2
1
(1 − n)
= √2
n(n + 1)2
−(n − 1)
= √ ,
2 n(n + 1)2

we can see that f ′ (n) < 0 for n > 1. That is, function f (n) decreases for n > 1.
Thus, an+1 < an is true for n > 1. Also,

n
lim an = lim = 0.
n→∞ n→∞ n + 1

Hence, this series converges by the alternating series test.


Lecture Notes – MATH2118 Further Engineering Mathematics C 17

EXAMPLE
∑ 2n + 1
Consider (−1)n+1 .
3n − 1
solution
Since
2n + 1
lim an = lim
n→∞ n→∞ 3n − 1
2 + n1
= lim
n→∞ 3 − 1
n

= 2/3
̸= 0,

the series diverges by the alternating series test.

4.2 Error in Approximating the Sum of an Alternating Series



Suppose the alternating series (−1)n+1 an , where an > 0, converges to a number L. If
Sn is the nth partial sum of the series, and an+1 < an for all n values, then

L − Sn ≤ an+1 for all n.

The error of the series is less than the absolute value of the (n + 1)th term of the series.

4.3 Absolute Convergence


∑ ∑ ∑
If an is absolutely convergent, that is, if |an | converges, then an converges.
∑ ∑
However, if |an | diverges, we cannot deduce that an diverges.

proof:

If bn = an + |an |, then bn ≤ 2|an |. Since |an | converges, it follows from the comparison
∑ ∑( ) ∑
test that bn must converge. Furthermore, bn − |an | converges, since both bn and
∑ ∑ ∑ ∑( )
|an | converge. Therefore, an converges, since an = bn − |an | .

EXAMPLE
∑ (−1)n+1
The alternating series is absolutely convergent, since
n2

∑ (−1)n+1 ∑ 1

n2 = n2
is a convergent p-series (with p = 2 > 1).
18 Infinite Series

EXAMPLE
∑ (−1)n+1
Test for convergence of .
n2 + 1
solution
The series

∑ ∑ (−1)n+1
|an | =
n2 + 1
∑ 1
=
n2 + 1
∑ 1
is absolutely convergent by the comparison test with the test series (p-series
n2
with p = 2 > 1), since
1 1
2
> 2 for n ≥ 1.
n n +1
Therefore, this series converges by the absolute convergence theorem.

EXAMPLE
∑ 1 + 2 sin(n)
Show that is convergent.
n2
solution
Consider the series:

∑ 1 + 2 sin(n) ∑ |1 + 2 sin(n)|
= (positive term series).
n2 n2

Noting that

1 + 2 sin(n) ≤ 3 since |sin(n)| ≤ 1,

then
1 + 2 sin(n) 3
≤ .
n2 n2
But, the series
∑ 3 ∑ 1
= 3
n2 n2
∑ |1 + 2 sin(n)|
is a convergent p-series (p = 2 > 1), and by the comparison test
n2
∑ 1 + 2 sin(n)
also converges. This implies that is absolutely convergent. Hence,
n2
∑ 1 + 2 sin(n)
converges by the absolute convergence theorem.
n2
Lecture Notes – MATH2118 Further Engineering Mathematics C 19

4.4 Conditionally Convergent Theorem


∑ ∑ ∑
A series an is said to be conditionally convergent if |an | diverges and an converges.

EXAMPLE
∑ (−1)n+1
Consider the alternating harmonic series, .
n
1 1
Let an = . Then, an+1 = , and
n n+1
1 1
< since n + 1 > n for n > 0.
n+1 n
Hence an+1 < an for n > 0. Also,
1
lim an = lim = 0.
n→∞ n→∞ n

Therefore, the series converges by the alternating series test. But,



∑ ∑ (−1)n+1 ∑ 1
|an | = =
n n

is a divergent harmonic series. Hence, this series conditionally converges.


20 Infinite Series

5 Review Questions


3
[1] If Sn denotes the nth partial sum of , show that
m=1
(3m − 2)(3m + 1)

1
Sn = 1 − .
3n + 1
Deduce that the series converges. What is its sum ?


3m − 2
[2] If Sn denotes the nth partial sum of , show that
m=1
m(m + 1)(m + 2)

1 4
Sn = 1 + − .
n+1 n+2
Deduce that the series converges. What is its sum ?

[3] Determine the nth partial sum of each of the following series, and hence determine
whether the series converges:
∑∞
(−1)m+1
(a) ;
m=1
m(m + 2)


( )n+1
(b) 3/4 ;
n=0

(c) 2 − 4/3 + 8/9 − 16/27 + 32/81 + · · · − · · · .




(m + 1)2
[4] For the series log , show that the nth partial sum is
m=1
m(m + 2)

n+1
Sn = log 2 + log .
n+2
Deduce that the series converges. What is its sum ?

[5] Use the comparison test to determine which of the following series converge:
∑ n
(a) ;
100n2 + 1
∑ 1
(b) √ ;
n n3 + 1
∑ m
(c) ;
(m + 2)(m + 1)
∑ k+2
(d) √ ;
k (k + 1)2
∑ 2k + 3
(e) .
k2 + 5
Lecture Notes – MATH2118 Further Engineering Mathematics C 21

[6] Determine which of the following series converge:


∑ n2
(a) ;
2n
∑ 3n
(b) ;
n2
∑ 1
(c) ;
5n
∑ 2n
(d) ;
n!
∑ n 10n
(e) ;
(n + 1)!
∑ n3
(f) ;
5n
∑ (n!)2
(g) .
(2n)!
[7] Determine which of the following series converge:
∑ 1
(a) (−1)n √ ;
n
∑ n
(b) (−1)n ;
3n + 1
∑ (−1)n
(c) ;
n2 + 1
∑ (−1)m
(d) √ .
m3 + 1
[8] Show that the series
∑ sin(nθ) ∑ cos(nθ)
and
n2 n2
are absolutely convergent for all θ.

[9] Determine, with reasons, which of the following series converge:


∑ 1
(a) ;
n(n + 1)
∑ 3n−2
(b) (−1)n ;
4n+1
∑ 2(−1)n
(c) √ ;
4n + 1
∑ 4m2
(d) ;
2m
∑ 1
(e) √ ;
4n3 + log n
∑ en
(f)
n!
22 Infinite Series

∑( 5 )n(n + 2 )
(g) ;
6 n+1
∑ (m + 2)!
(h) ;
m! m2
∑ 3k k!
(i) ;
kk
∑ m
(j) .
2m2
Lecture Notes – MATH2118 Further Engineering Mathematics C 23

6 Answers to Review Questions

[1] lim Sn = 1
n→∞

[2] lim Sn = 1
n→∞
[ ( )]
[3] (a) Sn = 1
2
1
2
+ (−1) n 1
n+2
− 1
n+1
; series converges with a sum of 1/4.
( )
(b) Sn = 3 1 − (3/4) ; series converges with a sum of 3.
n

( )
(c) Sn = 56 1 − (−2/3)n ; series converges with a sum of 6/5.

[4] Series converges with a sum of log 2.

[5] (a) Divergent

(b) Convergent

(c) Divergent

(d) Convergent

(e) Divergent

[6] (a) Convergent

(b) Divergent

(c) Convergent

(d) Convergent

(e) Convergent

(f) Convergent

(g) Convergent

[7] (a) Convergent

(b) Divergent

(c) Convergent

(d) Convergent

[8] Not available.

[9] (a) Convergent; comparison test.

(b) Convergent geometric series (common ratio, r = −3/4).

(c) Convegent; alternating series test.


24 Infinite Series

(d) Convergent; ratio test.


(e) Convergent; comparison test.
(f) Convergent; ratio test.
(g) Convergent; ratio test.
(h) Divergent; test for a divergent series.
(i) Divergent; ratio test.
(j) Convergent; ratio test.
MATH2118 Lecture Notes
Further Engineering Mathematics C

Power Series

Dr Eddie Ly

School of Mathematical & Geospatial Sciences (SMGS)


College of Sciences, Engineering & Health (SEH)
RMIT University, Melbourne, Australia

Summer Course 2015

1
2 Power Series

Contents
1 Introduction 3

2 Interval of Convergence 3

3 Differentiation and Integration of Power Series 7

3.1 Differentiation of a Power Series . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

3.2 Integration of a Power Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

4 Taylor Series 9

4.1 Maclaurin Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

4.2 Taylor’s Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

4.3 Approximation with Taylor Polynomials . . . . . . . . . . . . . . . . . . . . . . . 15

5 Binomial Series 16

6 Manipulation of Power Series 18

6.1 Addition and Subtraction of Power series . . . . . . . . . . . . . . . . . . . . . . 18

6.2 Composition of Power Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

6.3 Multiplication of Power Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

6.4 Division of Power Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

7 Review Questions 24

8 Answers to Review Questions 27


Lecture Notes – MATH2118 Further Engineering Mathematics C 3

1 Introduction

A series containing non-negative integral powers of a variable x,



c0 + c1 x + c2 x + · · · + cn x + · · · =
2 n
cn xn
n=0

where cn are constants depending on n, is called a power series in x. This series is just a
particular case of the more general form,



c0 + c1 (x − a) + c2 (x − a) + · · · + cn (x − a) + · · · =
2 n
cn (x − a)n
n=0

which is called a power series in x − a. These two series converge to c0 when x = 0 and
x = a, respectively.

EXAMPLE
The power series


1 + x + x + ··· + x + ··· =
2 n
xn
n=0

is a geometric series with r = x. Thus, the series converges for |r| = |x| < 1. That
is, for −1 < x < 1.

2 Interval of Convergence

The set of all real numbers x for which a power series converges is said to be its interval
of convergence. A power series in x − a may converge

• on a finite interval centered at a:


(a − r, a + r), [a − r, a + r), (a − r, a + r] or [a − r, a + r];

• on the infinite interval (−∞, ∞); or

• at the single point x = a.

In the respective cases, we say that the radius of convergence is

r, ∞ or 0.
4 Power Series

radius of
convergence
divergence divergence

r
( · · · · · · · · · · · · · · · · · · · ·)·
0 a−r a a+r

convergence

For example, for the case (a − r, a + r):

EXAMPLE


xn
Find the interval of convergence for .
n=0
2n (n + 1)2
solution
Absolute convergence theorem:
a
n+1 xn+1 2n (n + 1)2
lim
= lim n+1 ×
n→∞ an n→∞ 2 (n + 2)2 xn

x(n + 1)2
= lim
n→∞ 2(n + 2)2
( )2
|x| n+1
= · lim
2 n→∞ n + 2
( )
|2| 1 + n1 2
= · lim
2 n→∞ 1 + n2
| {z }
=1
|x|
= .
2
The series is absolutely convergent for L = 12 |x| < 1, or |x| < 2. That is, the series
converges for −2 < x < 2. When x = ±2, the ratio test fails since 12 |x| = 1. We
must perform separate checks of the series for convergence at these endpoints.
At x = 2:
∑ 2n ∑ 1 ∑ 1
= < since n + 1 > n,
2n (n + 1)2 (n + 1)2 n2

which is convergent by the comparison test with the convergent p-series.


At x = −2:
∑ (−2)n ∑ (−1)n
= ,
2n (n + 1)2 (n + 1)2
Lecture Notes – MATH2118 Further Engineering Mathematics C 5

which is convergent by the alternating series test, since

1 1 1
lim = 0 and < for n ≥ 1.
n→∞ (n + 1)2 (n + 2)2 (n + 1)2
| {z } | {z }
= an+1 = an

Hence, the interval of convergence is a closed interval [−2, 2]. The radius of conver-
gence, R = 2. The series diverges if |x| > 2 (for x > 2 and x < −2).

EXAMPLE


xn
Find the interval of convergence for .
n=0
n!
solution
Absolute convergence theorem:
a n+1
n+1 x n!
lim = lim × n
n→∞ an n→∞ (n + 1)! x

xn · x · n!
= lim
n→∞ (n + 1)n! · xn
x

= lim
n→∞ n + 1
( )
1
= |x| · lim
n→∞ n + 1
| {z }
=0

= 0.

Since L = 0 < 1, this series converges for all x values. Hence, the interval of
convergence is (−∞, ∞), and the radius of convergence, R = ∞.

EXAMPLE


(x − 5)n
Find the interval of convergence for .
n=0
n 3n
solution
Absolute convergence theorem:
a
n+1 (x − 5)n+1 n · 3n
= lim ×
an n→∞ (n + 1)3n+1 (x − 5)n

(x − 5) n
= lim
n→∞ 3(n + 1)
( )
|x − 5| n
= · lim
3 n→∞ n + 1
6 Power Series

( )
|x − 5| 1
= · lim
3 n→∞ 1 + 1
| {z n }
=1
|x − 5|
= .
3
The series converges absolutely if 13 |x − 5| < 1, that is, 2 < x < 8.
At x = 2:
∑ (x − 5)n ∑ (−3)n ∑ (−1)n
= = ,
n3n n3n n
which is a convergent series by the alternating series test, since
1 1 1
lim = 0 and < for n ≥ 1,
n→∞ n n+1 n
monotonically decreasing to zero.
At x = 8:
∑ (x − 5)n ∑ 3n ∑1
= = ,
n 3n n 3n n
which is the divergent harmonic series.
Hence, the interval of convergence is [2, 8), and the radis of convergence is 3. The
given series diverges for x < 2 and x ≥ 8.

EXAMPLE


Find the interval of convergence for n!(x + 10)n .
n=0
solution
Absolute convergence theorem:
a
n+1 (n + 1)! (x + 10)n+1
lim = lim

n→∞ an n→∞ n! (x + 10)n

= lim (n + 1)(x + 10)
n→∞

= |x + 10| · lim (n + 1)
n→∞

∞ for x ̸= −10
= .
0 for x = −10

The series diverges for all real numbers x, except for x = −10. At x = −10, we
obtain a convergent series consisting of all zeros. The radius of convergence is zero.
Lecture Notes – MATH2118 Further Engineering Mathematics C 7

3 Differentiation and Integration of Power Series



For each x in its interval of convergence, a power series cn xn converges to a single
number. Thus, a power series defines or represents a function f with domain the interval
of convergence,


f (x) = cn xn
n=0

= c0 + c1 x + c2 x2 + c3 x3 + · · · + cn xn + · · · .

3.1 Differentiation of a Power Series



If f (x) = cn xn converges on an interval (−r, r), then f (x) is continuous and differen-
tiable for |x| < r:
d∑

f ′ (x) = cn xn
dx n=0
∑∞
d( )
= cn xn
n=0
dx


= ncn xn−1 .
n=1

d
Note that the latter series starts at n = 1 since c0 = 0. A power series can be
dx
differentiated term-by-term:
d d d d d
f ′ (x) = c0 + c1 x + c2 x2 + c3 x3 + · · · + cn xn + · · ·
dx dx dx dx dx
= c1 + 2c2 x + 3c3 x + · · · + ncn x
2 n−1
+ ···
∑∞
= ncn xn−1 .
n=1

The radius of convergence of this series is the same as that of cn xn . Similarly,
d ′
f ′′ (x) = f (x)
dx
∑∞
= n(n − 1)cn xn−2
n=2

= 2c2 + 3 · 2c3 x + · · · + n(n − 1)cn xn−2 + · · ·


∑∞
= n(n − 1) cn xn−2 (now n starts from 2).
n=2

It follows that a function represented by a power series for |x| < r possesses derivatives
of all orders in the interval.
8 Power Series

3.2 Integration of a Power Series

Just as a power series can be differentiated term-by-term within its interval of convergence,
it can also be integrated term-by-term:
∫ ∫ ∑

f (x)dx = cn xn dx
∫ n=0
( )
= c0 + c1 x + c2 x2 + · · · + cn xn + · · · dx
( c1 c2 cn n+1 )
= c0 x + x2 + x3 + · · · + x + ··· + C
2 3 n+1
∑∞
cn
= xn+1 + C,
n=0
n + 1

where C is an integration constant. If f (x) = cn xn converges to an interval (−r, r),
then
∫ ∫ ∑

f (x)dx = cn xn dx
n=0
∞ ∫

= cn xn dx
n=0
∑∞
cn
= xn+1 + C.
n=0
n+1

The radius of convergence will be the same as that of cn xn .

EXAMPLE
Find a power series representation for ln(1 + x) for |x| < 1, and approximate ln(1.2)
to four decimal places.

solution
1
The power series for is given by
1+t
1
= 1 − t + t2 − t3 + · · · + (−1)n tn + · · ·
1+t
∑∞
= (−1)n tn for |t| < 1.
n=0

For |t| < 1:


∫x ∫x ∫x ∫x ∫x
1
dt = dt − t dt + t dt − · · · + (−1)
2 n
tn dt + · · ·
1+t
0 0 0 0 0
Lecture Notes – MATH2118 Further Engineering Mathematics C 9

[ ]t=x [ 2 ]t=x [ 3 ]t=x [ n+1 ]t=x


t t n t
= t − + − · · · + (−1)
t=0 2 t=0 3 t=0 n + 1 t=0
x2 x3 xn+1
=x− + − · · · + (−1)n + ··· for |x| < 1.
2 3 n+1
Also,
∫x [ ]t=x
1
dt = ln(1 + t)
1+t t=0
0

= ln(1 + x) − ln(1)
= ln(1 + x).

Hence,
x2 x3 xn+1
ln(1 + x) = x − + − · · · + (−1)n + ···
2 3 n+1
∑∞
(−1)n n+1
= x for |x| < 1.
n=0
n+1

Substituting x = 0.2 (valid since x = 0.2 satisfy |x| < 1) in the above series provides
(0.2)2 (0.2)3 (0.2)4 (0.2)5 (0.2)6
ln(1.2) = 0.2 − + − + − + ···
2 3 4 5 6
≈ 0.1823.

This is an alternating series. If the sum of the series is denoted by L, we know from
the theory for alternating series that

Sn − L ≤ an+1 .

The above answer of 0.1823 is accurate to four decimal places, since for the fifth
partial sum,
( ) ( )
S5 − L ≤ a6 = 1.067 10−5 < 5 10−5 .

4 Taylor Series

For a power series representing a function f (x) on |x − a| < r,

f (x) = c0 + c1 (x − a) + c2 (x − a)2 + · · · + cn (x − a)n + · · ·


∑∞
= cn (x − a)n ,
n=0
10 Power Series

there is a relationship between the coefficients cn and the derivatives of f (x). That is,

f ′ (x) = c1 + 2c2 (x − a) + 3c3 (x − a)2 + 4c4 (x − a)3 + · · · ,


f ′′ (x) = 2c2 + 3 · 2c3 (x − a) + 4 · 3c4 (x − a)2 + · · · ,
f ′′′ (x) = 3 · 2 · 1c3 + 4 · 3 · 2c4 (x − a) + · · · ,

and so on. Evaluating the above series at x = a gives

f (a) = c0 ,
f ′ (a) = 1 · c1 ,
f ′′ (a) = 2 · 1 · c2 = 2! c2 ,
f ′′′ (a) = 3 · 2 · 1 · c3 = 3! c3 ,

respectively. In general, f (n) (a) = n! cn , or

f (n) (a)
cn = for n ≥ 0
n!

and

∞ ∑

f (n) (a)
f (x) = cn (x − a) =
n
(x − a)n for |x − a| < r.
n=0 n=0
n!

When n = 0, f (0) (a) = f (a) and 0! = 1. This series is called the Taylor series for f (x)
at x = a (named in honor of the English mathematician Brook Taylor (1685–1731), who
published this result in 1715).

4.1 Maclaurin Series

A special case of a Taylor series when a = 0,



f (n) (0)
f (x) = xn
n=0
n!

is called the Maclaurin series for f (x) (named after the Scottish mathematician, and
former student of Isaac Newton, Colin Maclaurin (1698–1746)).
Lecture Notes – MATH2118 Further Engineering Mathematics C 11

EXAMPLE
Find the Taylor series expansion for ln x about x = 1.
solution
The derivatives of f (x) = ln(x) are

f (x) = ln x,
1
f ′ (x) = ,
x
−1
f ′′ (x) = 2 ,
x
2!
f ′′′ (x) = 3 and so on,
x
(n − 1)!
f (n) (x) = (−1)n−1 .
xn
Here a = 1, we have after inserting x = 1 into the above derivatives,

f (1) = 0,
f ′ (1) = 1,
f ′′ (1) = −1,
f ′′′ (1) = 2!, and so on,
f (n) (1) = (−1)n−1 (n − 1)!.

Thus, the Taylor series for ln x is




f (n) (a)
ln x = (x − a)n
n=0
n!
∑∞
f (n) (1)
= (x − 1)n
n=0
n!
f ′ (1) f ′′ (1) f ′′′ (1)
= f (1) + (x − 1)1 + (x − 1)2 + (x − 1)3 + · · ·
1! 2! 3!
1 −1 2
= 0 + (x − 1) + (x − 1)2 + (x − 1)3 + · · ·
1! 2! 3!
1 1
= (x − 1) − (x − 1)2 + (x − 1)3 + · · ·
2 3
∑∞
(−1) n−1
= (x − 1)n .
n=1
n

Absolute convergence theorem:


a
n+1 (−1)n (x − 1)n+1 n
lim = lim ×
n→∞ an n→∞ n+1 (−1)n−1 (x − 1)n

−n(x − 1)
= lim
n→∞ n+1
12 Power Series


1
= |x − 1| · lim
1
n→∞ 1 +
n

= |x − 1|.

The series converges when |x − 1| < 1, (i.e. for 0 < x < 2).
For the endpoints, at x = 0, we have


(−1)n−1 ∑

(−1)2n (−1)−1
n
(−1) =
n=1
n n=1
n


1
=− ,
n=1
n

which is a divergent harmonic series. At x = 2, we have




(−1)n−1 ∑ ∞
(−1)n
(1) = −
n
,
n=1
n n=1
n

which is a convergent series by the alternating series test, since


1 1 1
lim = 0 and < for all n ≥ 1.
n→∞ n n+1 n
Hence, the Taylor series for ln x converges for 0 < x ≤ 2, and R = 1.

4.2 Taylor’s Theorem

This theorem also known as the Generalised Mean Value Theorem. Let f (x) be a function
such that f (n+1) (x) exists for |x − a| < r, then

f (x) = Pn (x) + Rn (x),

where
f ′ (a) f ′′ (a) f (n) (a)
Pn (x) = f (a) + (x − a) + (x − a)2 + · · · + (x − a)n
1! 2! n!
is called the nth degree Taylor polynomial of f (x) at x = a (note that Taylor polynomials
do not exist for every function), and
f (n+1) (c)
Rn (x) = (x − a)n+1 ,
(n + 1)!
where a < c < x, is called the Lagrange form of the remainder, or error, involved in
approximating f (x) by Pn (x) (theory due to the French mathematician, Joseph Louis
Lagrange (1736–1813)).
Lecture Notes – MATH2118 Further Engineering Mathematics C 13

The series expansion for f (x) will only be valid for those values of x for which Rn → 0 as
n → ∞; that is, for x values which the power series converges. Hence,
Pn (x) = f (x) − Rn (x),
and so
lim Pn (x) = lim f (x) − lim Rn (x).
n→∞ n→∞ n→∞
If Rn (x) → 0 as n → ∞, then the sequence of partial sums converges to lim f (x) = f (x).
n→∞

EXAMPLE
Represent f (x) = cos x by a Maclaurin series.
solution
For Maclaurin series, a = 0:
∑∞
f (n) (a)
f (x) = (x − a)n
n=0
n!


f (n) (0)
= xn
n=0
n!
x2 x3
= f (0) + f ′ (0)x + f ′′ (0) + f ′′′ (0) + · · · .
2! 3!
For f (x) = cos x, we have
f (x) = cos x,
f ′ (x) = − sin x,
f ′′ (x) = − cos,
f ′′′ (x) = sin x, and so on.
Thus, for x = 0,
f (0) = 1,
f ′ (0) = 0,
f ′′ (0) = −1,
f ′′′ (0) = 0, and so on.
Hence,
x2 x4 x6
f (x) = 1 − + − + ···
2! 4! 6!
∑∞
(−1)n 2n
= x .
n=0
(2n)!
This series contains even powers of x, since cos x is an even function.
14 Power Series

Absolute convergence test:


a
n+1 (−1)n+1 x2n+2 (2n)!
lim = lim ×
n→∞ an n→∞ (2n + 2)! (−1)n x2n

−x 2
= lim
n→∞ (2n + 2)(2n + 1)

x2 −1
= · lim
2 n→∞ (n + 1)(2n + 1)
| {z }
=0

= 0.

Hence, the series converges absolutely for all real x values.


To show that cos x is represented by the series, we must show

lim Rn (x) = 0.
n→∞

The derivatives of f (x) satisfy



(n+1) |sin x| for n even
f (x) = .
|cos x| for n odd

In either case, f (n+1) (c) ≤ 1 for any real number c, and so

f (n+1) (c) n+1
Rn (x) = |x|
(n + 1)!
|x|n+1
≤ .
(n + 1)!
For any fixed, but arbitrary choice of x,
|x|n+1
lim = 0.
n→∞ (n + 1)!

Thus, lim Rn (x) = 0, implies that lim Rn (x) = 0. Therefore,
n→∞ n→∞

x2 x4 x6 (−1)n 2n
cos x = 1 − + − + ··· + x + ···
2! 4! 6! (2n)!
is a valid representation of cos x.

note
Some important Maclaurin series:
x2 x3 ∑

xn
x
e =1+x+ + + ··· = for all x,
2! 3! n=0
n!

x2 x4 x6 ∑

(−1)n
cos x = 1 − + − + ··· = x2n for all x,
2! 4! 6! n=0
(2n)!
Lecture Notes – MATH2118 Further Engineering Mathematics C 15

x3 x5 x7 ∑∞
(−1)n
sin x = x − + − + ··· = x2n+1 for all x,
3! 5! 7! n=0
(2n + 1)!

x2 x4 x6 ∑∞
x2n
cosh x = 1 + + + + ··· = for all x,
2! 4! 6! n=0
(2n)!

x3 x5 x7 ∑

x2n+1
sinh x = x + + + + ··· = for all x,
3! 5! 7! n=0
(2n + 1)!

x2 x3 x4 ∑∞
(−1)n n+1
ln(1 + x) = x − + − + ··· = x for x ∈ (−1, 1].
2 3 4 n=0
(n + 1)

4.3 Approximation with Taylor Polynomials

When the value of x is close to the number a (x ≈ a), the Taylor polynomial Pn (x) of
a function f (x) at x = a can be used to approximate the functional value of f (x). The
error in this approximation is

f (x) − Pn (x) = Rn (x) .

EXAMPLE
Approximate e−0.2 by P3 (x), and determine the accuracy of the approximation.
solution
Because the value of x = −0.2 is close to x = 0, we use the Taylor polynomial P3 (x)
of f (x) = ex at a = 0. Since f (x) = f ′ (x) = f ′′ (x) = f ′′′ (x) = ex , we have
f ′ (0) f ′′ (0) 2 f ′′′ (0) 3
P3 (x) = f (0) + x+ x + x
1! 2! 3!
x2 x3
=1+x+ + .
2 6
Then,
(−0.2)2 (−0.2)3
P3 (−0.2) = 1 + (−0.2) + +
2 3
≈ 0.81867.

Consequently, e−0.2 ≈ 0.81867. Furthermore,



f (4) (c)
R3 (x) = · |x|4
4!
ec
= · |x|4
4!
x4
< ,
24
16 Power Series

and since −0.2 < c < a, ec < 1. Thus,

4
R3 (−0.2) < (−0.2) ≈ 10−4
24

implies that e−0.2 ≈ 0.819 is accurate to three decimal places.

5 Binomial Series

From basic mathematics, we know that

(1 + x)2 = 1 + 2x + x2 ;
(1 + x)3 = 1 + 3x + 3x2 + x3 .

In general, if α is a non-negative integer, we can apply the Binomial Theorem to expand


(1 + x)α as

α(α − 1) 2 α(α − 1)(α − 2) 3 α(α − 1)(α − 2)(α − 3) 4


(1 + x)α = 1 + αx + x + x + x
2! 3! 4!
α(α − 1) · · · (α − n + 1) n
+ ··· + x + ··· .
n!

The expansion of (1 + x)α into the above form is called binomial series. Applying the
absolute ratio test provides

α(α − 1)(α − 2) · · · (α − n + 1) n
an = x ,
n!
α(α − 1)(α − 2) · · · (α − n + 1)(α − n) n+1
an+1 = x ,
(n + 1)!
a
n+1 α(α − 1)(α − 2) · · · (α − n + 1)(α − n)xn+1 · n!
⇒ = lim
an n→∞ (n + 1)! · α(α − 1)(α − 2) · · · (α − n + 1)xn

(α − n)x
= lim
n→∞ n+1

α − n
= |x| · lim
n→∞ n + 1

α/n − 1
= |x| · lim
n→∞ 1 + 1/n

= |x| · |−1|
= |x|.
Lecture Notes – MATH2118 Further Engineering Mathematics C 17

Thus, for |x| < 1, that is on the interval (−1, 1), the binomial series defines an infinitely
differentiable function f (x). Hence, we have the binomial series (Maclaurin series for
(1 + x)α ):



(1 + x)α = cn xn
n=0
α(α − 1) 2 α(α − 1)(α − 2) 3 α(α − 1)(α − 2)(α − 3) 4
= 1 + αx + x + x + x ···
2! 3! 4!
α(α − 1) · · · (α − n + 1) n
+ x + ··· for |x| < 1.
n!

EXAMPLE

Find a power series representation for 1 + x.

solution
For |x| < 1, we have

1 + x = (1 + x)α (here α = 12 )
( ) ( )( 1 ) ( )( 1 )( 1 )
1 1 1
− 1 1 1
− 1 − 2 1 1
− 1 − 2 − 3
=1+ x+ 2 2 x2 + 2 2 2
x3 + 2 2 2 2
x4
2 2! 3! 4!
( ) ( )
1 1
− 1 · · · 12 − n + 1 n
+ ··· + 2 2
x + ···
n!
1 1 1 5 4 7 5
= 1 + x − x2 + x3 − x + x − ··· .
2 8 16 128 256

EXAMPLE
In Einstein’s theory of relativity, the mass of a particle moving at a velocity v,
relative to an observer is given by
m0
m= √ ,
1 − v 2 /c2

where m0 is the rest mass and c is the speed of light. Many of the results from
classical physics do not hold for particles, such as electrons, which may move close
to the speed of light. Kinetic energy is no longer K = 12 m0 v 2 , but
( )
K = m − m0 c 2 .
m0
If we identify α = −1/2 and x = −v 2 /c2 in m = √ , we have |x| < 1 since
1 − v 2 /c2
no particle can surpass the speed of light, i.e. v < c. Hence, K can be written as
( )
m0
K= √ − m0 c 2
1 − v 2 /c2
18 Power Series

( )
= m0 c2 (1 + x)−1/2 − 1 with x = −v 2 /c2
(( ) )
1 3 5
= m0 c2 1 − x + x2 − x3 + · · · − 1
2 8 16
( 2 )
v 3v 4 5v 6
= m0 c 2
+ + 6 + ··· .
2c2 8c4 6c
In the case where v ≪ c, terms beyond the first in the series are negligible. This
leads to the well-known result
v2
K ≈ m0 c2 ·
2c2
1
= m0 v 2 .
2

6 Manipulation of Power Series

6.1 Addition and Subtraction of Power series

Power series can be added or subtracted, term-by-term for those values of x for which
both series converge. Suppose


f (x) = cn xn = c0 + c1 x + c2 x2 + · · · + cn xn + · · · for |x| < r1 ,
n=0

and


g(x) = dn xn = d0 + d1 x + d2 x2 + · · · + dn xn + · · · for |x| < r2 ,
n=0
where r1 and r2 are the corresponding radius convergence, then

∞ ∑

f (x) ± g(x) = cn x ±n
dn xn
n=0 n=0


( )
= cn ± dn xn
n=0

= (c0 + d0 ) ± (c1 + d1 )x ± (c2 + d2 )x2 ± · · · ± (cn + dn )xn + · · · for |x| < min(r1 , r2 ).

Also, if k is a constant, then




kf (x) = kcn xn
n=0

= kc0 + kc1 x + kc2 x2 + · · · + kcn xn + · · · for |x| < r1 .


Lecture Notes – MATH2118 Further Engineering Mathematics C 19

EXAMPLE
Find a power series representation for cosh θ. Hence, obtain estimate for cosh(1/2).
solution
( )
Using the relation cosh θ = 1
2
eθ + e−θ , and the series expansion for ex ,


xn
ex =
n=0
n!
x2 x3 x4
=1+x+ + + + ··· for all x,
2! 3! 4!
we have
1( θ )
cosh θ = e − e−θ
2(
( ) ( ))
1 θ2 θ3 θ4 θ2 θ3 θ4
= 1+θ+ + + + ··· + 1 − θ + − + + ···
2 2! 3! 4! 2! 3! 4!
θ2 θ4 θ6
=1+ + + + ··· for all θ
2! 4! 6!
∑∞
θ2n
= .
n=0
(2n)!
Alternative method:
1( θ −θ
)
cosh θ = e − e
2( )
1 ∑ θn ∑ (−θ)n
∞ ∞
= +
2 n=0 n! n=0 n!


θn + (−θ)n
=
n=0
2n!
( )
∑∞
1 + (−1)n θn
=
n=0
2n!



θn 0 for odd n
= for even n, since 1 + (−1)n =
n! 2 for even n
n=0

∑∞
θ2n
= .
n=0
(2n)!

For θ = 1/2:


(1/2)2n
cosh(1/2) =
n=0
(2n)!
(1/2)2 (1/2)4 (1/2)6
=1+ + + + ···
2! 4! 6!
≈ 1.1276 .
20 Power Series

6.2 Composition of Power Series

Suppose


f (x) = cn x n
n=0

= c0 + c1 x + c2 x2 + c3 x3 + · · · + cn xn + · · · for |x| < r1 .


( )
The power series for f g(x) can be obtained from
( ) ∑∞
( )n
f g(x) = cn g(x)
n=0
( )2 ( )3 ( )n
= c0 + c1 g(x) + c2 g(x) + c3 g(x) + · · · + cn g(x) + · · · for |g(x)| < r1 ,

and follow by substituting the power series expansion for g(x) into this expression.

EXAMPLE
Using the standard series from the Concise Collection of Formulae, determine the
2 /2
first few terms of the power series for ex .
solution
Using the power series expansion for et :


tn
t
e =
n=0
n!
t2 t3 t4
=1+t+ + + + ··· for all t,
2! 3! 4!
we have upon substituting t = 21 x2 ,
( 1 2 )2 ( 1 2 )3 ( 1 2 )4
2 ( ) x x x
ex /2 = 1 + 12 x2 + 2 + 2 + 2 + ···
2! 3! 4!
x2 x4 x6 x8 √
=1+ + + + + · · · for 12 x2 < 1 or |x| < 2 .
2 8 48 384

6.3 Multiplication of Power Series

Suppose


f (x) = cn x n
n=0

= c0 + c1 x + c2 x2 + c3 x3 + · · · + cn xn + · · · for |x| < r1 ,


Lecture Notes – MATH2118 Further Engineering Mathematics C 21

and


g(x) = dn xn
n=0

= d0 + d1 x + d2 x2 + d3 x3 + · · · + dn xn + · · · for |x| < r2 ,

then
( )( )
f (x) × g(x) = c0 + c1 x + c2 x2 + c3 x3 + · · · d0 + d1 x + d2 x2 + d3 x3 + · · ·
( ) ( )
= c0 d0 + c0 d1 + c1 d0 x + c2 d0 + c1 d1 + c0 d2 x2
( )
+ c0 d3 + c1 d2 + c2 d1 + c3 d0 x3 + · · · for |x| < min(r1 , r2 ).

EXAMPLE
Using the standard series from the Concise Collection of Formulae, determine the
first few terms of the power series for ex cos x.
solution
Using the power series expansions for ex and cos x, we have
( )( )
x2 x3 x4 x2 x4 x6
x
e cos x = 1 + x + + + + ··· 1 − + − + ···
2! 3! 4! 2! 4! 6!
( ) ( ) (1 )
= 1 + x(1) + x2 − 12 + 12 + x3 − 12 + 16 + x4 24 − 14 + 24
1
+ ···

x3 x4
=1+x− − + ··· for all x.
3 6
The series expansion for ex cos x is valid for all x, since both the series expansions
for ex and cos x are valid for all x.

6.4 Division of Power Series

Suppose


f (x) = cn x n
n=0

= c0 + c1 x + c2 x2 + c3 x3 + · · · + cn xn + · · · for |x| < r1 ,

and


g(x) = dn xn
n=0

= d0 + d1 x + d2 x2 + d3 x3 + · · · + dn xn + · · · for |x| < r2 ,


22 Power Series

then the quotient,


f (x) c0 + c1 x + c2 x2 + c3 x3 + · · · + cn xn + · · ·
=
g(x) d0 + d1 x + d2 x2 + d3 x3 + · · · + dn xn + · · ·
= q0 + q1 x + q2 x2 + q3 x3 + · · · + qn xn + · · ·

provided c0 ̸= 0 and d0 ̸= 0. The coefficients (q0 , q1 , q2 , q3 , . . .) may be obtained by the


procedure of long division, or by writing

c0 + c1 x + c2 x2 + c3 x3 + · · · + cn xn + · · ·
( )
= q0 + q1 x + q2 x2 + q3 x3 + · · · + qn xn + · · ·
( )
× d0 + d1 x + d2 x2 + d3 x3 + · · · + dn xn + · · · ,

and expanding the right-hand-side and equating coefficients of like terms. Note that the
resulting power series may not converge for |x| < min(r1 , r2 ) as there is an added compli-
cation, and problems may occur whenever the denominator is zero.

EXAMPLE
Using the standard series from the Concise Collection of Formulae,
∫ 1 determine the
first few terms of the power series for tanh x. Hence, evaluate tanh x dx.
0
solution
Using the power series expansions for sinh x and cosh x, we have
x3 x5 x7
sinh x = x + + + + ··· for all x,
3! 5! 7!
x2 x4 x6
cosh x = 1 + + + + ··· for all x,
2! 4! 6!
sinh x
⇒ tanh x =
cosh x
x3 x5 x7
x+ 3!
+ 5!
+ 7!
+ ···
=
1+ x2
2!
+ x4
4!
+ x6
6!
+ ···

= q0 + q1 x + q2 x2 + q3 x3 + · · · + qn xn + · · · .

This requires
x3 x5 x7
x+ + + + ···
6 120 5040
( ) ( )
x2 x4 x6
= q0 + q1 x + q2 x + q3 x + · · · + qn x + · · · × 1 +
2 3 n
+ + + ···
2 24 720
( ) ( ) (1 )
= q0 + q1 x + 12 q0 + q2 x2 + 12 q1 + q3 x3 + 24 q0 + 12 q2 + q4 x4
(1 ) ( 1 )
+ 24 q1 + 12 q3 + q5 x5 + 720 q0 + 241
q2 + 12 q4 + q6 x6
( 1 )
+ 720 q1 + 241
q3 + 12 q5 + q7 x7 + · · ·
Lecture Notes – MATH2118 Further Engineering Mathematics C 23

Equating the coefficients of x, we have

q0 = 0,
q1 = 1,
q2 = − 21 q0 = 0,
q3 = 1
6
− 12 q1 = − 31 ,
q4 = − 24
1
q0 − 12 q2 = 0,
q5 = 1
120
− 1
q
24 1
− 12 q3 = 2
15
,
q6 = − 720
1
q0 − 1
q
24 2
− 12 q4 = 0,
q7 = 1
5040
− 1
q
720 1
− 1
q
24 3
− 12 q5 = − 315
17
.

Hence,
x3 2x5 17x7
tanh x = x − + − + ··· for all x.
3 15 315
Integrating tanh x,
∫ 1 ∫ 1( )
x3 2x5 17x7
tanh x dx = x− + − + · · · dx
0 0 3 15 315
[ 2 ]x=1
x x4 x6 6 17x8
= − + x −
2 12 45 2520 x=0
121
=
280
≈ 0.4321.

Exact Answer:
∫ 1 ∫ 1
sinh x
tanh x dx = dx
0 0 cosh x
[ ]x=1
= ln|cosh x|
x=0
( ) ( )
= ln cosh 1 − ln cosh 0
( )
= ln cosh 1 − ln(1) since cosh 0 = 1
≈ 0.4338.

The relative difference between the approximate and exact answers is 0.378.
24 Power Series

7 Review Questions

[1] Determine the Taylor polynomial of degree three for f (x) = x at x = 4.

Hence, estimate 4.2.

[2] Suppose f (x) is a sufficiently well-behaved function, and

Pn (x) = a0 + a1 (x − a) + a2 (x − a)2 + a3 (x − a)3 + · · · + an (x − a)n

is a polynomial which satisfies

Pn (a) = f (a), Pn′ (a) = f ′ (a), Pn′′ (a) = f ′′ (a), ..., Pn(n) = f (n) (a).

Show that
f ′′ (a) f (3) (a) f (n) (a)
a0 = f (a), a1 = f ′ (a), a2 = , a3 = , ··· , an = .
2! 3! n!

[3] Obtain the following Maclaurin Series:


x3 x5 x7
(a) arctan x = x − + − + ··· ;
3 5 7
x2 x3 x4
(b) ex = 1 + x + + + + ··· ;
2! 3! 4!
x2 x3 x4
(c) log(1 + x) = x − + − + ··· .
2 3 4
[4] Determine the Taylor series for f (x) = cos x about the point x = π/3.

[5] Obtain a Taylor series for tan x in the following form,


( ) ( )2
tan x = a0 + a1 x − π/4 + a2 x − π/4 + · · · .

[6] Determine the radius of convergence R for each of the following power series:
∑ nxn
(a) ;
2n+1
∑ (x − 1)n+1
(b) ;
n 3n−1
∑ xn
(c) (−1)n √ ;
n+1
∑ 2n−1 xn
(d) ;
n3
∑ (n!)2
(e) xn ;
(2n)!
∑ ( )
n n+1
(f) (−1) xn .
n+2
Lecture Notes – MATH2118 Further Engineering Mathematics C 25



( )n
[7] (a) Use the geometric series −x2 to obtain the expansion
n=0

x3 x5
arctan x = x − + − ··· + ··· for |x| < 1.
3 5

(b) Use (a) to show that


arctan x
lim = 1.
n→∞ x
(c) Show that ∫ x
arctan t x3 x5 x7
dt = x − 2 + 2 − 2 + · · · .
0 t 3 5 7

[8] Assuming that the power series for sin x and cos x hold for all complex numbers,
show that

sin(iθ) = i sinh θ and cos(iθ) = cosh θ, where i = −1 .

[9] Using the Binomial Theorem, determine power series expansions and radius of con-
vergence for each of the following functions:

(a) 1 − x;

(b) (1 + 2x)−3 ;
1
(c) √3
;
1 + 3x3
( )−2
(d) 1 + 2x2 .

[10] Show that


7 3 1
= − .
+ 5x − 2
3x2 3x − 1 x + 2
7
Hence, obtain a power series expansion for 2 using the binomial series.
3x + 5x − 2
[11] Use the power series expansion for log(1 + x) to find a power series expansion for
( )
1+x
log .
1−x

Hence, obtain an estimate for log 3.

[12] Using the standard series from the Concise Collection of Formulae, determine the
first few terms of the power series for
( )
(a) exp − 12 x2 ;

(b) ex cos x ;
26 Power Series

( )
(c) log 1 + ex .

[13] Use the power series for log(1 + x) to show that


( )2 11x4
log(1 + x) =x −x +
2
+ ···
3
if |x| < 1.
12

[14] Use the first four terms of appropriate power series to obtain estimates of
∫ 1
dx
(a) √ ;
0 1 − 14 x4
∫ 1/10 x
e −1
(b) dx ;
0 x
∫ 1/2 √
1
(c) 1 + x3 dx ;
0 2
∫ 1/5
sin x
(d) dx.
0 x
[15] Using the binomial and exponential series, show that

e−x 4
√ = 1 + x2 + x3 + · · · if |x| < 1/2.
1 − 2x 3
∫ 1/5
e−x
Hence, obtain an approximate value for √ dx.
0 1 − 2x
[16] Use the series,
x2 x4 x6
cos x = 1 − + − + ··· for all x,
2! 4! 6!
and
α(α − 1) 2 α(α − 1)(α − 2) 3
(1 + x)α = 1 + αx + x + x + ··· if |x| < 1,
2! 3!
to find the first four terms of the power series for

1 − x · cos x.

Hence, obtain an approximate value for


∫ 1/10 √
1 − x · cos x dx .
0
Lecture Notes – MATH2118 Further Engineering Mathematics C 27

8 Answers to Review Questions


1 1 1 √
[1] P3 (x) = 2 + (x − 4) − (x − 4)2 + (x − 4)3 ; 4.2 ≈ 2.0494.
4 64 512
[2] Not available.

[3] Not available.


√ √
1 3( ) 1( )2 3( )3
[4] cos(π/3) ≈ − x − π/3 − x − π/3 + x − π/3 − · · · + · · ·
2 2 4 2
[5] a0 = 1, a1 = 2, a2 = 2.

[6] (a) R = 2
(b) R = 3
(c) R = 1
(d) R = 1/2
(e) R = 4
(f) R = 1

[7] Not available.

[8] Not available.


x x2 x3 5x4
[9] (a) 1 − − − − − · · · ; R = 1.
2 8 16 128
(b) 1 − 6x + 24x2 − 80x3 + · · · − · · · ; R = 1/2.
14x9 1
(c) 1 − x3 + 2x6 − + ··· − ··· ; R = √ 3
.
3 3
1
(d) 1 − 4x2 + 12x4 − 32x6 + · · · − · · · ; R = √ .
2
∑∞ ( )
(−1)n n 7 35x 217x2
[10] − 3n+1
+ n+1 x = − − − − · · · ; R = 1/3.
n=0
2 2 4 8
( ) ( )
1+x x3 x5 x7 x9
[11] log =2 x+ + + + + · · · for |x| < 1;
1−x 3 5 7 9
log 3 ≈ 1.0981 using the first four terms.
x2 x4 x6
[12] (a) 1 − + 2 − 3 + ···
2 2 2! 2 3!
3
x x4
(b) 1 + x − − + ···
3 6
x x2 x4
(c) log 2 + + − + ···
2 8 192
28 Power Series

[13] Not available.

[14] (a) 1.0280


(b) 0.1026
( )
(c) 0.50387 using the first three terms; truncation error less than 7.6 10−7 .
( )
(d) 0.19956 using the first two terms; truncation error less than 5.3 10−7 .

[15] 0.2032
√ x 5x2 3x3
[16] 1 − x · cos x ≈ 1 − − + + ··· ;
2 8 16
∫ 1/10

1 − x · cos x dx ≈ 0.0973.
0
Introduction to MATLAB

Dr Eddie Ly
BEng(Hons), BAppSc, PhD RMIT
School of Mathematical & Geospatial Sciences (SMGS)
College of Science, Engineering & Health (SHE)
RMIT University, Melbourne, Australia
Summer Course 2015

PART 1 OF 8 MATH2118 Further Eng Maths C 1


Introduction

 MATLAB stands for “Matrix Laboratory”.


 Developed in 1970 by The MathWorks Inc., Massachusetts, USA, for
applications involving matrices, numerical analysis and linear algebra
(solving a system of linear equations).
 Designed for technical calculations (where scientific calculations,
visualisations and user defined programmes can be combined).
 Competitors: Maple and Mathematica
 MATLAB’s related simulation product: FEMLAB (multiphysics simulations)

PART 1 OF 8 MATH2118 Further Eng Maths C 2


Toolbox

 MATLAB can be extended with so called Toolboxes, which are collections


of MATLAB functions.

 Symbolic Math Toolbox


Consists of ingredients from the computer algebra package Maple
(developed by Waterloo Maple Inc., Canada)

PART 1 OF 8 MATH2118 Further Eng Maths C 3


Starting MATLAB

 Double-click on the MATLAB


icon.

 Command Window appears, in


which commands can be typed
after the MATLAB prompt:
>>
(press [Enter] key)

PART 1 OF 8 MATH2118 Further Eng Maths C 4


Stopping MATLAB

 Two ways to stop MATLAB:

(1) By the command,


>> quit

(2) By the menu File, choose Exit MATLAB.

PART 1 OF 8 MATH2118 Further Eng Maths C 5


Command Window

 To communicate with MATLAB


by entering instructions after the
>> prompt

 Student Edition:
EDU >>

PART 1 OF 8 MATH2118 Further Eng Maths C 6


Launch Pad

 Lists all installed toolboxes and


other MATLAB-related programs.
For example, Simulink.

 Run tools and access documentation


for all your MathWorks products.

PART 1 OF 8 MATH2118 Further Eng Maths C 7


Command History Window

 View a log of the functions you


entered in the Command Window,
which you can copy, paste and
execute them.

PART 1 OF 8 MATH2118 Further Eng Maths C 8


Entering Commands & Expressions

 Enter commands after the prompt >>.


>> 1+2
ans =
3

 Assigned answer to a temporary


variable called ans (to store the
most recent answer, abbreviation
for answer).

PART 1 OF 8 MATH2118 Further Eng Maths C 9


 A variable in MATLAB is a symbol used to contain a value.
>> sqrt(ans)
ans =
1.7321

The variable ans now has the value of 1.7321.

 MATLAB uses high precision for all its computations.


By default, answers are displayed using four decimal places (short format).

PART 1 OF 8 MATH2118 Further Eng Maths C 10


 Assigning the result to a variable of your own choosing.
>> x = 1+2+3
x =
6
>> y = 2*x + x/3
y =
14
You can assign a new value to the same variable (reuse the variable).

 It is not possible to perform calculations with variables that have not been
assigned a value.

PART 1 OF 8 MATH2118 Further Eng Maths C 11


 If you now want to know what the value of x is, enter:
>> x
x =
6

 Normally, MATLAB displays the output below the command. The output is
suppressed by ending the command with a semicolon (;). For example,
>> s = 2*3;
>>

The value of 6 has been assigned to the variable s, but will not be
displayed on the screen.

PART 1 OF 8 MATH2118 Further Eng Maths C 12


 If you want to know the value of this variable, enter:
>> s
s =
6

 If a command is longer than one line, you can end the line with three
periods and press [Enter]. You can then continue on the following line.
>> s = 1+2+…
3+4
>> s =
10

PART 1 OF 8 MATH2118 Further Eng Maths C 13


Interruption of Calculations or Outputs

 A long MATLAB calculation can be interrupted with the [Ctrl-C] keys.


After this, a new prompt appears and new commands can be entered.

 Program with endless-loop (due to programming or unknown errors)


can be terminated in this manner as well.

PART 1 OF 8 MATH2118 Further Eng Maths C 14


Order of Precedence

 A scalar is a single number.


A scalar variable is a variable that contains a single number.

 Scalar arithmetic operations:

^ Exponentiation x^y
* Multiplication x*y
/ Right Division x/y
\ Left Division y/x
+ Addition x+y
- Subtraction x-y

PART 1 OF 8 MATH2118 Further Eng Maths C 15


 Right division, denoted by the forward slash (/), is the normal division
operator.
 Left division, denoted by the backslash (\), is used for solving sets of linear
algebraic equations.
 Mathematical expressions are evaluated from left to right. The order of
operations is the standard order: terms inside parentheses,
exponentiation, multiplication or division, then addition or subtraction.
 Parentheses can be used to define the order of operations, where
evaluation begins with the innermost pair of parentheses, and proceeds
outward.

PART 1 OF 8 MATH2118 Further Eng Maths C 16


>> 10-2*3 >> 10-(2*3) >> (10-2)*3
ans = ans = ans =
4 4 24

>> 2^3-1+6/2*3 >> 2^3-1+6/(2*3)


ans = ans =
16 8

>> 27^(1/3) >> 27^1/3


ans = ans =
3 9
 To avoid mistakes and to improve the readability of your MATLAB
expressions, use parentheses where possible.
PART 1 OF 8 MATH2118 Further Eng Maths C 17
Variables

 The name of a variable has to start with a letter. After that, the name can
consist of an arbitrary number of letters and numbers.

 The Command Workspace lists all used variables, and indicates to which
class the variables belong. If necessary, you can remove variables by
using this workspace (browser).

PART 1 OF 8 MATH2118 Further Eng Maths C 18


Special Variables

 MATLAB uses some special variables:


ans Contains the most recent unassigned answer
eps Value of 2.2204E-16
i,j Complex number i
pi 3.14159 …
Inf Infinity value, i.e. 1/0
NaN Represents “ Not-a-Number ”, i.e. 0/0

 Some important commands:


who Gives a list of the variables in use
whos Gives a list of the variables in use as well as some extra information
clear Removes all variables
clear x Removes the variable x only

PART 1 OF 8 MATH2118 Further Eng Maths C 19


 WARNING
In principle, it is possible to assign a value to the internal MATLAB
variables (see previous slide), but this can influence your calculations.
Therefore, it is wise to never assign a value to an internal MATLAB
variables.

PART 1 OF 8 MATH2118 Further Eng Maths C 20


Workspace

 Refers to the names and values of any variables in use in the current work
session.

 Variable names consist of no more than 32 characters (letters, digits and


underscore) and begin with a letter. MATLAB is case-sensitive.

For example, force, Force, FORCE and force_x are all different variables.

PART 1 OF 8 MATH2118 Further Eng Maths C 21


Related Workspace Commands:

cls clears the Command Window


(not removing the declared variables)
clear removes all variables from the computer memory
clear x y removes the variables x and y from the memory only
exist(’var’) determines if a file or a variable exists having the
name ‘var’ (returns 1 if exists, otherwise 0)

PART 1 OF 8 MATH2118 Further Eng Maths C 22


Complex Number Operations
 MATLAB handles complex number algebra automatically.
To enter z = 1+3i, type z = 1+3i or z = 1+3j.
 An asterisk is not needed between i or j and a number. However, it is required
with a variable. For example, z = a+i*b for z = a+ib.
 Examples:
>> z1 = 1+2i; z2 = 1-3i;
>> z1-z2
ans =
0 + 5.0000i
>> z1*z2
ans =
7.0000 – 1.0000i
>> z1/z2
ans =
-0.5000 + 0.5000i

PART 1 OF 8 MATH2118 Further Eng Maths C 23


Array & Matrix Computations

Dr Eddie Ly
BEng(Hons), BAppSc, PhD RMIT
School of Mathematical & Geospatial Sciences (SMGS)
College of Science, Engineering & Health (SEH)
RMIT University, Melbourne, Australia
Summer Course 2015

PART 2 OF 8 MATH2118 Further Eng Maths C 1


Arrays

 MATLAB is designed for array operations. Array is a collection of numbers,


i.e. vector, matrix.

 Vector = one-dimensional array


Matrix = two-dimensional array

 Three- or higher-dimensional arrays are possible.

 MATLAB represents vector as a row or column vector.


A vector can have only one column or row.

PART 2 OF 8 MATH2118 Further Eng Maths C 2


Creating Vectors

 To create a row vector, enter the elements of the vector inside a pair of
square brackets [ ], separating the elements with a space or comma.

Example: To enter row vectors [1 2 3] and [-1 0 –2], enter:


>> x = [1,2,3]
x =
1 2 3

>> y = [-1 0 –2]


y =
-1 0 -2

PART 2 OF 8 MATH2118 Further Eng Maths C 3


 To create a column vector, enter the elements of the vector inside a pair of
square brackets and separating the elements by semicolons. For example,
>> s = [-1;2;6]
s =
-1
2
6
 Alternatively, create a row vector follow by a transpose operation using the
’ command. For example,
>> s = [-1,2,6]’
s =
-1
2
6

PART 2 OF 8 MATH2118 Further Eng Maths C 4


 Third way to create a column vector is by entering each element on a new
line. For example,
>> s = [-1
2
6]
s =
-1
2
6

Remember to press [Enter] after entering each element.

PART 2 OF 8 MATH2118 Further Eng Maths C 5


Appending Vectors
 Vectors can be created by appending one vector to another.
>> a = [1,2,3];
b = [4,5,6];
>> c = [a,b]
c =
1 2 3 4 5 6

>> [a,b(2)]
ans =
1 2 3 5

>> [a(1:2),b]
ans =
1 2 4 5 6

PART 2 OF 8 MATH2118 Further Eng Maths C 6


Vector of Regularly Spaced Elements
 We can use the colon operator to generate a large vector with regularly
spaced elements.

Syntax: x = [a:s:b]

This will create a vector x of values


a, a+s, a+2s, a+3s, …, …, …, b-s, b
where s is the increment value (optional, default value of 1). Note the last
value is b if b-a is an integer multiply of increment s. For example,
>> [1:3:10]
ans =
1 4 7 10

PART 2 OF 8 MATH2118 Further Eng Maths C 7


 More examples,
>> t = [3:5:14]
t =
3 8 13
>> u = [0:0.2:1]
u =
0 0.2000 0.4000 0.6000 0.8000 1.0000

If s is omitted, then by default s=1.


>> [-2:1]
ans =
-2 -1 0 1

The increment s can be negative. If s>0 then a<b, and if s<0, a>b.
>> [8:-2:0]
ans =
8 6 4 2 0

PART 2 OF 8 MATH2118 Further Eng Maths C 8


Command: linspace

 To create a linearly spaced row vector, where the number of values is


specified instead of the increment s.

Syntax: linspace(a,b,n)
where a = lower limit
b = upper limit
n = number of points (default n=100)
Example:
>> linspace(1,2,6)
ans =
1.0000 1.2000 1.4000 1.6000 1.8000 2.0000

PART 2 OF 8 MATH2118 Further Eng Maths C 9


Command: logspace

 To create an array of logarithmically spaced elements.

Syntax: logspace(a,b,n)
where a = lower limit, 10^a
b = upper limit, 10^b
n = number of points (default n=50)

Example:
>> logspace(0,2,4)
ans =
1.0000 4.6416 21.5443 100.0000

PART 2 OF 8 MATH2118 Further Eng Maths C 10


Creating Matrices

 Three ways to create a matrix in MATLAB:

Method 1:
Enter matrix row by row, separating the elements in a given row with
spaces or commas, and separating the rows with semicolons. For example,
>> [1,2,3; 4,5,6]
ans =
1 2 3
4 5 6
 1 2 3
represents the matrix, 4 5 6
 

PART 2 OF 8 MATH2118 Further Eng Maths C 11


Method 2:
Create a matrix from row or column vectors by appending vectors to a matrix, or two or
more vectors together.

Command [x y] combines the row vectors x and y to form a larger row vector.
For example,
>> x = [1,2,3];
y = [7,8,9];
>> r = [x y]
r =
1 2 3 7 8 9

Command [x;y] combines the two vectors to form a matrix. For example,
>> M = [x; y]
M =
1 2 3
7 8 9
PART 2 OF 8 MATH2118 Further Eng Maths C 12
Matrix M can also be created by (without creating new arrays first):
>> M = [[1,2,3];[7,8,9]]
M =
1 2 3
7 8 9

Example:
>> A = [1,2,3; 4,5,6;];
x = [7,8,9];
>> M = [A; x]
M =
1 2 3
4 5 6
7 8 9

PART 2 OF 8 MATH2118 Further Eng Maths C 13


>> M = [x; A]
M =
7 8 9
1 2 3
4 5 6
>> B = [-1,-2,-3; -4,-5,-6];
>> [A, B]
ans =
1 2 3 -1 -2 -3
4 5 6 -4 -5 -6
>> [A; B]
ans =
1 2 3
4 5 6
-1 -2 -3
-4 -5 -6

PART 2 OF 8 MATH2118 Further Eng Maths C 14


Create a new matrix by appending the second row of B to A:
>> [A; B(2,:)]
ans =
1 2 3
4 5 6
-4 -5 -6

Create a new matrix by combining the first column of both A and B:


>> [A(:,1) B(:,1)]
ans =
1 -1
4 -4

PART 2 OF 8 MATH2118 Further Eng Maths C 15


Method 3:
Create a new matrix by extracting portion of another matrix. For example,
>> M = [1,2,3,4; 5,6,7,8; 2,4,6,8; 1,3,5,7]
M =
1 2 3 4
5 6 7 8
2 4 6 8
1 3 5 7

>> G = M(1:3, 2:4) >> M = [M(1:2,1:3); M(4,1:3)]


G = H =
2 3 4 1 2 3
6 7 8 5 6 7
4 6 8 1 3 5
PART 2 OF 8 MATH2118 Further Eng Maths C 16
Array Editor

 MATLAB Workspace Browser provides a graphical interface for managing


the workspace, such as to view, save and clear workspace variables.

 Workspace Browser includes the Array Editor, a graphical interface for


managing assigned arrays.

 Workspace Browser can be activated by


 selecting Workspace from the View menu;
 double-clicking Workspace tab in the Launch Pad; or
 entering workspace at the Command Window prompt.

PART 2 OF 8 MATH2118 Further Eng Maths C 17


WORKSPACE

ARRAY EDITOR

PART 2 OF 8 MATH2118 Further Eng Maths C 18


Workspace Operations

 Viewing and editing the workspace variables


 Clearing workspace variables
 Plotting workspace variables
 Saving and loading workspace
 Displays the name of each variable, its array size, its size in bytes
and the class

PART 2 OF 8 MATH2118 Further Eng Maths C 19


Matrix Transpose Operation
 The transpose operation interchanges the rows and columns. For an m x n
matrix A with m rows and n columns, AT (read “A transpose”) is an n x m
matrix.
1 2  1 3 
For example, A    then AT
  .
3 4  2 4

 If AT  A, the matrix A is symmetric.


 MATLAB command for matrix transpose is ’. If the array elements are
complex, ’ produces the complex conjugate transpose, i.e. resulting
elements are complex conjugate of the original elements.
 To transpose the complex-valued array without producing complex
conjugate elements, use dot transpose operator .’.

PART 2 OF 8 MATH2118 Further Eng Maths C 20


Array Addressing

 Array indices are the row and column numbers of an element in an array.
 Examples (x is a vector, A is a matrix):
x(2) refers to the second element of x
x(:) refers to all the row or column elements of x
x(2:4) refers to the second to fourth elements of x, i.e. x(2), x(3) and x(4)
A(2,3) refers to the element in row 2 and column 3 of A
A(:,1) refers to all the elements in column 1 of A
A(2,:) refers to all the elements in row 2 of A
A(:,2:4) refers to all the elements in columns 2 thru 4 of A,
i.e. A(:,2), A(:,3) and A(:,4)
A(2:3,1:2) refers to all the elements in rows 2 and 3, that are also in
columns 1 and 2 of A

PART 2 OF 8 MATH2118 Further Eng Maths C 21


Empty Array

 Empty or null array contains no elements and is expressed as [] in MATLAB.


 We can use [] command to delete selected rows or columns of a matrix.
Examples:
>> A(1,:) = [] deletes the first row of matrix A
>> A(:,1:5) = [] deletes columns 1 thru 5 of matrix A
>> A([1 3],:) = [] deletes rows 1 and 3 of matrix A
>> A(:,[2 5]) = [] deletes columns 2 and 5 of matrix A

 MATLAB does not accept negative or zero indices.

PART 2 OF 8 MATH2118 Further Eng Maths C 22


Commands: min(A), max(A)
 For real-valued vector x, min(x) and max(x) return the algebraically smallest and greatest
element in vector x, respectively. For example,
>> x = [-2,5,1,8];
>> min(x)
ans =
-2
>> max(x)
ans =
8
 For complex-valued vector x, or any of the elements are complex, min(x) and max(x) return
the elements that has the smallest and largest magnitude, respectively. For example,
>> x = [-1-i,2,3+4i];
>> min(x)
ans =
-1.0000 – 1.0000i
>> max(x)
ans =
3.0000 + 4.0000i

PART 2 OF 8 MATH2118 Further Eng Maths C 23


 Similarly, for real-valued matrix A, the commands min(A)and max(A) return a row
vector containing the smallest and largest elements in each column of matrix A, or the
elements of the smallest and largest magnitude if any of the elements are complex.

Example:
>> A = [1,2,3; 4,5,6]
A =
1 2 3
4 5 6
>> min(A)
ans =
1 2 3
>> [y,k] = min(A)
>> [y,k] = max(A)
stores the minimum or maximum values in the row vector y and their indices in the row
vector k.

PART 2 OF 8 MATH2118 Further Eng Maths C 24


Commands: size(A), length(A)

 For an array of dimension m x n, MATLAB command size(A)returns a


row vector [m n].
 MATLAB command length(A)gives the number of elements of A if A
is a vector, or the largest value of m or n if A is an m x n matrix.

Example:
>> A = [1,2,3; 4,5,6];
>> size(A)
ans =
2 3
>> length(A)
ans =
3

PART 2 OF 8 MATH2118 Further Eng Maths C 25


Commands: find(A)

 MATLAB command find(A) generates an array containing the indices of the non-zero
elements of the array A (row-wise then column-wise).

Example:
>> A = [-1,0,2; 3,4,0; 0,0,2]
ans =
-1 0 2
3 4 0
0 0 2
>> find(A)
ans =
1
2
5
7
9
PART 2 OF 8 MATH2118 Further Eng Maths C 26
Multidimensional Arrays
 MATLAB 6 (or higher) supports multidimensional arrays.
Type >> help datatypes for more information.
 A three-dimensional array has the dimension m x n x q.
A four-dimensional array has the dimension m x n x q x r, etc.
The first two dimensions are the row and column, and third, fourth, etc., are
called pages. For example, type A(2,3,2) refers to the element in the row
2, column 3 of page 2.
 Multidimensional arrays can be created by extending two-dimensional
arrays, or by concatenating arrays using the cat command.
 MATLAB command ndims(A) can be used to check the number of
dimensions of matrix A.

PART 2 OF 8 MATH2118 Further Eng Maths C 27


Scalar-Array Addition & Subtraction
 When a scalar is added to or subtracted from an array, the scalar is added or subtracted
from each element in the array. For example,
1 2  1  2 2  2
3 4   2   3  2 4  2 
   
>> A = [1,2; 3,4];
>> A+2
ans =
3 4
5 6
>> A-2
ans =
-1 0
1 2

PART 2 OF 8 MATH2118 Further Eng Maths C 28


Array Addition & Subtraction
 Two or more arrays of identical size can be added or subtracted.
For example, 1 2   1 0  1  1 2  0
3 4   2  2   3  2 4  2
     
>> A = [1,2; 3,4];
B = [-1,0; 2,-2];
>> A+B
ans =
0 2
5 2
>> A-B
ans =
2 2
1 6

PART 2 OF 8 MATH2118 Further Eng Maths C 29


Scalar-Array Multiplication & Division
 To multiply or divide an array by a scalar, we use the normal multiplication
and division operators. For example,
>> A = [1,2; 3,4];
>> 2*A
ans =
2 4
6 8
>> A/2
ans =
0.5000 1.0000
1.5000 2.0000

 Each element is multiplied or divided by the scalar.

PART 2 OF 8 MATH2118 Further Eng Maths C 30


Array Multiplication
 Two types of array multiplications are defined in MATLAB:
A.*B element-by-element multiplication
A*B matrix multiplication
 Element-by-element multiplication
For matrices A and B, the symbol .* signifies that each element in A is
multiplied by the corresponding element in B.
 1 2  1 0
A  B 
 3 4  2  2
>> A = [1,2; 3,4];
B = [-1,0; 2,-2];
>> A.*B
ans =
-1 0
6 -8
PART 2 OF 8 MATH2118 Further Eng Maths C 31
 Matrix multiplication
 1 0
 1 2 B 
A   2  2
 3 4 
 1 2   1 0   1  4 0  4  3  4
AB       
 3 4  2  2  3  8 0  8  5  8

>> A = [1,2; 3,4];


>> B = [-1,0; 2,-2];
>> A*B
ans =
3 -4
5 -8
PART 2 OF 8 MATH2118 Further Eng Maths C 32
Array Division
 Array division (also called element-by-element division) can only be
performed on arrays having the same size, and the elements of one array
are divided by the elements of the other array. The MATLAB command for
this operation is ./ (array right division).
Example:
 1 2  1 0
A  ; B 
 3 4  2  2
>> A = [1,2; 3,4];
B = [-1,0; 2,-2];
>> B./A
ans =
-1.0000 0.0000
0.6667 -0.5000

PART 2 OF 8 MATH2118 Further Eng Maths C 33


Array Exponentiation
 In MATLAB, we can raise
arrays to powers,
scalars to array powers, and
arrays to array powers.
 To perform exponentiation on an element-by-element basis,
use .^ command. For example,
2
 1 2  12 2 2   1 4
A 
2
  2 2
 
 3 4 3 4   9 16 
>> A = [1,2; 3,4];
>> A.^2
ans =
1 4
9 16
PART 2 OF 8 MATH2118 Further Eng Maths C 34
 To raise a scalar to an array power, enter s.^A , where s is a scalar and
A is an array.

Example:
 21
2 2   2 4
2A   3 4
 
2 2   8 16 

>> A = [1,2; 3,4];


>> 2.^A
ans =
2 4
8 16

PART 2 OF 8 MATH2118 Further Eng Maths C 35


 To raise an array to an array power, enter A.^A , where A is an array.

Example:
 11
22   1 4
AA   3 4
 
3 4   27 256 

>> A = [1,2; 3,4];


>> A.^A
ans =
1 4
27 256

PART 2 OF 8 MATH2118 Further Eng Maths C 36


Vector Dot Product
 The vector dot product a  b of the vectors a and b is a scalar. It can be computed from
|a||b|cos, where  is the angle between the two vectors, and |a|, |b| are the magnitudes
of the vectors.

Given a  a1 , a2 , a3  and b  b1 , b2 , b3 , then


a  b  a1 , a 2 , a3   b1 , b2 , b3   a1b1  a 2 b2  a3b3

The same result can be obtained by matrix product of a row vector a and column vector b.
That is,
 b1 
a1 a2 a3  b2   a1b1  a 2 b2  a3b3
 
b3 

provided each vector has the same number of elements.

PART 2 OF 8 MATH2118 Further Eng Maths C 37


Example:
>> a = [1,2,3];
>> b = [-1; -2; -3];
>> a*b
ans =
-14

MATLAB command dot(a,b) computes the vector dot product of


vectors a and b, both of n elements. For the above example, enter
>> dot([1,2,3], [-1,-2,-3])
ans =
-14

PART 2 OF 8 MATH2118 Further Eng Maths C 38


Cross Product
 The cross product of two vectors, a and b, can be performed by MATLAB
command cross(a,b). For example, if a and b are vectors with three
elements, cross(a,b) computes the three-element vector that is the
cross product a x b.

Example:
>> a = [-1,2,-3];
b = [2,-6,9];
cross(a,b)
ans =
0 3 2

PART 2 OF 8 MATH2118 Further Eng Maths C 39


Special Matrices: Null Matrix
 The null matrix, denoted by 0, contains all zeros, and is not the same as the empty matrix
[], which has no elements.
Application: To initialise a matrix.

 MATLAB commands:
zeros(n) creates an n x n null matrix, i.e. n x n matrix of zeros
zeros(m,n) creates an m x n null matrix
zeros(size(A)) creates a null matrix having the same dimension as the matrix A

Example:
>> zeros(2)
ans =
0 0
0 0
 Property: 0A = A0 = 0

PART 2 OF 8 MATH2118 Further Eng Maths C 40


Special Matrices: Identity Matrix
 The identity or unity matrix, denoted by I, is a square matrix whose diagonals elements are
all one and zeros elsewhere.
 1 0 0
Example of a 3 x 3 identity matrix: I  0 1 0 
 
0 0 1
 MATLAB commands:
eye(n) creates an n x n identity matrix
eye(size(A)) creates an identity matrix having the same dimension as the matrix A

Example:
>> eye(2)
ans =
1 0
0 1
 Property: IA = AI = A

PART 2 OF 8 MATH2118 Further Eng Maths C 41


Special Matrices: Matrix of all Ones
 The following MATLAB commands create matrices filled with ones.

ones(n) creates an n x n matrix of ones


ones(m,n) creates an m x n matrix of ones
ones(size(A)) creates a matrix of ones having the same dimension as the matrix A

Examples:
>> ones(2)
ans =
1 1
1 1
>> ones(2,3)
ans =
1 1 1
1 1 1

PART 2 OF 8 MATH2118 Further Eng Maths C 42


Polynomials
 Mathematical notation: P ( x)  a1 x n  a2 x n 1  a3 x n  2    an x  an 1

Polynomial P(x) is a function of x and of degree or order n (highest power


of x in P(x)). The polynomial’s coefficients are denoted by a1 , a2 ,  , an , an 1

 In MATLAB, such polynomial is described by a row vector whose elements


are the polynomial’s coefficients in the following order: a1 , a2 , a3 ,  , an , an 1

 For example, for P ( x )  2 x 3  x  5, n = 3, a1  2, a 2  0, a3  1, a 4  5

The required vector is [2,0,-1,5].

PART 2 OF 8 MATH2118 Further Eng Maths C 43


 Addition of Polynomials

To add two polynomials, we add the corresponding polynomial’s coefficients.


For example, consider f ( x)  x 2  x  1 and g ( x )   x 2  2 x  3, f ( x)  g ( x)
produces f ( x)  g ( x)  x  4
>> f = [1,-1,1];
g = [-1,2,3];
f+g
ans =
0 1 4

If the polynomials are of different degrees, add zeros to the coefficient array of the
lower-degree polynomial.

PART 2 OF 8 MATH2118 Further Eng Maths C 44


 Multiplication of Polynomials by Scalars

To multiply a polynomial by a scalar, simply multiply the coefficient array by that scalar.

For example, 3 f ( x )  3( x 2  x  1)  3 x 2  3 x  3

In MATLAB:
>> f = [1,-1,1];
3*f
ans =
3 -3 3

PART 2 OF 8 MATH2118 Further Eng Maths C 45


 Multiplication of Polynomials

For example, to multiply f(x) and g(x), enter

>> conv(f,g)
ans =
-1 3 0 -1 3

The resulting polynomial is  x  x  x  3.


4 3

PART 2 OF 8 MATH2118 Further Eng Maths C 46


 Division of Polynomials

To divide polynomials, use MATLAB command deconv.


x3  2 x 2  5x  3
For example, to compute , enter:
x  3x  1
2

>> f = [1,-2,5,-3];
g = [1,-3,1];
[q,r] = deconv(f,g)
q =
1 1
r =
0 0 7 -4

That is, f  x  1  7 x  4 .
g x  3x  1
2

PART 2 OF 8 MATH2118 Further Eng Maths C 47


 Command: poly(r)

This command computes the coefficient of the polynomial whose roots are specified by the
vector r.

For example, for repeated roots of 1, i.e. x = 1,1, the required polynomial is
x  1x  1  x  12  x 2  2 x  1

In MATLAB:
>> r = [1,1];
poly(r)
ans =
1 -2 1

PART 2 OF 8 MATH2118 Further Eng Maths C 48


 Command: roots(a)

This command computes the roots of a polynomial specified by the coefficient array a.
The result is a column vector containing the polynomial’s roots.

For example, the roots of x 2  2 x  1  x  12 are x =1, 1.

In MATLAB:
>> roots([1,-2,1])
ans =
1
1

PART 2 OF 8 MATH2118 Further Eng Maths C 49


 Command: polyval(a,x)

This command evaluates a polynomial at specified values of its independent variable x,


which can be a matrix or a vector. The polynomial’s coefficients are stored in an array,
and the result is the same size as x.

For example, to compute f ( x )  x 2  2 x  1 at x = -1, 0, 1,


enter

>> f = [1,-2,1];
x = [-1,0,1];
polyval(f,x)
ans =
4 1 0

PART 2 OF 8 MATH2118 Further Eng Maths C 50


Programming in MATLAB

Dr Eddie Ly
BEng(Hons), BAppSc, PhD RMIT
School of Mathematical & Geospatial Sciences (SMGS)
College of Science, Engineering & Health (SEH)
RMIT University, Melbourne, Australia
Summer Course 2015

PART 6 OF 8 MATH2118 Further Eng Maths C 1


Introduction
MATLAB interactive mode is very useful for simple problem, or to test your
code line by line.

However, for more larger and complex problems, especially where problems
involved repeating a number of calculations over and over again, the
problem must be “coded” or “converted” into a computer program.

The program can be coded into a MATLAB script file.

PART 6 OF 8 MATH2118 Further Eng Maths C 2


Relational Operators
MATLAB has six relational operators to make comparisons between arrays.
Relational Operator Meaning
< less than
<= less than or equal to
> greater than
>= greater than or equal to
== equal to
~= not equal to

Note:
The equal to ‘==‘ operator consists of two equal signs, not a single equal sign.
A single equal sign represents the assignment, or replacement operator, in MATLAB.

PART 6 OF 8 MATH2118 Further Eng Maths C 3


Outcome
Using these relational operators return either 0 (zero) if the comparison is false, or 1 (one) if
it is true. The result can be used as a variable.

Examples:
>> 2<6 >> 3 == 4
ans = ans =
1 0

>> x = 2<1 >> t = [1,2,3];


x = >> t > 1
0 ans =

>> x 0 1 1
x = >> t >= 1
0 ans =
1 1 1

PART 6 OF 8 MATH2118 Further Eng Maths C 4


 The relational operators can be used for array addressing. For instance,
>> a = [1,2,3,4,5];
b = [1,2,0,8,5];
a(a==b)
ans =
1 2 5

 MATLAB performs arithmetic operators +, -, *, / and \ first, follow by the relational


operators in expressions where both type of operators exist. For example, x=1==1-2
is equivalent to x = 1==(1-2) and returns the value of x=0, i.e. false.

 The relational operators have equal precedence among themselves, and MATLAB
evaluates them in order from left to right.

PART 6 OF 8 MATH2118 Further Eng Maths C 5


Logical Operators
MATLAB has three logical operators (sometimes called Boolean operators).
These operators perform element-by-element operations.

NOT Operator
~ ~A returns an array the same dimension as A containing elements of one where
element of A is zero, and zero where A is nonzero. The NOT symbol is called the
tilde.

Example:
>> B = [2,0,1,5,0];
>> ~B
ans =
0 1 0 0 1

PART 6 OF 8 MATH2118 Further Eng Maths C 6


AND Operator
& A&B returns a new array of the same dimension as A and B containing ones when
both A and B have nonzero elements, and zeros where either A or B is zero.

Example:
>> A = [1,0,2,0,4];
B = [2,0,1,5,0];
>> A&B
ans =
1 0 1 0 0
>> 6&7 >> 0&0
ans = ans =
1 0
>> c&d
??? Undefined function or variable ’c’.

PART 6 OF 8 MATH2118 Further Eng Maths C 7


OR Operator
| A|B returns a new array of the same dimension as A and B containing ones where
at least one element in A or B is nonzero, and zeros where A and B are both zero.

Example:
>> A = [1,0,2,0,4];
B = [2,0,1,5,0];
>> A|B
ans =
1 0 1 1 1
>> 6|7 >> 0|0
ans = ans =
1 0
>> c|d
??? Undefined function or variable ’c’.

PART 6 OF 8 MATH2118 Further Eng Maths C 8


XOR Exclusive OR Function
xor(A,B) Returns a new array of the same dimension as A and B, and containing
elements of zeros where element of A and B are either both nonzero or
both zero, and ones where either A or B is nonzero, but not both.
Exclusive OR function can be defined in terms of the AND, OR and NOT
operators as follows:
function EORfun = xor(A,B)
EORfun = (A|B) & ~(A&B);

Example:
>> A = [1,0,2,0,4];
B = [2,0,1,5,0];
xor(A,B)
ans =
0 0 0 1 1
PART 6 OF 8 MATH2118 Further Eng Maths C 9
TRUTH TABLE
1 = truth
0 = false
>> X = [1,1,0,0]’;
Y = [1,0,1,0]’;
TT = [X, Y, ~X, X|Y, X&Y, xor(X,Y)]
TT =
1 1 0 1 1 0
1 0 0 1 0 1
0 1 1 1 0 1
0 0 1 0 0 0

X Y ~X X|Y X&Y xor(X,Y)


true true false true true false
true false false true false true
false true true true false true
false false true false false false

PART 6 OF 8 MATH2118 Further Eng Maths C 10


Order of Precedence for Operator Types
Precedence Operator Type
1 Evaluate terms inside brackets ( ), starting with innermost terms first.
2 Arithmetic operators and logical NOT operator, starting from left to right
3 Rational operators, starting from left to right
4 Logical AND operator
5 Logical OR and XOR operators

Example:
To enter the relation 1< x <2 in MATLAB, enter:
>> (1<x) & (x<2)

PART 6 OF 8 MATH2118 Further Eng Maths C 11


Examples:
>> h = 1&2+3 is equivalent to >> h = 1&(2+3)
h = h =
1 1

>> (1>0)&(2>3) is equivalent to >> 1>0&2>3


ans = ans =
0 0

>> (1==1)|3<0 is equivalent to >> 1==1|3<0


ans = ans =
1 1
Note:
Starting from MATLAB 6 onwards, the AND operator has a higher precedence than the OR operator.

PART 6 OF 8 MATH2118 Further Eng Maths C 12


Logical Functions
any(x) Returns a scalar, which is one if any of the elements in the vector x is
nonzero, and zero otherwise.
any(A) Similar to any(x), but returns a row vector having the same number of
columns as A, and containing ones in the column where the corresponding
column of A contains a nonzero element, and vice versa.
all(x) Returns a scalar, which is one if all the elements in the vector x are
nonzero, and zero otherwise.
all(A) Works similar to all(x), but returns a row vector have the same number
of columns as A.

Other related logical functions:


find(A), finite(A), isnan(A), isinf(A), isempty(A),
isreal(A), xor(A,B)

PART 6 OF 8 MATH2118 Further Eng Maths C 13


The if Statement
MATLAB conditional statements allow us to write programs that make
decisions. Conditional statements contain one or more of the if, else
and elseif statements.

Basic form of the if statement:


if logical expression
statements
end

Every if statements must have an accompanying end statement, where


the end statement terminates the end of the executable statements.

PART 6 OF 8 MATH2118 Further Eng Maths C 14


Example:
Given a real number x, compute log(x) for x >= 1.
if x >= 1
y = log(x)
end

Example:
Compute the square root of c if c is a positive number.
if c>0
sqrt(c)
end

PART 6 OF 8 MATH2118 Further Eng Maths C 15


The Nested if Statements
MATLAB also allows us to “nest” a group of if statements:
if logical expression 1
statement group 1
if logical expression 2
statement group 2
if logical expression 3
statement group 3
end
end
end
Each if statement has an accompanying end statement !
PART 6 OF 8 MATH2118 Further Eng Maths C 16
The else and elseif Statements
Use else and elseif statements together with the if statement to
make a decision where more than one action can occur:

if logical expression
statement group 1
else
statement group 2
end
When the test (if logical expression) is performed for an array, the test
returns a value of true only if all the elements of the logical expression are
nonzero !
PART 6 OF 8 MATH2118 Further Eng Maths C 17
Example:
Given a real number x, compute the square root of x. If x<0, return only the positive complex root.
if x >= 0
sqrt(x)
else
sqrt(abs(x))*I
end

Example:
if x >= 0
disp(’A non-negative number’)
else
disp(’A negative number’)
end

PART 6 OF 8 MATH2118 Further Eng Maths C 18


The elseif Statement
General form of the if statement:
if logical expression 1
statement group 1
elseif logical expression 2
statement group 2
else
statement group 3
end
The else statement must be located just before the end statement to
take care of all conditions that might be unaccounted for if the else and
elseif statements are employed.
PART 6 OF 8 MATH2118 Further Eng Maths C 19
Example:
Computing the roots of a quadratic function.
h = b^2-4*a*c;
if h>0
hs = sqrt(h);
x1 = (-b+hs)/(2*a);
x2 = (-b-hs)/(2*a);
else if h==0
x1 = -b/(2*a);
x2 = x1;
else
hs = sqrt(abs(h))*I;
x1 = (-b+hs)/(2*a);
x2 = (-b-hs)/(2*a);
end

PART 6 OF 8 MATH2118 Further Eng Maths C 20


Strings
 A string is a variable that contains characters, and created by enclosing the
characters in single quotes. For example,
>> uni = ’RMIT University’
uni =
RMIT University

 Strings are stored as row vectors in which each column represents a


character:
>> size(uni)
ans =
1 15
That is, uni has 1 row and 15 columns (including blank spaces).

PART 6 OF 8 MATH2118 Further Eng Maths C 21


 We access the characters of a string in the same manner as we access the elements of a vector.
For example, to extract the letter ’T’,
>> uni(4)
ans =
T

 To extract a group of letters, or a sub-string, enter:


>> abbrev = uni(1:4)
abbrev =
RMIT

 To insert characters into a string, enter:


>> uni2 = [uni(1:4),’-’,uni(6:15)]
uni2 =
RMIT-University

PART 6 OF 8 MATH2118 Further Eng Maths C 22


Command: findstr

 MATLAB command findstr (stands for ‘find string’) finds the locations
of certain characters of a given string.

Examples:
>> findstr(uni,’M’)
ans =
2
>> findstr(uni,’i’)
ans =
8 13

That is, the letter ‘i’ (lower case ‘i’) occurs in the 8th and 13th columns of
the string named ‘uni’.

PART 6 OF 8 MATH2118 Further Eng Maths C 23


Equality of Two Strings
 Two string variables are equal if and only if every character is the same,
including blank spaces. Note that uppercase and lowercase letters are
different. For example, hi is different to Hi.

 Command: strcmp
Use this command to compare two string variables.

Syntax: strcmp(’string1’,’string2’)
returns one if string1 is same as string2, and zero otherwise.

PART 6 OF 8 MATH2118 Further Eng Maths C 24


Command: lower(’string’), upper(’string’)

These commands convert the given string variable to all lowercase or all uppercase letters
(useful for accepting keyboard inputs involving letters).

Example:
rerun = input(’Try again (Y/N)?’, ’s’);
if (isempty(rerun))|(upper(rerun)==’Y’)
rerun = ’Y’
else
rerun = ’N’
end

Note:
The command isempty(x) returns a 1 if the array x is empty, and 0 otherwise.

PART 6 OF 8 MATH2118 Further Eng Maths C 25


Loops
A loop is a structure for performing a repetition of certain task, such as
computations and printings, over a number times, where each repetition is a
pass. There are two kinds of loops available in MATLAB:

for-loop
Repetitions where the number of passes is known in advance.

while-loop
Repetitions terminate when a specified condition is satisfied, and number of
passes is not known in advance.

PART 6 OF 8 MATH2118 Further Eng Maths C 26


for-Loops

Use for-loops structure to repeat a task or computations for a specified


number of times.

Syntax:
for loop_variable = m:s:n
statements
………
statements
end

A for statement needs an accompanying end statement, which marks


the end of the statements that are to be executed.
PART 6 OF 8 MATH2118 Further Eng Maths C 27
Initially, the loop structure will assign the value of m to the loop_variable.
The statements are executed once during each pass, using the current
value of the loop_variable.

The loop_variable then incremented by the step value or incremental value,


s, and the statements are executed again. This repetition process continues
until the loop_variable exceeds the terminating value n.

Note:
The loop_variable can be a scalar (most common type), vector or matrix.

PART 6 OF 8 MATH2118 Further Eng Maths C 28


Example:
>> for k = 1:2:10
x = 2*k
end

x = (for k=1)
2
x = (for k=1+2=3)
6
x = (for k=3+2=5)
10
x = (for k=5+2=7)
14
x = (for k=7+2=9)
18

PART 6 OF 8 MATH2118 Further Eng Maths C 29


The for-loop may be written on a single line. The previous example can be rewritten as

>> for k=1:2:10, x=2*k, end

But, this form is less readable than the previous form.

Note: (m:s:n)
(1) Step value, s, can be negative. For example, k=10:-2:1 produces k=10,8,6,4,2
(2) If s is omitted, s=1 by default.
(3) If s>0, the loop only executed if m<n since m:s:n
(4) If s<0, the loop only executed if m>n.
(5) If m=n, only one pass will be performed.

WARNING:
If s is not an integer, round-off errors can cause the loop to execute a different number of passes
than intended.

PART 6 OF 8 MATH2118 Further Eng Maths C 30


Example:
A MATLAB function for computing factorial of an integer.
function nfac = nfactorial(n)
if (n<0)
disp(’ Invalid input!’)
else
nfactorial = 1;
for k = 2:n
nfactorial = nfactorial*k;
end;
nfactorial
end;

PART 6 OF 8 MATH2118 Further Eng Maths C 31


Command: break

Use break command to terminate the looping process before the loop_variable reaches
its terminating value without stopping the entire program.

Example:
>> for k=1:2:10 | k = 1;
x = 50-k^2; | x = 5-1^2 = 49 (>10; cont)
if (x <= 10) | k = 1+2 = 3;
break | x = 50-3^2 = 41 (>10; cont)
else | k = 3+2 = 5;
y = sqrt(x) | x = 50-5^2 = 25 (>10; cont)
end; | k = 5+2 = 7;
end; | x = 50-7^2 = 1 (<10; stop!)

Note:
We can use the while-loop structure to perform the same task.

PART 6 OF 8 MATH2118 Further Eng Maths C 32


Command: continue

Suppose we want to just skip the pass where an error can occur (for
example, taking square root of a negative number), and continue executing
the loop for the remaining passes. We cannot use the break command,
because it will stop the execution of the loop rather than skipping the pass.

The continue statement passes control to the next iteration of the


for- or while-loop in which it appears, skipping any remaining
statements in the body of the loop. In nested loops, continue passes
control to the next pass of the for- or while-loop enclosing it.

PART 6 OF 8 MATH2118 Further Eng Maths C 33


Example:
A MATLAB program to remove all blank spaces from the word ‘R M I T’.

>> str = ’R M I T’;


str2 = [];
for k=1:length(str)
if (str(k)==’ ’)
continue
else
str2 = [str2,str(k)];
end;
end;
str2

str2 =
RMIT
>> length(str2)
ans =
4

PART 6 OF 8 MATH2118 Further Eng Maths C 34


Implied Loops
Many MATLAB commands contain implied loops.

Example:
>> x = [0:2:8];
y = x.^2
y =
0 4 16 36 64

To achieve the same result using a for loop, enter:


>> for k = 1:5
x = 2*(k-1);
y(k) = x^2;
end;
>> y
y =
0 4 16 36 64
PART 6 OF 8 MATH2118 Further Eng Maths C 35
while-Loops
Use while-loops structure to terminate a looping process because a
specified condition is satisfied.

Syntax:
while logical expression
statements
………
statements
end

A while statement needs an accompanying end statement, which


marks the end of the statements thatare to be executed.
PART 6 OF 8 MATH2118 Further Eng Maths C 36
while-loop is used when we want the loop to continue as long as a certain statement is true.
Such a task is often more difficult to do with a for-loop.

Example:
>> x = 32;
while (x>1)
x = x/2
end;
x =
16
x =
8
x =
4
x =
2
x =
1
PART 6 OF 8 MATH2118 Further Eng Maths C 37
For the while-loop to function properly, the following two conditions must occur:

(1) The loop_variable must have a value before the while statement
is executed;
(2) The loop_variable must be changed somehow by the statements.

The statements are executed once during each pass, using the current value
of the loop_variable. The looping continues until the logical expression is false.

Note:
Always make sure that the loop_variable has a value assigned to it before
the start of the loop.

PART 6 OF 8 MATH2118 Further Eng Maths C 38


switch Structure
switch structure provides an alternative to using the if, elseif and else commands.
Anything programmed using the switch can also be programmed using if structures.
However, the switch structure is more readable than code using the if structure.

Syntax:
switch input expression (scalar or string)
case value_1
statement_group_1
case value _2
statement_group_2
.. .. ..
otherwise
statement_group_n
end

PART 6 OF 8 MATH2118 Further Eng Maths C 39


 The input expression is compared to each case value. If they are the same, then the
statements for that particular case statement are executed, and processing continues
with any statements after the end statement.

 If the input expression is a string, then it is equal to the case value if strcmp returns a
one (for true).

 Only the first matching case is executed. If no match occurs, the statements for the
otherwise statement are executed. The otherwise statement is optional, and if
omitted the execution continues with the statements after the end statement if no match
exists.

 Each case value statement must be on a single line.

PART 6 OF 8 MATH2118 Further Eng Maths C 40


Example:
>> x = 2;
switch x
case (x>0)
disp(‘ x is positive.‘);
case (x==0)
disp(‘ x is zero.‘);
case (x<0)
disp(‘ x is negative.‘);
end;
>> x = 2;
switch x
case (x>0)
disp(‘ x is positive.‘);
case (x==0)
disp(‘ x is zero.‘);
otherwise
disp(‘ x is negative.‘);
end;

PART 6 OF 8 MATH2118 Further Eng Maths C 41


Example:
Write a MATLAB program using the switch structure to input one angle, whose value may be 45, –
45, 135, or –135 degrees, and display the quadrant (1, 2, 3 or 4) containing the angle.

function quad = angle(x)


while (x<0)
x = x+360;
end;
switch x
case {0,45,90,360}
disp(’ QUADRANT 1’);
case {135,180}
disp(’ QUADRANT 2’);
case {225,270}
disp(’ QUADRANT 3’);
case 315
disp(’ QUADRANT 4’);
end;

PART 6 OF 8 MATH2118 Further Eng Maths C 42

Вам также может понравиться