Nume - Lesson 1
Nume - Lesson 1
NUMERICAL METHODS
PREVIEW OF TOPICS
Root-finding (Nonlinear systems)
Solve for x so that f(x) = 0.
Curve fitting
Integration
Differentiation
Differential Equations
Given
PROGRAMMING
Process of creating a set of instructions that tell a computer how to perform a task
Done for automation purposes
“Garbage in, garbage out” / GIGO
PROGRAMMING LANGUAGES/SOFTWARES
C/C++, Java, SQL, VBA, Python
Mathcad, MATLAB, Octave, Maple, Mathematica
TERMINOLOGIES
Algorithm
o Sequence of logical steps required to perform a specific task
Pseudocode
o English description of a program
Flowchart
o Visual/graphical representation of a program
Pseudocode
NOTES:
For clarity:
o Put comments to explain variables, purpose of code segments, etc.
For testing:
o Run with typical data.
o Run with unusual but valid data.
o Run with invalid data to check error handling.
Refresh your programming knowledge.
Find an introductory level programming book in the library/internet; check for tutorials.
Approach the problem through the algorithm-pseudocode-computer code link.
Practice at home (or during your free time).
Do not be afraid of programming; try to feel the power of it. =)
ERRORS
SIGNIFICANT FIGURES
o Digits of the number which are known to be correct
o Designate the reliability of a number
o *The number of significant figures to be used in a number depends on the origin
of the number.
o EXAMPLE: Calculation of the area of a circle A= πD2 / 4
ACCURACY and PRECISION
o Computers used to obtain numerical solution are imperfect tools; limited to
represent the magnitudes and precision of numbers.
o Errors from calculations (and measurements) can be characterized with regard
to their accuracy AND precision.
Precision
o How closely a computed (individual) or measured values agree with each other
Accuracy
o How closely a computed or measured value agrees with the true value
Imprecision
o Also called uncertainty
o Magnitude of the scatter
Inaccuracy
Also called bias
Systematic deviation from the truth
*ERROR = Imprecision + Inaccuracy
NOTES:
Precision is governed by the number of digits being carried in the numerical
calculations.
Accuracy is governed by the errors in the numerical approximation.
ERROR DEFINITIONS
TRUE ERROR (ET)
o Exact/absolute value of the error
o Doesn’t consider order of magnitude of the value under examination
ET = True Value- Approximation
o The error can be normalized to the true value
NOTES:
Many numerical methods work in an iterative* fashion, thus there should be a stopping
criterion for these methods.
The process stops when the error level drops below a certain specified tolerance value
(εs).
o These errors cannot be totally eliminated, but clever algorithms may help to
minimize them.
TOTAL NUMERICAL ERROR
o Summation of the truncation and round-off errors
ERROR TYPES
OTHER SOURCES OF ERRORS
Gross Errors/Blunders
Model Errors
Data Uncertaint
Python as a CALCULATOR
“+” for addition
“-” for subtraction
“/” for division
“*” for multiplication
“**” for exponentiation
ASSIGNING VARIABLES
x=1
x = 1.2
x = ‘one’
x = (1, 2, 3)
x = [1,2,3]
COMPARISON OPERATORS
DATA STRUCTURE
LIST SLICING
** List slicing is [start point: end point]
x = [ 1,2,3,4]
x[0:2]
x[1:4]
x[2:4]
x[1:3]
TUPLES
Tuples are just like lists, except you define a tuple with parentheses instead of square
brackets.
Tuples are immutable which means that once created they cannot be modified in any
way.
x = (1,2,3)
SETS
Sets are like lists and tuples but are defined by curly brackets. It obeys mathematical
set definitions.
primes = {2,3,5,7} ; odds = {1,3,5,7,9}
primes.union(odds) #combine primes and odds
primes.intersect(odds)
primes.difference(odds)
LESSON 2
OUTLINE
Review of Matrix Concepts
System of Linear Equations
Types of Solution
Introduction to Methods
Direct Methods
o Gauss Elimination
o Gauss-Jordan Elimination
o LU Decomposition
o Inverse Method
o Cramer’s Rule
Square Matrix (m = n)
o Order of Matrix
o Principal (or Main) Diagonal
Diagonal Matrix
o Square matrix that is both an upper triangular and lower triangular matrix
o (aij = 0 for i ≠ j)
Identity Matrix
o Diagonal matrix where all elements along the main diagonal are equal to 1
o Represented by In
Null Matrix
o Matrix where all elements are zero
o Represented by O
Symmetric Matrix
o gij = gji
Tridiagonal Matrix
o All elements not on the principal diagonal or on the two diagonals surrounding
the principal diagonal are zero
Sparse Matrix
o Most of the elements are zero
o Usually seen in engineering and scientific applications
MATRIX PROPERTIES
Let O = null matrix; I = identity matrix
Matrix Addition
o A + O = A [Additive Identity]
o A + (-A) = O [Additive Inverse]
o A + B = B + A [Commutative Property]
o (A + B) + C = A + (B + C)
[Associative Property]
Matrix Multiplication
o A(BC) = (AB)C [Associative Property]
o A(B + C) = AB + AC [Left Distributive]
≠ BA + CA
o (A + B) C = AC + BC [Right Distributive]
o AI = IA = A [Multiplicative Identity]
Scalar Multiplication
o ФxA=O
o 1xA=A
o kI(A) = k(IA) = I(kA)
o (k + I)A = kA + IA
o k(A + B) = kA + kB
*where Ф = zero (scalar)