CMPE 203 Numerical Methods
CMPE 203 Numerical Methods
ACCURACY. Accuracy refers to how close a measurement is to the o 234.87 – Since the number to the right of 8 is 7, this will
true or accepted value. become 234.9
1. Every non-zero numbers are ALWAYS significant figures. o 78.657 – The number to the right of 6 is 5. And the number
to its right is a non-zero, therefore, it will become 78.7
E.g.
o 846 has 3 sigfigs
4. If the number to the immediate right of the last significant is a 5,
and that 5 is followed by a zero, you look at the last
2. Zeroes in-between non-zero numbers are ALWAYS significant. significant digit and make it even.
E.g. E.g.
o 704 has 3 sigfigs o 2.5350 – The number to the right of 3 is 5. And the number
o 5006 has 4 sigfigs to its right is 0. The 3 will become 2.54.
o 2.5250 – If the number is already even, it is what it is. In
this case, it will be 2.52.
3. Trailing zeroes, or the zeroes to the right of non-zero numbers, are
siginificant only if there’s a decimal point.
E.g. SCIENTIFIC NOTATIONS
o 500 has 1 sigfig A useful way to represent very huge/very small numbers.
o 500. has 3 sigfigs E.g.
o 500.050 has 6 sigfigs
o 45000 = 4.5 × 104
o 3750 = 4.75 × 103
4. Leading zeroes, zeroes to the left, are NEVER significant. o 580000 = 5.8 × 105
o 0.0023 = 2.3 × 10−3
E.g.
o 0.00076 = 7.6 × 10−4
o 006 has 1 sigfig
o 0.0067 has 2 sigfigs
o 0.05087 has 4 sigfigs
o 0.0508700 has 6 sigfigs
ROOT FINDING
5. All counting numbers and constants have an infinite number of Solving for 𝑥 such that 𝑓(𝑥) = 0. Root is where the function
significant digits. becomes zero; it’s point intesecting the x-axis.
E.g. E.g. 𝑥 2 − 4𝑥 + 4 = 0
o 1 hour = 60 minutes (𝑥 − 2)2 = 0
o 12 inches = 1 foot
o 24 hours = 1 day √(𝑥 − 2)2 = √0
𝑥−2=0
1. If the digit to the immediate right of the last significant digit is less But in numerical methods, there are two (2) categories for root-
than 5, do not round up the last significant digit. finding;
𝑓(1) = 𝑒 −1 − 1
𝑓(𝑥𝑅 ) = −0.632
Take note that 𝑥𝐿 < 𝑥𝑅
Now, that there are three (3) values for 𝑥; 𝑥𝐿 , 𝑥𝑅 , 𝑥𝑀 . There will 𝑓(𝑥𝑀 ) = 0.107
be a new region, hence, it is called the bisection method.
i 𝑥𝐿 𝑥𝑅 𝑓(𝑥𝐿 ) 𝑓(𝑥𝑅 ) 𝑥𝑀 𝑓(𝑥𝑀 ) In mathematical expression, the formula for this is;
0.5 + 1
𝑥𝑚𝑖𝑑 = = 0.75
2
1
𝑥𝑀 = 0 + (1 − 0) ( ) = 0.613
Since 𝑓(𝑥𝑀 ) is now approaching zero 0. It’s safe to conclude 1 + 0.632
that the value of x, that will make the function equivalent to 0, is 1
appriximately equal to 0.5625. 𝑥𝑀 = 0 + (0.613 − 0) ( ) = 0.572
1 + 0.071
1
𝑥𝑀 = 0 + (0.572 − 0) ( ) = 0.5677
1 + 0.0076
FALSE-POSITION METHOD
This method has the same process with bisection method excpet
on how to get the new 𝑥𝑀 . This method uses Linear Interpolation to With 𝑥𝑀 approaching 0, root value is approximately 0.5677.
get 𝑥𝑀 .
Under open methods, there are two (2) different methods; SECANT METHOD
1. Newton-Raphson Method
In this method, there are 2 guess values; 𝑥𝑎 and 𝑥𝑏 (depends on us)
2. Secant Method
3. Incremental Search Method 𝑓(𝑥𝑎 )(𝑥𝑎 − 𝑥𝑏 )
4. Fixed-Point Iteration Method 𝑥𝑛𝑒𝑤 = 𝑥𝑎 −
𝑓(𝑥𝑎 ) − 𝑓(𝑥𝑏 )
E.g. 𝑥 2 − 𝑥 − 1 = 0
i 𝑥𝑎 𝑥𝑏 𝑓(𝑥𝑎 ) 𝑓(𝑥𝑏 ) 𝜀
Guess value: 𝑥 = 1
1 3 2 5 1
𝑓(𝑥) = 𝑥 2 − 𝑥 − 1
2 2 1.75 1 0.3125 50%
𝑓 ′ (𝑥) = 2𝑥 − 1
… … … … … …
i 𝑥𝐿 𝑓(𝑥𝑜𝑙𝑑 ) 𝑓′(𝑥𝑜𝑙𝑑 )
1.61803 1.61803 0 0 0.000%
1 1 -1 1
−1
𝑥𝑛𝑒𝑤 = 1 − =2
1
i 𝑥𝐿 𝑓(𝑥𝑜𝑙𝑑 ) 𝑓′(𝑥𝑜𝑙𝑑 )
1 1 -1 1
2 2 1 3
2 -1 -0.5
n … -0.618
i 𝑥 𝑓(𝑥𝑜 )
1 1.5 -0.25
The process will be repeated once a desired accuracy is
2 1.505 -0.239975 achieved. In this case, if you substitute -0.618 to thhe formed
3 1.51 -0.2299 equation, you’ll get the same thing, -0.618, hence the definition of
accuracy.
4 1.515 -0.219775
Therefore, 𝑥 = −0.618
5 1.52 -0.2096
… … …
n 1.61 -0.0179 But in this method, the roots is dependent on how 𝑔(𝑥) is
expressed. There could be many forms of a function.
… 1.615 -0.006775
Let’s say, if;
… 1.62 0.0044
𝑥2 − 𝑥 − 1
𝑥2 = 𝑥 + 1
Now, that there is a change from 1.615 to 1.62, that means that there
is a root between that interval. Therefore, we can say that 1
𝑥 = 1+
𝑥 ≈ 1.6185 𝑥
This value of x is a guess value within the interval because any value i 𝑥 𝑔(𝑥)
within that can be the answer. 1 1 2
2 2 1.5
… … …
n … 1.618
FIXED-POINT METHOD
Let’s form another 𝑥 = 𝑔(𝑥)
In this method, there is an initial guess value 𝑥𝑜 and a form:
𝑥2 − 𝑥 − 1
𝑥 = 𝑔(𝑥)
𝑥 = 𝑥2 − 1
𝑥𝑛𝑒𝑤 = 𝑔(𝑥𝑜 )
i 𝑥 𝑔(𝑥)
1 1 0
E.g. 𝑥 2 − 𝑥 − 1 = 0
2 0 -1
STEP 1. Express the equation into 𝑥𝑜 = 𝑔(𝑥) 3 -1 0
𝑥2 − 𝑥 − 1 4 0 -1
𝑥2 − 𝑥 = 1
If this is the case, then don’t use this function.
𝑥(𝑥 − 1) = 1
1
𝑥=
𝑥−1
1
STEP 2. Let’s say 𝑥𝑜 = 0, substitute that to 𝑔(𝑥) which is 𝑥−1
MATRICES AND DETERMINANTS 7. ZERO or NULL MATRIX is a matrix wherein all elements
are zero.
0 0 0
[0 0 0]
MATRIX 0 0 0
A rectangular array of numbers enclosed within brackets or quantity
and arranged in “m” rows and “n” columns. Each number in the
matrix is called an element. 8. TRIANGULAR MATRIX is a square matrix whose
elements above the principal diagonal (or below the
principal diagonal) are zero.
1 7 9
[0 2 4]
0 0 4
1 0 0
The number 𝑎11 ........... 𝑎𝑚𝑛 are called the elements of the [4 2 0]
matrix. The horizontal lines are called rows and the vertical lines are 1 2 4
called columns of the matrix. Thus, 𝑎𝑖𝑗 is the elements in the ith row
and the jth column of A. Size: 𝒎 𝒙 𝒏
PROPERTIES OF MATRIX
TYPES OF MATRICES EQUALITY OF MATRICES. Two matrices A and B are equal if they
1. SQUARE MATRIX is a matrix in which the number of rows are of the same order and corresponding elements are equal. When m
equals the number of column. = n, it is a square matrix. An n x n or a square matrix is said to be of
1 3 4 order “n”. The number associated with a square matrix is called a
[5 2 4] determinants.
1 9 6
3. ROW MATRIX is a matrix having only one row and “n” To multiply matrices, the inner dimension must be equal.
columns. It is called a“row vector”. ⬚ ⬚
𝐴 = [⬚ ⬚] 𝐵 = [⬚ ⬚ ⬚]
[2 4 7] ⬚ ⬚ ⬚
⬚ ⬚
𝐴: 3 𝑥 2 𝐵: 2 𝑥 3
4. COLUMN MATRIX is a matrix with “m” rows and only one
column. It is also called a column vector.
Their inner dimensions are both 2. Thefore, A and B can be multiplied.
2
The final dimension would be their outer dimensions. Therefore, it’s
[4 ]
7 3𝑥3
1 2
7 8 2
𝐴 = [3 4] 𝐵=[ ]
5. DIAGONAL MATRIX is a square matrix for which every 9 10 1
5 6
term off the main diagonal is zero.
1 0 0 Multiply row 1 and column 1 since it’s position in the output matrix is
[0 3 0] on row 1 column 1
0 0 4 1(7) + 2(9) = 25
MATRIX DETERMINANTS
3 −2 2 5
1 4 −2 −2 0 3
𝑑𝑒𝑡𝐴 𝑜𝑟 |𝐴| = | | = 𝑎𝑑 − 𝑏𝑐 𝐴=[ ]
6 8 −2 0 1 −3
= 1(8) − 4(6) = −16 −3 3 2 4
• Proceed to the process.
For 3 𝑥 3 matrices
1 3 4 MINORS OF A MATRIX
𝐴 = |5 2 4| E.g. Solve for 𝑚22 (minor of row 2 col 2)
1 9 6
1 3 4
1 3 4 1 3 1 3 4 1 3
𝐴=5 2 4
5 2 4 5 2 − 5 2 4 5 2
1 9 6
1 9 6 1 9 1 9 6 1 9
Delete row 2 and col 2
1 3 4
[1(2)(6) + 3(4)(1) + 4(5)(9)] 1 4
𝐴=5 2 4=
− [4(2)(1) + 1(4)(9) + 3(5)(6)] 1 6
1 9 6
= 204 − 134 = 70
𝑚22 = 1(6) − 4(1) = 2
For 4 𝑥 4 matrices
COFACTORS OF A MATRIX
PIVOTAL METHOD
The cofactor of a matrix with elements is equal to the minors
1 3 6 −2 multiplied by (−1)𝑟+𝑐
3 2 7 −5
𝐴=[ ] 𝑪𝒎𝒏 = (−𝟏)𝒎+𝒏 (𝒎𝒎𝒏 )
4 5 5 4
6 −3 −3 6
𝑷𝒊𝒗𝒐𝒕𝒂𝒍 𝑬𝒍𝒆𝒎𝒆𝒏𝒕 = 𝟏 1 4
𝑚22 = =2
1 6
TRANSPOSE OF A MATRIX
2 − 3(3) 7 − 3(6) −5 − 3(−2)
1+1 It is the interchange of rows and columns of matrix, denoted by 𝐴𝑇
= (−1) | 5 − 4(3) 5 − 4(6) 4 − 4(−2) |
−3 − 6(3) −3 − 6(6) 6 − 6(−2) 𝑎 𝑏 𝑐 𝑎 𝑑 𝑔
𝐴=𝑑 𝑒 𝑓 𝐴𝑇 = 𝑏 𝑒 ℎ
𝑔 ℎ 𝑖 𝑐 𝑓 𝑖
−7 −11 1
= [ −7 −19 12]
−21 −39 18
ADJOINT OF A MATRIX SOLUTIONS TO SYSTEMS OF LINEAR
Example: EQUATIONS
3 6 2 𝐶11 𝐶12 𝐶13 CRAMER’S RULE
𝐴 = 4 7 −1 𝐴𝑑𝑗 𝐴 = 𝐶21 𝐶22 𝐶23
5 1 3 𝐶31 𝐶32 𝐶33 det 𝐴𝑥𝑛
𝑥𝑛 =
det 𝐴
Example:
7 −1
𝐶11 = (−1)1+1 [ ]
1 3 2𝑥 + 𝑦 − 𝑧 = 1
𝐶11 = (−1)1+1 [7(3) − 1(−1)] = 22 𝐴 = [ 3𝑥 − 𝑦 + 𝑧 = 4 ]
2𝑥 + 3𝑦 + 𝑧 = 3
22 𝐶12 𝐶13
STEP 1. Transform to augmented
𝐴𝑑𝑗 𝐴 = 𝐶21 𝐶22 𝐶23
𝐶31 𝐶32 𝐶33 2 1 −1 1
𝐴 = 3 −1 1 4
2 3 1 3
After finding all the cofactors, transpose the matrix and that will be
𝐴𝑥 = 𝐵
the adjoint of A.
4 −5
𝐴𝑇 = [ ]
2 3 3.1. Replace 𝐴𝑧 by 𝐵 where 𝐴𝑧 is the third column of 𝐴, then get
the determinant
2 1 1
4 −5
[ ] 𝐴 = 3 −1 4
𝐴−1 = 2 3 = [0.18 −0.22
]
0.09 0.14 2 3 3
22
det 𝐴𝑧 = [−6 + 9 + 8] − [−2 + 9 + 24] = −20
det 𝐴𝑥 −20
𝑥= = =1
det 𝐴 −20
det 𝐴𝑦 0
𝑦= = =0
det 𝐴 −20
det 𝐴𝑧 −20
𝑧= = =1
det 𝐴 −20
GAUSS-JORDAN METHOD 1 0 0 1
𝐴=0 1 0 2
Example: 0 0 1 3
𝑥 + 3𝑦 + 𝑧 = 10
𝐴 = [ 𝑥 − 2𝑦 − 𝑧 = −6 ]
2𝑥 + 𝑦 + 2𝑧 = 10 Example 2:
𝑥+𝑦+𝑧=4
𝐴 = [ 2𝑥 − 3𝑦 + 𝑧 = 2 ]
STEP 1. Transform to augmented −𝑥 + 2𝑦 − 𝑧 = −1
1 3 1 10
𝐴=1 −2 −1 −6
2 1 2 10 1 1 1 4
𝐴 = 2 −3 1 2
𝐴𝑥 = 𝐵 −1 2 −1 −1
𝑅2′ = 𝑅2 − 2𝑅1
STEP 2. 𝐴 must be an identity matrix. Formulate an equation to do 𝑅3′ = 𝑅3 + 𝑅1
that.
1 3 1 10
𝐴=1 −2 −1 −6 1 1 1 4
2 1 2 10 𝐴=0 −5 −1 −6
0 3 0 3
Solve the first column first
𝑅2′ = −𝑅1 + 𝑅2
Interchange 𝑅2 and 𝑅3
𝑅3′ = −2𝑅1 + 𝑅3
1 1 1 4
𝐴=0 3 0 3
0 −5 −1 −6
1 3 1 10
𝐴 = 0 −5 −2 −16 𝑅2 ′
𝑅2′′ =
0 −5 0 −10 3
Interchange 𝑅2 and 𝑅3 1 1 1 4
𝐴=0 1 0 1
1 3 1 10 0 −5 −1 −6
𝐴 = 0 −5 0 −10
0 −5 −2 −16 𝑅1 ′ = 𝑅1 − 𝑅2 ′′
𝑅2 ′ 𝑅3′′ = 𝑅3 ′ + 5𝑅2 ′′
𝑅2′′ =
−5
1 0 1 3
1 3 1 10 𝐴=0 1 0 1
𝐴=0 1 0 2 0 0 −1 −1
0 −5 −2 −16
𝑅3 ′′
𝑅3′′ = 𝑅3 ′ + 5𝑅2 ′′ 𝑅3′′′ =
−1
𝑅1 ′ = 𝑅1 − 3𝑅2 ′′
1 0 1 3
𝐴=0 1 0 1
1 0 1 4 0 0 1 1
𝐴=0 1 0 2
0 0 −2 −6 𝑅1 ′′ = 𝑅1 ′ − 𝑅3 ′′′
𝑅3 ′′
𝑅3′′′ =
−2 1 0 0 2
𝐴=0 1 0 1
0 0 1 1
1 0 1 4
𝐴=0 1 0 2
0 0 1 3
𝑅1 ′′ = 𝑅1 ′ − 𝑅3 ′′′
Example 3:
2𝑥 + 𝑦 − 𝑧 = 1
𝐴 = [ 3𝑥 − 𝑦 + 𝑧 = 4 ]
2𝑥 + 3𝑦 + 𝑧 = 3
2 1 −1 1
𝐴 = 3 −1 1 4
2 3 1 3
𝑅1
𝑅1′ =
2
1 1 1
1 −
𝐴= 2 2 2
3 −1 1 4
2 3 1 3
𝑅2′ = 𝑅2 − 3𝑅1
𝑅3′ = 𝑅3 − 2𝑅1
1 1 1
1 −
2 2 2
𝐴= 5 5 5
0 −
2 2 2
0 2 2 2
−2
𝑅2′′ = 𝑅 ′
5 2
1 1 1
1 −
𝐴= 2 2 2
0 1 −1 −1
0 2 2 2
1
𝑅1′′ = 𝑅1 ′ − 𝑅2 ′′
2
𝑅3′′ = 𝑅3 ′ − 2𝑅2 ′′
1 0 0 1
𝐴 = 0 1 −1 −1
0 0 4 4
𝑅3 ′′
𝑅3′′′ =
4
1 0 0 1
𝐴 = 0 1 −1 −1
0 0 1 1
𝑅2′′′ = 𝑅2′′ + 𝑅3′′′
1 0 0 1
𝐴=0 1 0 0
0 0 1 1