01 Modeling, Computers, And Error Analysis
01 Modeling, Computers, And Error Analysis
and Error
Analysis
• Mathematical model
Outli • Computer-aided numerical calculations
• Errors
ne
Eg
g
• An egg can be cooked as soft-
boiled or hard-boiled depending
on how it is cooked.
Eg
g
(𝑀 ≈ 57 𝑔) at room temperature (𝑇𝑒𝑔𝑔 = 21 °𝐶) in boiling water (𝑇𝑤𝑎𝑡𝑒𝑟 =
• According to The Science of Boiling an Egg by Charles D. H. Williams, a medium egg
− 𝑇 𝑟
�
𝜆 𝑐𝜌1/
=
3 4 2/3
𝜋2 3
𝜋
𝜅
Mathematical
Model
𝐷𝑒𝑝𝑒𝑛𝑑𝑒𝑛𝑡
𝑖𝑛𝑑𝑒𝑝𝑒𝑛𝑑𝑒𝑛𝑡
𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒 , 𝑝𝑎𝑟𝑎𝑚𝑒𝑡𝑒𝑟𝑠, 𝑓𝑜𝑟𝑐𝑖𝑛𝑔
=𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑠
𝑓 𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛𝑠
• Dependent variable – characteristic that usually
reflects the behavior or state of the system
• Independent variables – dimensions along which
the system’s behavior is determined
• Parameters – reflects the system’s properties or
composition
• Forcing functions – external influences acting
upon the system
Mathematical
Model
• The actual mathematical expression can range
from a single algebraic relationship to large
complicated sets of differential equations.
𝐹 = 𝑚𝑎
• Example: Newton’s 2nd Law of Motion
𝑎 �
�
�
=
�
Mathematical
Model
• What if we want to predict the velocity of a falling
of time, 𝑣(𝑡)?
parachutist near the Earth’s surface as a function
𝑑𝑣
𝑎 𝐹 =
𝑑𝑡
=
𝐹 =𝑚 𝐹𝐷 + 𝐹𝑈
𝐹𝐷 = 𝑚𝑔 𝑔𝑟𝑎𝑣𝑖𝑡𝑦
𝐹𝑈 = −𝑐𝑑𝑣 (𝑎𝑖𝑟
𝑑𝑣 𝑚𝑔 − 𝑐𝑑𝑣 𝑐𝑑
𝑟𝑒𝑠𝑖𝑠𝑡𝑎𝑛𝑐𝑒)
= =𝑔
𝑑𝑡 − 𝑚 𝑣
𝑚
Mathematical
Model
• What if we want to predict the velocity of a falling
of time, 𝑣(𝑡)?
parachutist near the Earth’s surface as a function
𝑑
Mathematical
Model
• A parachutist of mass 68.1 kg jumps out of a
stationary hot air balloon. Compute velocity prior
to opening the chute. The drag coefficient is
equal to 12.5 kg/s.
Mathematical
• Aside from Newton’s second
law, there are other major Model
organizing principles in
engineering.
• Among the most important of
these are the conservation
𝐶ℎ𝑎𝑛𝑔𝑒
laws.
= 𝑖𝑛𝑐𝑟𝑒𝑎𝑠𝑒𝑠 −
𝑑𝑒𝑐𝑟𝑒𝑎𝑠𝑒𝑠
Mathematical
• Aside from Newton’s second
law, there are other major Model
organizing principles in
engineering.
• Among the most important of
these are the conservation
𝐶ℎ𝑎𝑛𝑔𝑒
laws.
= 𝑖𝑛𝑐𝑟𝑒𝑎𝑠𝑒𝑠 −
𝑑𝑒𝑐𝑟𝑒𝑎𝑠𝑒𝑠
Computer-aided
numerical
calculations
• Computer-aided numerical calculations or simply
Numerical Methods are techniques by which
Math problems are formulated in order to be
solved using arithmetic and logical operations.
• Reduces higher Math to basic arithmetic
operations
• Greatly expands the types of problems to be
solved
• Large systems of equations
• Nonlinear systems
• Complicated geometries
Computer-aided
numerical
calculations
• Computer-aided numerical calculations or simply
Numerical Methods are techniques by which
Math problems are formulated in order to be
solved using arithmetic and logical operations.
• Efficient way to learn how to use computers
• Numerical methods are designed for computer
implementation
• Allows the designing of programs/scripts to
solve
problems involving Mathematical models
Computer-aided
numerical
calculations
• Programming – process of creating a set of
instructions that tells a computer how to perform
a task
• Done for automation purposes
• Programming languages/softwares
• C, C++, Java, SQL, VBA, Python
• Mathcad, MATLAB, Octave, Maple,
Mathematica
Computer-aided
numerical
calculations
• Algorithm – sequence of logical steps required to
perform a specific task
• Pseudocode – worded description of a program
(usually in English)
• Flowchart – visual/graphical representation of a
program
Computer-aided
numerical
calculations
sin(𝑥) using the following Taylor series
• Example: Write a computer program to calculate
∞
expansion:
sin 𝑥 = −1
∑ ❑ 2𝑛 + 1
!
𝑛= 𝑛 𝑥 2𝑛+1
0
Computer-aided
numerical
Algorithm
calculations
• Enter 𝑥 and the sin(𝑥) using the following Taylor series
• Example: Write a computer program to calculate
use, 𝑛
∞
number of terms to expansion:
sin 𝑥 = −1
• Calculate sin(𝑥) ∑ ❑ 2𝑛 + 1
!
𝑛= 𝑛 𝑥 2𝑛+1
using the Taylor series 0
• Loop 𝑘 from 1 ∞
expansion:
sin 𝑥 = −1
to•𝑛𝑠𝑖𝑛 = 𝑠𝑖𝑛 + −1 𝑘+1 ∗ 𝑥 2𝑘−1 / ∑ ❑ 2𝑛 + 1
2𝑘 − 1 !
!
𝑛= 𝑛 𝑥 2𝑛+1
0
• End loop
• Output 𝑥, 𝑠𝑖𝑛
Flowchart
Computer-aided
numerical
calculations
sin(𝑥) using the following Taylor series
• Example: Write a computer program to calculate
∞
expansion:
sin 𝑥 = −1
∑ ❑ 2𝑛 + 1
!
𝑛= 𝑛 𝑥 2𝑛+1
0
Notes:
Computer-aided
• For clarity: numerical
• put comments to explain
variables, purpose of code
calculations
segments Programming errors (bugs)
• use variable names that • Syntax error – will not compile, compiler will help you
• Example: typographical error, writing 𝑝𝑟𝑖𝑚𝑡𝑓 instead of
make sense to find it.
• For testing: 𝑝𝑟𝑖𝑛𝑡𝑓
• Test with typical data • Run-time error – will compile but may stop running at
• Test with unusual but valid some point
data • Example: division by zero, trying to read from a non-
• Test with invalid data to existent file
check error handling • Logical error – will compile and run, but the result is
positive
Error
s
• Significant figures
• Digits of the number which are known to be
correct
• Designate the reliability of a number
• Depends on the origin of the number
Error
s
• Accuracy and Precision
• Computers used to obtain numerical solution
are imperfect tools; limited to represent the
magnitudes and precision of numbers.
• Errors from calculations (and measurements)
can be characterized with regard to their
accuracy and precision.
Error
s
• Accuracy – how closely a computed or measured
value agrees with the true value
• Precision – how closely a computed or measured
values agree with each other
• Fractional𝑡𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒 −
𝜀𝑡 𝑎𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑖𝑜𝑛
𝑡𝑟𝑢𝑒
relative true error
=
• Percentage relative𝑣𝑎𝑙𝑢𝑒
𝑡𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒 −
true error
𝜀𝑡 𝑎𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑖𝑜𝑛 ×
𝑡𝑟𝑢𝑒
= 100%
𝑣𝑎𝑙𝑢𝑒
Error
s
• Approximate error (𝑬𝒂) – in actual
situations, true value is rarely available
• Error estimates (or approximations) are
𝐸
determined in
𝜀𝑎
𝑎𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡
absence of knowledge regarding the true value
=
𝑎
𝑖𝑜𝑛
𝑝𝑟𝑒𝑠𝑒𝑛𝑡 𝑎𝑝𝑝𝑟𝑜𝑥 − 𝑝𝑟𝑒𝑣𝑖𝑜𝑢𝑠
• Fractional relative approximate error
𝜀𝑎 𝑎𝑝𝑝𝑟𝑜𝑥
𝑝𝑟𝑒𝑠𝑒𝑛𝑡
= 𝑎𝑝𝑝𝑟𝑜𝑥
𝑝𝑟𝑒𝑠𝑒𝑛𝑡 𝑎𝑝𝑝𝑟𝑜𝑥 − 𝑝𝑟𝑒𝑣𝑖𝑜𝑢𝑠
• Percentage relative approximate error
𝜀𝑎 𝑎𝑝𝑝𝑟𝑜𝑥 ×
𝑝𝑟𝑒𝑠𝑒𝑛𝑡
= 100%
𝑎𝑝𝑝𝑟𝑜𝑥
Error
s
• Iterative process – a process in which repetition
of a sequence of operations yields results
successively closer to a desired result.
• Many numerical methods work in an iterative
manner, thus there should be an exit or stopping
criterion for these methods.
Error
s
Exit criteria
• In iteration, we can either define the number of
iterations to be performed (which is not practical
since we won’t know how many should be
performed beforehand) or set a rule on when to
stop.
Error
s
• Let 𝒙 be a vector with 𝑵 elements:
P-Norm in Finite Dimensions
𝒙 ∞ = 𝒎𝒂𝒙{ 𝒙𝟏 , 𝒙𝟐 , … ,
as:
𝒙𝒏 }
Error
s
been converged if the 𝐿𝑝 − 𝑛𝑜𝑟𝑚 of the difference
• A solution in solving a system of equation is said to have
𝑥
iterations
𝐿1 𝑒𝑥𝑖𝑡 ∆𝑥 + ∆x + ⋯ + ∆𝑥 ≤
1 2 𝑛
𝑐𝑟𝑖𝑡𝑒𝑟𝑖𝑜𝑛: 𝑥(𝑘)∆𝑥2 + ∆𝑥2 + ⋯ + ∆𝑥2
𝜀𝑠
≤ 𝜀𝑠
𝐿2 𝑒𝑥𝑖𝑡 1 2 𝑛
• Example: 𝜋, 1/3
system may create problems
• Example: 𝜋, 1/3
double create problems
precision.
• Computers cannot use infinitely many digits to store
Compare the results. numbers
• Single precision (7-8 digits) vs.
• Double precision (15-16 digits)
• Round-off errors cannot be totally eliminated,
but clever algorithms may help to minimize them.
Error
At x =
s
• Truncation Error
π/2:
• Results from using an approximation in place of
an exact mathematical procedure.
sin 𝑥 = −1 𝑛 𝑥 2𝑛+1 𝑥3 𝑥5
∑❑
𝑛=0
2𝑛 + 1
𝑥!7
=𝑥−
+⋯
3!
+
5!
−
7!
Error
s
• Gross Error/Blunder – computer malfunctions or
human imperfections
• Model Error – incorrect mathematical model
• Data Uncertainty – measurement errors