0% found this document useful (0 votes)
31 views

Lecture1 - Modelling-Computers-Error Analysis - 19feb2024 - NK - v1

The document provides an introduction to a computational methods in engineering course. It discusses modeling, computers, errors, and numerical methods. It also introduces MATLAB and provides engineering examples to help understand computational methods.

Uploaded by

yamanf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Lecture1 - Modelling-Computers-Error Analysis - 19feb2024 - NK - v1

The document provides an introduction to a computational methods in engineering course. It discusses modeling, computers, errors, and numerical methods. It also introduces MATLAB and provides engineering examples to help understand computational methods.

Uploaded by

yamanf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 75

CME302

COMPUTATIONAL METHODS IN
ENGINEERING
Part 1 – Modelling, Computers, and Error Analysis

Dr.Namık KILIÇ e-mail: [email protected] 19th Feb 2024


Part1 – Modelling,
Computers, and Error
Analysis
Chapters 1 - 4
INTRODUCTION
prepared to embark on your
studies of numerical
methods.

fundamental understanding
of the importance of
computers and the role of
approximations and errors in
the implementation and
development of numerical
methods.

mastered each of the specific


study objectives listed
INTRODUCTION

Computing and Engineering Problem solving


Requires understanding of engineering systems.
▪ By observation and experiment.
▪ Theoretical analysis and generalization.

▪ Computers are great tools, however, without fundamental


understanding of engineering problems, they will be
useless.
INTRODUCTION

The Engineering Problem-


Solving Process
INTRODUCTION

Mathematical Models
• A mathematical model is represented as a functional relationship
of the form.

Dependent  independent forcing 


= f parameters, 
Variable  variables , func t ions 
• Dependent variable: Characteristic that usually reflects the state of
the system.
• Independent variables: Dimensions such as time ans space along
which the systems behavior is being determined.
• Parameters: reflect the system’s properties or composition.
• Forcing functions: external influences acting upon the system.
INTRODUCTION

Newton’s 2nd law of Motion 1

• States that “the time rate change of momentum of a body


is equal to the resulting force acting on it.”
• The model is formulated as,

F=ma

F = net force acting on the body (N)


m = mass of the object (kg)
a = its acceleration ( )
m/s 2
INTRODUCTION

Newton’s 2nd law of Motion

▪ Formulation of Newton’s 2nd law has several characteristics that are


typical of mathematical models of the physical world:
▪ It describes a natural process or system in mathematical terms.
▪ It represents an idealization and simplification of reality.
▪ Finally, it yields reproducible results, consequently, can be used for predictive
purposes.
INTRODUCTION
Complex Models Usually Require
More Advanced Mathematics
Some mathematical models of physical phenomena may be much
more complex.
Complex models may not be solved exactly or require more
sophisticated mathematical techniques than simple algebra for
their solution.
▪ Example, modeling of a falling parachutist:
INTRODUCTION
Modeling the Velocity of a Freefalling Parachutist

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

History & Basic


Engineering Examples
Applications Introduction

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

Bascule Bridge Example: Reference:


Introduction to Scientific Computing, Autar Kaw, Luke Snyder

Hub

Trunnion
Trunnion-Hub-Girder Assembly
Procedure

1- Trunnion immersed in dry-ice/alcohol


2- Trunnion warm-up in hub
3- Trunnion-Hub immersed in dry-
ice/alcohol
4- Trunnion-Hub warm-up into Grider
INTRODUCTION
1- Problem: After Cooling, the Trunnion Got Stuck in Hub
2- Why did it get stuck? Did it contract enough?
Magnitude of contraction needed in the trunnion was
0.015” or more

Consultant calculations D = D    T
INTRODUCTION
INTRODUCTION
Can You Find a Better Estimate for the Contraction?
INTRODUCTION
INTRODUCTION

Some Numerical Disasters


ARIANE 5: June 4, 1996

• A 64 bit Floating Point number containing the


horizontal velocity was converted to 16 bit
signed integer.
• Range overflow and Rocket destroyed

1991 - Position predicted from time and velocity:

• The system up-time in 1/10 of a second


was converted to seconds using 24bit precision (by
multiplying with 1/10)
• 1/10 has non-terminating binary expansion
• after 100h, the error accumulated to 0.34s
the SCUD travels 1600 m/s, so it travels >500m
in this time
INTRODUCTION

Engineering Applications

Electrical & Mechanical & Chemical &


Civil Engineering Computer Aerospace Pharmaceutical
Engineering Engineering Engineering
• Structural • Network • Heat Flow • Molecular
Analysis Analysis • Fluid Dynamics Modeling
• Traffic • Signal • Structural • Biomedical
Simulations Processing Optimization Applications
• Environmental • Electromagnetic
Simulations Fields
INTRODUCTION
Engineering Examples for Understanding
INTRODUCTION
Introduction to MATLAB

Today lecture is not intended to be a comprehensive manual of


MATLAB.

COMP 111 already built up comprehensive knowledge on programming.

Today objecive is to provide sufficient information to give you a good


start.

The great advantage of MATLAB in this course is that programs can be


tested and debugged quickly, allowing the user to concentrate more
on the principles behind the program and less on programming itself.
Introduction to MATLAB

MATLAB contains a large number of functions that access proven


numerical libraries, such as LINPACK and EISPACK. This means that
many common tasks (e.g., solution of simultaneous equations) can be
accomplished with a single function call.

There is extensive graphics support that allows the results of


computations to be plotted with a few statements.

All numerical objects are treated as double-precision arrays. Thus


there is no need to declare data types and carry out type conversions.
Introduction to MATLAB
Data Types
double, char, and logical are considered by MATLAB as arrays.
Numerical objects belong to the class double, which represent double-
precision arrays; a scalar is treated as a 1 × 1 array. The elements of
a char type array are strings (sequences of characters), whereas a
logical type array element may contain only 1 (true) or 0 (false).

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

MATLAB contains several built-in constants and special variables, most


important of which are
Introduction to MATLAB

Arrays can be created in several ways.

One of them is to type the elements of the array between brackets.


The elements in each row must be separated by blanks or commas.
>> A = [ 2 -1 0
-1 2 -1
0 -1 1]

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

MATLAB supports the usual arithmetic operators

There are two division operators.

Often we need to apply the *, /, and ˆ operations


to matrices in an elementby-element fashion.
This can be done by preceding the operator with
a period (.)
Introduction to MATLAB

The comparison (relational) operators return 1


for true and 0 for false.

The logical operators


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.

The if conditional can be followed by any


number of elseif constructs, which work in
the same manner.

The else clause


can be used to define the block of
statements which are to be executed if
none of the if–elseif clauses are true.
Introduction to MATLAB

The function signum, which determines


the sign of a variable, illustrates the use
of the conditionals:
Introduction to MATLAB
switch
expression is evaluated and the control is
passed to the case that matches the value.
For instance, if the value of expression is
equal to value2, the block of statements
following case value2 is executed. If the
value of expression does not match any of
the case values, the control passes to the
optional otherwise block.
Introduction to MATLAB
while executes a block of statements if the
condition is true. After execution of the block,
condition is evaluated again. If it is still true,
the block is executed again. This process is
continued until the condition becomes false.

for loop requires a target and a sequence over


which the target loops. The form of the
construct is

When the continue statement is encountered in


a loop, the control is passed to the next
iteration without executing the statements in
the current iteration.
Introduction to MATLAB
return
A function normally returns
to the calling program when
it runs out of statements.
However, the function can be
forced to exit with the return
command. In the example
below, the function solve
uses the Newton–Raphson
method to find the zero of
f(x) = sin x − 0.5x.
Introduction to MATLAB
The body of a function must be
preceded by the function
definition line
function [output args] =
function name(input arguments)

The input and output arguments


must be separated by commas.
The number of arguments may
be zero. If there is only one
output argument, the enclosing
brackets may be omitted
Introduction to MATLAB

Evaluating Functions Let us


consider a slightly different
version of the function solve
shown below. The expression
for dx, namely, x = −f(x)/f (x), is
now coded in the function
myfunc, so that solve contains a
call to myfunc. This will work
fine, provided that myfunc is
stored under the file name
myfunc.m so that MATLAB can
find it.
Introduction to MATLAB
Creating Arrays We learned before that an array can be created by
typing its elements between brackets:
>> x = [0 0.25 0.5 0.75 1]

Arrays with equally spaced elements can also be constructed with the
colon operator
>> x = 0:0.25:1

Another means of creating an array with equally spaced elements is


the linspace function.
>> x = linspace(0,1,5)

The function logspace is the logarithmic counterpart of linspace.


>> x = logspace(0,1,5)
Introduction to MATLAB

The function call


X = zeros(m,n) returns a matrix of m rows and n columns that is filled
with zeros

X = ones(m,n)

X = rand(m,n)

X = eye(n)
Introduction to MATLAB

There are numerous array


functions in MATLAB that
perform matrix operations
and other useful tasks
Approximations and Round-Off Errors
▪ For many engineering problems, we cannot obtain analytical solutions.
▪ Numerical methods yield approximate results, results that are close to the
exact analytical solution. We cannot exactly compute the errors associated
with numerical methods.
▪ Only rarely given data are exact, since they originate from measurements. Therefore
there is probably error in the input information.
▪ Algorithm itself usually introduces errors as well, for example, unavoidable round-
offs, etc …
▪ The output information will then contain error from both of these sources.

▪ How confident we are in our approximate result?


▪ The question is “how much error is present in our calculation and is it
tolerable?”
Accuracy & Precision
• Accuracy. How close is a computed or measured value to
the true value.
• Precision (or reproducibility). How close is a computed
or measured value to previously computed or measured
values.
• Inaccuracy (or bias). A systematic deviation from the
actual value.
• Imprecision (or uncertainty). Magnitude of scatter.
Targets Illustrating Accuracy & Precision
Significant Figures
• Number of significant figures indicates precision. Significant digits of a number
are those that can be used with confidence, for example, the number of certain
digits plus one estimated digit.

▪ 53,800 How many significant figures?

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

Et = True value − Approximation ( + / −)

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

• If the following criterion is met

 s = ( 0.5  10(2-n ) ) %

▪ you can be sure that the result is correct to at least n significant


figures.
Round-off Errors
• Numbers such as  , e, or 7 cannot be expressed
by a fixed number of significant figures.
• Computers use a base-2 representation, they cannot precisely represent
certain exact base-10 numbers.
• Fractional quantities are typically represented in computer using
“floating point” form, for example,
(a) Decimal

(b) Binary Number


Systems
The signed magnitude method for integer representation of
The manner in which a floating-point (decimal) number is
stored in a word.
How a decimal number would be stored in a hypothetical base-10
computer
Example: 1/ 34 = 0.029411765
▪ Suppose only 4 decimal places can be stored

0.029411765 → 0.0294 100


▪ The first zero to right of decimal point is useless. So,
normalize by multiplying the mantissa by 10 and
lowering the exponent by 1

0.0294  100 → 0.2941 10−1

Additional significant figure is retained


Normalization means limited range of mantissa
1
 m 1
b
Therefore
▪ for a base-10 system 0.1 ≤ m(mantissa) <1
▪ for a base-2 system 0.5 ≤ m <1

Floating point representation allows both fractions and very large


numbers to be expressed on the computer. However,
▪ Floating point numbers take up more room.
▪ Take longer to process than integer numbers.
▪ Round-off errors are introduced because mantissa holds only a
finite number of significant figures.
Chopping & Rounding
▪ Example:
 = 3.14159265358 to be stored on a base-10 system
carrying 7 significant digits.
 = 3.141592 chopping error →  t = 0.00000065
If rounded
 = 3.141593 rounding error →  t = 0.00000035
Some machines use chopping, because rounding adds to
the computational overhead. Since number of significant
figures is large enough, resulting chopping error is
“usually” negligible.
Biggest Sources of Rounding Errors in Numerical
Calculation
• Large interdependent computations (billions of
operations); tiny errors can compound (add up).
• Adding a large & small number.
• Smearing: Occurs whenever the individual terms in a
summation are larger than the summation itself.
• Subtractive cancellation: round-off induced when
subtracting two nearly equal floating-point numbers.
TRUNCATION ERRORS
▪ Recall from Chap. 1, how we approximated the
derivative

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 ) + v(ti ) (ti +1 − ti )+R1

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 xy y 

+
Error Propagation
TRADEOFF BETWEEN ROUND-OFF & TRUNCATION
ERROR

You might also like