Lecture1 - Modelling-Computers-Error Analysis - 19feb2024 - NK - v1
Lecture1 - Modelling-Computers-Error Analysis - 19feb2024 - NK - v1
COMPUTATIONAL METHODS IN
ENGINEERING
Part 1 – Modelling, Computers, and Error Analysis
fundamental understanding
of the importance of
computers and the role of
approximations and errors in
the implementation and
development of numerical
methods.
Mathematical Models
• A mathematical model is represented as a functional relationship
of the form.
F=ma
dv F
=
dt m
F = FD + FU
FD = mg
FU = −cv
dv mg − cv
=
dt m
Free-body diagram
INTRODUCTION
Modeling the Velocity of a Freefalling Parachutist
dv c
=g− v
dt m
This is a differential equation and is written in terms of the
differential rate of change dv / dt of the variable that we are
interested in predicting.
If the parachutist is initially at rest (v = 0 at t = 0), using calculus.
INTRODUCTION
NUMERICAL METHOD
ANALYSIS & ENGINEERING Course Computational
APPLICATIONS Topics Examples
FUTURE TECHNOLOGY
REVIEW
New
Technologies Introduction
Example
INTRODUCTION
Introduction
• Direct and iterative methods
• Discretization
Propogation of Errors
• Round-off
• Truncation and discretization error
• Numerical stability
Study Areas
• Interpolation , Extrapolation
• Regression, Optimization
• Differential Equation
INTRODUCTION
Study Interpolation
Areas
Extrapolation
x u2
1 −
Regression
2 e
−
2
du
Optimization
Differential Equation
1- Velocity to vary with time
2- Gross Domestic Product: average of 10% increase from 100 to 110
3- Compute a line that passes as close as possible
4- $1=197 glasses, increasing the $1.49 = 148 glasses but maximize the income
5- Wing & Fluid analysis in a room or around a building with Euler Method
INTRODUCTION
Problem Description
• CHEMICAL
• MECHANICAL
Definition Easy or Hard? • AEROSPACE
• INDUSTRIAL
• MATERIAL
Mathematical Model & Design
• CIVIL
Searching for Solution Control of the Model • COMPUTER
• ELECTRICAL
• MATLAB Solution of Mathematical Model
• MATHEMATICA
• EXCEL With Computer Program? Which Steps?
• MAPLE
• MATHCAD
Using of Model
• OTHER SOFTWARES
• CAD PROGRAMMES Check the Results Do it again! IF it’s wrong!
• ANALYSIS
INTRODUCTION
Hub
Trunnion
Trunnion-Hub-Girder Assembly
Procedure
Consultant calculations D = D T
INTRODUCTION
INTRODUCTION
Can You Find a Better Estimate for the Contraction?
INTRODUCTION
INTRODUCTION
Engineering Applications
There are other data types, such as sparse (sparse matrices), inline
(inline objects), and struct (structured arrays), but we seldom come
across them in this text.
The class of an object can be displayed with the class command.
For example,
>> x = 1 + 3i % Complex number
>> class(x)
ans = double
Introduction to MATLAB
Variables
Variable names, which must start with a letter, are case sensitive.
The length of the name is unlimited, but only the first N characters are
significant. To find N for your installation of MATLAB, use the
command
>> namelengthmax
ans =
63
Introduction to MATLAB
The elements can also be typed on a single line, separating the rows
with colons: >> A = [2 -1 0; -1 2 -1; 0 -1 1]
A = 2 -1 0
-1 2 -1
0 -1 1
Introduction to MATLAB
Conditionals
if, else, elseif The if construct executes the
block of statements if the condition is true.
If the condition is false, the block skipped.
Arrays with equally spaced elements can also be constructed with the
colon operator
>> x = 0:0.25:1
X = ones(m,n)
X = rand(m,n)
X = eye(n)
Introduction to MATLAB
5.38 × 104 3
5.380 × 104 ▪ In the following table, read ‘10 4’ as 10 to the power of 4.
4
5.3800 × 104 5
▪ Zeros are sometimes used to locate the decimal point not significant figures.
0.00001753 4
0.0001753 4
0.001753 4
Error Definitions
▪ True Value = Approximation + Error
True error
true error
True fractional relative error =
true value
true error
True percent relative error, t = 100%
true value
Error Definitions
• For numerical methods, the true value will be known only
when we deal with functions that can be solved analytically
(simple systems). In real world applications, we usually not
know the answer a priori. Then
Approximate error
a = 100%
Approximation
• Iterative approach, example Newton’s method.
Current approximation −Previous approximation
a = 100%
Current approximation
Error Definitions
• Use absolute value.
• Computations are repeated until stopping criterion is satisfied.
a s
Pre-specified % tolerance based
on the knowledge of your solution
s = ( 0.5 10(2-n ) ) %
dv v v(ti +1 ) − v(ti )
=
dt t ti +1 − ti
TRUNCATION ERRORS
dv v(ti +1 ) − v(ti )
dt ti +1 − ti
Key questions:
▪ Given t = ti+1 − ti
▪ How good is the approximation? Error.
▪ What is benefit for reducing t? Convergence.
TAYLOR’S THEOREM
▪ If a function f and its first n + 1 derivatives are continuous on
an interval containing xi and xi+1 = xi + h, then the value of the
function at xi+1 is given by
f ( xi ) 2
f ( xi +1 ) = f ( xi ) + f ( xi )h + h
2!
f (3) ( xi ) 3 f ( n ) ( xi ) n
+ h + + h + Rn
3! n!
▪ Where
f ( n +1) ( ) n +1
Rn = h
(n + 1)!
Taylor Series
Truncation Errors and the Taylor Series
• Non-elementary functions such as trigonometric,
exponential, and others are expressed in an approximate
fashion using Taylor series when their values,
derivatives, and integrals are computed.
• Any smooth function can be approximated as a
polynomial. Taylor series provides a means to predict the
value of a function at one point in terms of the function
value and its derivatives at another point.
Taylor Series Example
▪ To get the cos(x) for small x:
x2 x4 x6
cos x = 1 − + − +
2! 4! 6!
▪ If x = 0.5, the exact value is 0.877582562. The approximation is
▪ cos(0.5) = 1 − 0.125 + 0.0026041 − 0.0000127 + …
▪ = 0.877582465
▪ From the supporting theory, for this series, the error is no greater than the
first omitted term.
x8
for x = 0.5 = 9.68812 10−8
8!
▪ The true error is 0.877582562 − 0.877582465 = 9.66126 10−8
The Taylor Series Remainder
▪ nth order approximation
f
f ( xi +1 ) f ( xi ) + f ( xi )( xi +1 − xi ) +
( xi +1 − xi ) +
2
2!
f (n)
+ ( xi +1 − xi ) + Rn
n
n!
▪ define h = (xi+1 − xi) step
size
f ( n +1) ( ) ( n +1)
Rn = h
( n + 1)!
• Remainder term, Rn, accounts for all terms from (n + 1) to
infinity.
O(h) Notation
f ( xi ) 2
f ( xi +1 ) = f ( xi ) + f ( xi )h + h
2!
f (3) ( xi ) 3 f ( n) ( xi ) n
+ h + + h + Rn
3! n!
▪ where
Rn = O(h n +1 )
Summary of the Taylor Series Error
• is not known exactly, lies somewhere between xi +1 xi .
• Need to determine f n +1 ( x).
• To do this you need f (x).
• If we knew f (x), there wouldn’t be any need to perform the Taylor
series expansion!
• However, R = O(h n +1 ), (n + 1) th ▪ order, the order of truncation
▪ error is h n +1.
• O(h), halving the step size will halve the error.
• O(h 2 ), ▪ halving the step size will quarter the error.
Taylor Series Error
• Truncation error is decreased by addition of terms to the
Taylor series.
• If h is sufficiently small, only a few terms may be
required to obtain an approximation close enough to the
actual value for practical purposes.
ESTIMATING THE TRUNCATION ERROR OF THE
VELOCITY APPROXIMATION OF THE DERIVATIVE
OF THE VELOCITY
v(ti )
v(ti +1 ) = v(ti ) + v(ti ) (ti +1 − ti ) + (ti +1 − ti ) 2 + + Rn
2!
v(ti +1 ) − v(ti ) R1
v(ti ) = −
ti +1 − ti ti +1 − ti
First-order Truncation
Approximation error
R1 v( )
= (ti +1 − ti ) = O(ti +1 − ti ) = O(h)
ti +1 − ti 2!
NUMERICAL DIFFERENTIATION
▪ First forward divided difference:
f ( xi +1 ) − f ( xi )
f ( xi ) = O ( h)
h
▪ First backward divided difference:
f ( xi ) − f ( xi −1 )
f ( xi ) + O ( h)
h
▪ First centered divided difference:
f ( xi +1 ) − f ( xi −1 )
f ( xi ) = + O(h 2 )
2h
GRAPHICAL REPRESENTATION OF DIVIDED
DIFFERENCES
CENTERED SECOND DIVIDED DIFFERENCE
f ( xi +1 ) − 2 f ( xi ) + f ( xi −1 )
f ( xi ) = + O(h 2 )
h2
▪ By reformulating you can see it’s the difference of two
first derivative divided differences:
f ( xi +1 ) − f ( xi ) f ( xi ) − f ( xi −1 )
−
f ( xi ) h h
h
TWO-DIMENSIONAL TAYLOR SERIES
f ( xi +1 , yi +1 ) = f ( xi , yi )
f f
+ ( xi +1 − xi ) + ( yi +1 − yi )
x y
1 2 f 2 f 2 f 2
+ 2 ( xi +1 − xi ) + 2
2
( xi +1 − xi )( yi +1 − yi ) + 2 ( yi +1 − yi )
2! x xy y
+
Error Propagation
TRADEOFF BETWEEN ROUND-OFF & TRUNCATION
ERROR