Вы находитесь на странице: 1из 84

Motilal Nehru National Institute of Technology

Civil Engineering Department

Computer Based Numerical Techniques


CE-401

Introduction

Introduction
Consider the following equations.

Numerical Methods - Definitions

Numerical Methods

Analytical vs. Numerical methods

Analytical vs. Numerical methods

Mathematician and Engineer

Reasons to study numerical Analysis


Powerful problem solving techniques and can be
used to handle large systems of equations
It enables you to intelligently use the commercial
software packages as well as designing your own
algorithm.
Numerical Methods are efficient vehicles in learning
to use computers
It Reinforce your understanding of mathematics;
where it reduces higher mathematics to basic
arithmetic operation.

Course
Contents

Motilal Nehru National Institute of Technology


Civil Engineering Department

Computer Based Numerical Techniques


CE-401

Mathematical Modeling

Chapter 1: Mathematical Modeling


Mathematical Model
A formulation or equation that expresses the essential
features of a physical system or process in mathematical
terms.
Generally, it can be represented as a functional
relationship of the form

Mathematical Modeling

Simple Mathematical Model


Example: Newtons Second Law
(The time rate of change of momentum of a body is
equal to the resultant force acting on it)

a = acceleration (m/s2) .the dependent variable


m = mass of the object (kg) .the parameter
representing a property of the system.
f = force acting on the body (N)

Typical characteristics of Math. model


It describes a natural process or system in
mathematical way
It represents the idealization and simplification
of reality.
It yields reproducible results, and can be used
for predictive purpose.

Complex Mathematical Model


Example: Newtons Second Law

Where:
c = drag coefficient (kg/s),
v = falling velocity (m/s)

Complex Mathematical Model

At rest: (v = 0 at t = 0),
Calculus can be used to solve the equation

Analytical solution to Newton's Second Law


.

Analytical solution to Newton's Second Law

Analytical solution to Newton's Second Law

Numerical Solution to Newton's Second Law

Numerical solution: approximates the exact


solution by arithmetic operations.

Suppose

Numerical Solution to Newton's Second Law


.

Numerical Solution to Newton's Second Law


.

Comparison between Analytical vs. Numerical Solution

Motilal Nehru National Institute of Technology


Civil Engineering Department

Computer Based Numerical Techniques


CE-401

Accuracy and Errors

Terms
Errors are mainly associated with calculations
and measurements
Accuracy: How closely a computed value or
measured value agrees with true value
Precision: How individual computed values or
measured values agree with one another.
Inaccuracy is also called bias
Imprecision is also called uncertainty

Figure 4.1

Measured Numbers
A measuring tool

is used to determine a

quantity such as height


or the mass of an
object.
provides numbers for a
measurement called
measured numbers.
Copyright 2009 by Pearson Education, Inc.

27

Reading a Meterstick
. l2. . . . l . . . . l3 . . . . l . . . . l4. .

cm

The markings on the meterstick at the end of the orange

line are read as:


the first digit
2
plus the second digit 2.7
The last digit is obtained by estimating.
The end of the line may be estimated between 2.72.8 as
half way (0.5) or a little more (0.6), which gives a reported
length of 2.75 cm or 2.76 cm.

28

Known & Estimated Digits


If the length is reported as 2.76 cm,

the digits 2 and 7 are certain (known).


the final digit, 6, is estimated (uncertain).
all three digits (2, 7, and 6) are significant, including the
estimated digit.

29

Learning Check
. l8. . . . l . . . . l9. . . . l . . . . l10. . cm
What is the length of the orange line?
1) 9.0 cm
2) 9.04 cm
3) 9.05 cm

30

Solution
. l8. . . . l . . . . l9. . . . l . . . . l10. . cm
The length of the orange line could be reported as

2) 9.04 cm
or

3) 9.05 cm

The estimated digit may be slightly different. Both readings


are acceptable.

31

Zero as a Measured Number


. l3. . . . l . . . . l4. . . . l . . . . l5. . cm

For this measurement, the first and second known digits


are 4 and 5.

When a measurement ends on a mark, the estimated digit


in the hundredths place is 0.

This measurement is reported as 4.50 cm.


32

Significant Figures in
Measured Numbers
Significant Figures

obtained from a measurement include all of


the known digits plus the estimated digit.

reported in a measurement depend on the


measuring tool.

33

Significant Figures

34

Counting Significant Figures


All nonzero numbers in a measured number are
significant.

Measurement
38.15 cm
5.6 ft
65.6 lb
122.55 m

Number of
Significant Figures
4
2
3
5

35

Sandwiched Zeros
Sandwiched Zeros
occur between nonzero numbers.
are significant.

Measurement
50.8 mm
2001 min
0.0702 lb
0.405 05 m

Number of
Significant Figures
3
4
3
5

36

Trailing Zeros
Trailing Zeros
follow nonzero numbers in numbers without decimal
points.
are usually placeholders.
are not significant.
Number of
Measurement
Significant Figures
25 000 cm
2
200 kg
1
48 600 mL
3
25 005 000 g
5
37

Leading Zeros
Leading Zeros
precede nonzero digits in a decimal number.
are not significant.

Measurement
0.008 mm
0.0156 oz
0.0042 lb
0.000 262 mL

Number of
Significant Figures
1
3
2
3

38

Learning Check
State the number of significant figures in each of the
following measurements.
A. 0.030 m

B.
C.
D.

4.050 L
0.0008 g
2.80 m

39

Solution
State the number of significant figures in each of the
following measurements.
A.

0.030 m

B.
C.
D.

4.050 L
0.0008 g
2.80 m

4
1
3

40

Significant Figures in
Scientific Notation
In scientific notation all digits in the coefficient
including zeros are significant.

Measurement
8 x 104 m
8.0 x 104 m
8.00 x 104 m

Number of
Significant Figures
1
2
3

41

Study Tip: Significant Figures


The significant figures in a measured number are
all the nonzero numbers.
12.56 m
4 significant figures
zeros between nonzero numbers.
4.05 g
3 significant figures
zeros that follow nonzero numbers in a decimal
number.
25.800 L
5 significant figures

42

Learning Check
A. Which answer(s) contain 3 significant figures?
1) 0.4760 2) 0.00476
3) 4.76 x 103
B. All the zeros are significant in
1) 0.00307.

2) 25.300.

3) 2.050 x 103.

C. The number of significant figures in 5.80 x 102 is


1) one (1). 2) two (2).
3) three (3).

43

Solution
A. Which answer(s) contain 3 significant figures?

2) 0.00476

3) 4.76 x 103

B. All the zeros are significant in


2) 25.300.

3) 2.050 x 103.

C. The number of significant figures in 5.80 x 102 is


3) three (3).

44

Learning Check
In which set(s) do both numbers contain the same
number of significant figures?
1) 22.0 and 22.00
2) 400.0 and 40
3) 0.000 015 and 150 000

45

Solution
In which set(s) do both numbers contain the same
number of significant figures?
3) 0.000 015 and 150 000
Both numbers contain 2 significant figures.

46

Examples of Exact Numbers


An exact number is obtained

when objects are counted.


Counted objects
2 soccer balls
4 pizzas

from numbers in a defined relationship.


Defined relationships
1 foot = 12 inches
1 meter = 100 cm
47

Exact Numbers

48

Learning Check

A. Exact numbers are obtained by


1. using a measuring tool.
2. counting.
3. definition.
B. Measured numbers are obtained by
1. using a measuring tool.
2. counting.
3. definition.

49

Solution

A. Exact numbers are obtained by


2. counting.
3. definition.
B. Measured numbers are obtained by
1. using a measuring tool.

50

Learning Check
Classify each of the following as (1) exact or (2) measured
numbers.
A.__Gold melts at 1064 C.
B.__1 yard = 3 feet

C.__The diameter of a red blood cell is 6 x 10-4 cm.


D.__There are 6 hats on the shelf.
E.__A can of soda contains 355 mL of soda.

51

Solution
Classify each of the following as (1) exact or (2) measured
numbers.
A. 2 A measuring tool is required.
B. 1 This is a defined relationship.

C. 2 A measuring tool is used to determine


length.
D. 1 The number of hats is obtained by counting.

E. 2 The volume of soda is measured.

52

Number Representation
Do machines represent integers and floatingpoint numbers using the same
representation?
How does computer represent integers?

How does computer represent floating-point


numbers?
53

Representation of Integers
13 as 8-bit unsigned integers (no negative #)
1310 = 000011012
= 0 x 27 + 1 x 26 + 0 x 25 + 0 x 24 +
1 x 23 + 1 x 22 + 0 x 21 + 1 x 20
=8+4+0+1

54

Exercise
What is the equivalent decimal number
represented by the following binary number?
1101012 = ?

55

Representation of Floating-point Numbers

15678

156.78 = 0.15678 x 103


in an "imaginary" base-10 floating-point system
56

Normalized Representation
(and notations used in this course)
z (0.a1a2 a3 ...) e
m e
is the sign
is the base, e is the exponent
binary : =2
decimal : =10

1/ m < 1

(i.e., a1 0)

binary: 0.5 m < 1


decimal: 0.1 m < 1

57

Representation of Floating-point Numbers


13.625 1 23 1 22 0 21 1 20
1 2 1 0 2 2 1 2 3
(1101.101)2
( ) (0.1101101)2 2 4

Sign Signed exponent (e)

58

( Normalized form)

Mantissa (a)

Exercise
What is the normalized floating-point
representation of 12.7510 (for = 2)?
What is the normalized floating-point
representation of 2.210 (for = 2)?

What is the equivalent decimal value of


(0.110111)2 x 23 ?
59

There are discrete points


on the number lines that
can be represented by our
computer.
How about the space
between ?
60

Implication of floating-point representations


Only limited range of quantities may be represented
Number too larger overflow
Number too small (too close to 0) underflow

Only a finite number of quantities may be


represented
round-off or chopping errors

61

Exercise
Consider the following floating-point representation
The mantissa has only 3 bits
z (0.a1a2a3 ) 2 2e
Exponent, e, ranges from -4 to 4

Can you give an integer that cannot be represented


by this representation?
Can you give an integer between 0 and 14 that
cannot be represented by this representation?

62

IEEE 754 Floating-point Representation


Size in
bits

Sign
(0=+ve,
1 = -ve)

Exponent

Bias of the Mantissa


exponent

Single
precision
(float)

32 bits

1 bit

8 bits
(-126 to
+127)

127

23 bits

double
precision
(double)

64 bits

1 bit

11 bits
(-1022 to
+1023)

1023

52 bits

Larger exponent Wider range of numbers


Longer mantissa Higher precision
63

Note on IEEE 754 Representation


Exponents of all 0's and 1's are reserved for special
numbers.
Zero is a special value denoted with an exponent
field of zero and a mantissa field of zero, and we
could have +0 and -0.
+ an - are denoted with an exponent of all 1's
and a mantissa field of all 0's.
NaN (Not-a-number) is denoted with an exponent of
all 1's and a non-zero mantissa field.

64

Errors and Significant Digits


I paid $10 for 7 oranges. What is unit price of
each orange?
Rs. 1.528571429 (that is the exact output from
my computer !!)
Is there any difference between
Rs. 1.527571429 and Rs. 1.5?
Is there any difference between Rs. 1.5 and
Rs. 1.50?
65

Significant figures, or digits


The significant digits of a number are those
that can be used with confidence.
They correspond to the number of certain
digits plus one estimated digits.
x = 3.5 (2 significant digits) 3.45 x < 3.55
x = 0.51234 (5 significant digits)
0.512335 x < 0.512345
66

Excercise
Suppose x = 3.141592658979323
Show the value of x up to 4 significant digits.
Show the value of x up to 10 significant digits.

Calculate 22/7 up to 5 significant digits.

67

Motilal Nehru National Institute of Technology


Civil Engineering Department

Computer Based Numerical Techniques


CE-401

Approximations and Errors

Approximations and Errors


The major advantage of numerical analysis is that
a numerical answer can be obtained even when a
problem has no analytical solution.

Although the numerical technique yielded close


estimates to the exact analytical solutions, there
are errors because the numerical methods involve
approximations.

Approximations and Round-Off Errors


Chapter 3
For many engineering problems, we cannot obtain analytical
solutions.
Numerical methods yield approximate results, results that are
close to the exact analytical solution.
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, e.g., 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?
by Lale Yurttas, Texas A&M
University

Chapter 3

70

Accuracy and Precision


Accuracy refers to how
closely a computed or
measured value agrees
with the true value.

Precision refers to how


closely individual
computed or measured
values agree with each
other.
Bias refers to systematic
deviation of values from
the true value.

Significant Figures
Significant figures of a number are those that can be used
with confidence.

Rules for identifying sig. figures:


All non-zero digits are considered significant. For example, 91
has two significant digits (9 and 1), while 123.45 has five
significant digits (1, 2, 3, 4 and 5).
Zeros appearing anywhere between two non-zero digits are
significant. Example: 101.12 has five significant digits.
Leading zeros are not significant. For example, 0.00052 has
two significant digits
Trailing zeros are generally considered as significant. For
example, 12.2300 has six significant digits.

Significant Figures
Scientific Notation
If it is not clear how many, if any, of zeros are significant. This
problem can be solved by using the scientific notation
0.0013 = 1.3*10-3

0.00130 = 1.30*10-3

2 sig. figures

3 sig. figures

If a number is expressed as 2.55 *104, (3 s.f), then we are only


confident about the first three digits. The exact number may be
25500, 25513, 25522.6 , .. etc. So we are not sure about the
last two digits nor the fractional part- If any.
However, if it is expressed as 2.550 * 104, (4 s.f), then we are
confident about the first four digits but uncertain about the
last one and the fractional part if any.

Error Definition
Numerical errors arise from the use of approximations
Errors

Truncation errors
Result when
approximations are used
to represent exact
mathematical procedure.

Round-off errors
Result when numbers
having limited significant
figures are used to
represent exact numbers.

Round-off Errors
Numbers such as p, 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, e.g.,
Example:
p = 3.14159265358 to be stored carrying 7 significant digits.
p = 3.141592 chopping
p = 3.141593 rounding

Truncation Errors
Truncation errors are those that result using
approximation in place of an exact mathematical
procedure.

dv v V t i 1 V t i

dt t
t i 1 t i

True Error
True error (Et)
True error (Et) or Exact value of error
= true value approximated value
True percent relative error ( t
True percent relative error t

True error
100 (%)
True value
true value approximated value
100 (%)
true value

See Example 3.1 P 54

Example 3.1

Example 3.1

Approximate Error
The true error is known only when we deal with functions that
can be solved analytically.
In many applications, a prior true value is rarely available.
For this situation, an alternative is to calculate an
approximation of the error using the best available estimate of
the true value as:
a Approximate percent relative error

Approximate error
100 (%)
approximation

Approximate Error
In many numerical methods a present approximation is
calculated using previous approximation:
present approximation previous approximation
a
100 (%)
present approximation

Note:
- The sign of
may be positive or negative
a t or
- We interested in whether the absolute value is lower
than a prespecified tolerance (s), not to the sign of error.
Thus, the computation is repeated until (stopping criteria):

a s

Prespecified Error
We can relate (s) to the number of significant
figures in the approximation,
So, we can assure that the result is correct to at
least n significant figures if the following criteria
is met:

s (0.5 10
See Example 3.2 p56

2 n

) %

Example
The exponential function can be computed using Maclaurin
series as follows:
2
3
n
e x 1 x

x
x

2! 3!

x
n!

Estimate e0.5 using series, add terms until the absolute value of
approximate error a fall below a pre-specified error s
conforming with three significant figures.
{The exact value of e0.5=1.648721}

Solution
s 0.5 1023 % 0.05%

Вам также может понравиться