EEPC102 Module I

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

MODULE I

INTRODUCTION

Lesson 1 Mathematical modelling


and Engineering
Problem Solving

Lesson 2 Programming and


Software

Lesson 3 Approximations and


Round-off Errors

MATH122 Module I
2

MODULE I

MODELLING, COMPUTERS AND ERROR ANALYSIS

 INTRODUCTION

Numerical methods are techniques by which mathematical problems


are formulated so that they can be solved with arithmetic operations.
Although there are many kinds of numerical methods, they have one common
characteristic: they invariably involve large numbers of tedious arithmetic
calculations. It is little wonder that with the development of fast, efficient
digital computers, the role of numerical methods in engineering problem
solving has increased dramatically in recent years.

OBJECTIVES

After studying the module, you should be able to:

1. Understand the relevance of numerical methods in engineering


problem solving.
2. Define the concept of approximation and precision in solving
mathematical equations using numerical methods
3. Explain errors in computations

MATH122 Module I
3

 DIRECTIONS/ MODULE ORGANIZER

There are three lessons in the module. Read each lesson carefully then
answer the exercises/activities to find out how much you have benefited from
it. Work on these exercises carefully and submit your output to your
instructor.

In case you encounter difficulty, discuss this with your instructor during
the face-to-face meeting.

MATH122 Module I
4

Lesson 1

 Mathematical Modelling and


Engineering Problem Solving

A mathematical model can be broadly defined as a formulation or equation


that expresses the essential features of a physical system or process in
mathematical terms. In a very general sense, it can be represented as a
functional relationship of the form

A Simple Mathematical Model

Dependent variable-a characteristic that usually reflects the behavior or


state of the system
Independent variables-dimensions, such as time and space, along which the
system’s behavior is being determined
Parameters-constants reflective of the system’s properties or composition
Forcing functions-external influences acting upon the system

Modeling: Newton’s Second Law of Motion


Statement:The time rate of change of momentum of a body is equal to the
resultant force acting on it
𝐹𝐹 = 𝑚𝑚𝑚𝑚
Forcing function
𝐹𝐹 (net force acting on the object)
Dependent variable ≫ 𝑎𝑎 =
𝑚𝑚
(acceleration)
Parameter
(mass of object)
–No independent variable is involved
–E.g., it can be used to determine the terminal velocity of a free-falling body
near the earth’s surface

MATH122 Module I
5

More on Newton’s Second Law of Motion

• It describes a natural process or system in mathematical terms


• It represents an idealization and simplification of reality
–Ignore negligible details of the natural process and focus on its essential
manifestations
–Exclude the effects of “relativity” that are of minimal importance when
applied to object and forces that interact on or about the earth’s surface at
velocities and on scales visible to humans
• It yields reproducible results and can be used for predictive purposes
–Have generalization capabilities

Figure 1.1 The engineering problem-solving process.

MATH122 Module I
6

Bungee-Jumping

•For a body falling within the vicinity of the earth, the net force is composed
of two opposing forces
𝐹𝐹 = 𝐹𝐹𝐷𝐷 + 𝐹𝐹𝑈𝑈
- The downward pull of gravity 𝐹𝐹𝐷𝐷
•The force due to gravity can be formulated as
𝐹𝐹𝐷𝐷 = 𝑚𝑚𝑚𝑚
– 𝑔𝑔 is the acceleration due to gravity (9.81𝑚𝑚/𝑠𝑠 2 )
- The upward force of air resistance 𝐹𝐹𝑈𝑈
• A good approximation is to formulate it as
𝐹𝐹𝑈𝑈 = −𝑐𝑐𝑑𝑑 𝑣𝑣 2

– 𝑣𝑣 is the velocity; 𝑐𝑐𝑑𝑑 is the lumped drag coefficient,


accounting for the properties of the falling object like shape
or surface roughness

»The greater the fall velocity, the greater the upward force
due to air resistance

• The net force therefore is the difference between downward and


upward force. We can a differential equation regarding the velocity
of the object
𝑑𝑑𝑑𝑑 𝑐𝑐𝑑𝑑
= 𝑔𝑔 − 𝑣𝑣 2
𝑑𝑑𝑑𝑑 𝑚𝑚
• The exact solution of 𝑣𝑣 can not be obtained using simple algebraic
manipulation but rather using more advanced calculus techniques
(when 𝑣𝑣 (𝑡𝑡) = 0, 𝑡𝑡 = 0 )
𝑔𝑔𝑔𝑔 𝑔𝑔𝑐𝑐𝑑𝑑 Here 𝑡𝑡 is independent variable,
𝑣𝑣(𝑡𝑡) = � tanh(� 𝑡𝑡)
𝑐𝑐𝑑𝑑 𝑚𝑚 𝑣𝑣(𝑡𝑡) is dependent variable, 𝑐𝑐𝑑𝑑 and
𝑚𝑚 are parameters, and 𝑔𝑔 is the
forcing function.
(an analytical or closed-form solution that 𝑒𝑒 𝑥𝑥 − 𝑒𝑒 −𝑥𝑥
tanh(𝑥𝑥 ) =
𝑒𝑒 𝑥𝑥 + 𝑒𝑒 −𝑥𝑥
can exactly satisfy the original differential
equation)

MATH122 Module I
7

Example 1.1
A bungee jumper with a mass of 68.1 kg leaps from a stationary hot air balloon
(the drag coefficient is 0.25 kg/m)
a. Compute the velocity for the first 12s of free fall
b. Determine the terminal velocity that will attained for an infinite long
cord

𝑔𝑔𝑔𝑔 𝑔𝑔𝑐𝑐𝑑𝑑 9.8(68.1) 9.8(0.25)


𝑣𝑣 (𝑡𝑡) = � tanh(� 𝑡𝑡) = � tanh (� 𝑡𝑡)
𝑐𝑐𝑑𝑑 𝑚𝑚 0.25 68.1
= 51.6674tanh (0.18967𝑡𝑡)
𝑣𝑣 (12) = 50.5891

𝑣𝑣 (∞) = 51.6674

• Using a computer (or a calculator), the model can be used to generate


a graphical representation of the system

𝑚𝑚𝑚𝑚 = 𝑐𝑐𝑑𝑑 𝑣𝑣 2

𝑔𝑔𝑔𝑔
𝑣𝑣 = �
𝑐𝑐𝑑𝑑

An example of Numerical Modeling

1. Numerical methods are those in which the mathematical problem is


reformulated so it can be solved by arithmetic operations

MATH122 Module I
8

–E.g., the time rate of change of velocity


mentioned earlier:
𝑑𝑑𝑑𝑑 ∆𝑣𝑣 𝑣𝑣(𝑡𝑡𝑖𝑖+1 ) − 𝑣𝑣(𝑡𝑡𝑖𝑖 )
≈ =
𝑑𝑑𝑑𝑑 ∆𝑡𝑡 𝑡𝑡𝑖𝑖+1 − 𝑡𝑡𝑖𝑖

A finite-difference approximation of
the derivative at time 𝑡𝑡𝑖𝑖

𝑑𝑑𝑑𝑑 ∆𝑣𝑣
Notice that = lim
𝑑𝑑𝑑𝑑 ∆𝑡𝑡→0 ∆𝑡𝑡

2. Substituting the finite difference into the differential equation gives


𝑑𝑑𝑑𝑑 𝑐𝑐𝑑𝑑
= 𝑔𝑔 − 𝑣𝑣 2
𝑑𝑑𝑑𝑑 𝑚𝑚
𝑣𝑣(𝑡𝑡𝑖𝑖+1 ) − 𝑣𝑣(𝑡𝑡𝑖𝑖 ) 𝑐𝑐𝑑𝑑
= 𝑔𝑔 − 𝑣𝑣(𝑡𝑡𝑖𝑖 )2
𝑡𝑡𝑖𝑖+1 − 𝑡𝑡𝑖𝑖 𝑚𝑚

Solve for
𝑐𝑐𝑑𝑑
𝑣𝑣 (𝑡𝑡𝑖𝑖+1 ) = 𝑣𝑣(𝑡𝑡𝑖𝑖 ) + �𝑔𝑔 − 𝑣𝑣 (𝑡𝑡𝑖𝑖 )2 � ((𝑡𝑡𝑖𝑖+1 − 𝑡𝑡𝑖𝑖 )
𝑚𝑚
New = old + slope x step

This approach is formally called Euler’s method.

3. Applying Euler's method in 2 s intervals yields:

MATH122 Module I
9

How do we improve the solution? –Smaller steps

Conservation laws

Conservation laws provide the foundation for many model functions


–They boil down

Change = increases - decreases

–Can be used to predict changes with respect to time by given it a


special name “the time-variable (or transient)” computation
–If no change occurs, the increases and decreases must be in balance

Change = 0 = increases - decreases

•It is given a special name, the “steady-state” calculation

1. Example: Fluid Flow

Figure 1.2 A flow balance for steady incompressible fluid flow at the junction
of pipes.
–For steady-state incompressible fluid flow in pipes
Flow in = Flow out
•The flow out of the fourth pipe must be 60
2. Different fields of engineering and science apply these laws to
different paradigms within the field
Among these laws are
–Conservation of mass

MATH122 Module I
10

–Conservation of momentum
–Conservation of charge
–Conservation of energy

Table 1.1 Devices and types of balances that are commonly used in the four
major areas of engineering. For each case, the conservation law upon which
the balance is based is specified.

Learning Activity

Compute the velocity of a free-falling parachutist using Euler’s method for


the case where m=80 kg and c=10 kg/s. Perform the calculation from t =0 to
20 s with a step size of 1 s. Use an initial condition that the parachutist has
an upward velocity of 20 m/s at t =0. At t =10 s, assume that the chute is
instantaneously deployed so that the drag coefficient jumps to 60 kg/s.

MATH122 Module I
11

Lesson 2

 Programming
and Software

I. PACKAGES AND PROGRAMMING


Today, there are two types of software users. On one hand, there are
those who take what they are given. That is, they limit themselves to the
capabilities found in the software’s standard mode of operation. For example,
it is a straightforward proposition to solve a system of linear equations or to
generate a plot of x-y values with either Excel or MATLAB software. Because
this usually involves a minimum of effort, most users tend to adopt this
“vanilla” mode of operation. In addition, since the designers of these
packages anticipate most typical user needs, many meaningful problems can
be solved in this way.
First, you can look for a different package and see if it is capable of
solving the problem. You will see, neither one is all encompassing and each
has different strengths. By being conversant with both, you will greatly
increase the range of problems you can address.
Second, you can grow and become a “power user” by learning to write
Excel VBA1 macros or MATLAB M-fi les. They are nothing more than computer
programs that allow you to extend the capabilities of these tools. Because
engineers should never be content to be tool limited, they will do whatever
is necessary to solve their problems. A powerful way to do this is to learn to
write programs in the Excel and MATLAB environments. Furthermore, the
programming skills required for macros and M-fi les are the same as those
needed to effectively develop programs in languages like Fortran 90 or C.
Our emphasis here is on facets of programming that directly affect its
use in engineering problem solving.
Computer Programs
Computer programs are merely a set of instructions that direct the
computer to perform a certain task. Since many individuals write programs
for a broad range of applications, most high-level computer languages, like
Fortran 90 and C, have rich capabilities. Although some engineers might need
to tap the full range of these capabilities, most merely require the ability to
perform engineering-oriented numerical calculations.

MATH122 Module I
12

Few programming techniques.


• Simple information representation (constants, variables, and type
declarations).
• Advanced information representation (data structure, arrays, and
records).
• Mathematical formulas (assignment, priority rules, and intrinsic
functions).
• Input/output.
• Logical representation (sequence, selection, and repetition).
• Modular programming (functions and subroutines).

II. STRUCTURED PROGRAMMING

In the early days of computers, programmers usually did not pay much
attention to whether their programs were clear and easy to understand.
Today, it is recognized that there are many benefits to writing organized,
well-structured code. Aside from the obvious benefit of making software
much easier to share, it also helps generate much more efficient program
development. That is, well-structured algorithms are invariably easier to
debug and test, resulting in programs that take a shorter time to develop,
test, and update.
Structured programming is a set of rules that prescribe good style
habits for the programmer. Although structured programming is flexible
enough to allow considerable creativity and personal expression, its rules
impose enough constraints to render the resulting codes far superior to
unstructured versions. In particular, the finished product is more elegant and
easier to understand.
A key idea behind structured programming is that any numerical
algorithm can be composed using the three fundamental control structures:
sequence, selection, and repetition. By limiting ourselves to these structures,
the resulting computer code will be clearer and easier to follow.
An alternative approach to express an algorithm that bridges the gap
between flowcharts and computer code is called pseudocode. This technique
uses code-like statements in place of the graphical symbols of the flowchart.
One advantage of pseudocode is that it is easier to develop a program
with it than with a flowchart. The pseudocode is also easier to modify and
share with others.

MATH122 Module I
13

A. Logical Representation

Sequence. The sequence structure expresses the trivial idea that unless you
direct it otherwise, the computer code is to be implemented one instruction
at a time. As in Fig.2.1 below, the structure can be expressed generically as
a flowchart or as pseudocode.

Fig 2.1 (a) Flowchart and


(b) pseudocode for the
sequence structure.

Selection. In contrast to the step-by-step sequence structure, selection


provides a means to split the program’s flow into branches based on the
outcome of a logical condition. Figure 2.2 shows the two most fundamental
ways for doing this.
The single-alternative decision, or IF/THEN structure (Fig. 2.2a),
allows for a detour in the program flow if a logical condition is true. If it is
false, nothing happens and the program moves directly to the next
statement following the ENDIF. The double-alternative decision, or
IF/THEN/ELSE structure (Fig. 2.2b), behaves in the same manner for a true
condition. However, if the condition is false, the program implements the
code between the ELSE and the ENDIF.

FIGURE 2.2 Flowchart and pseudocode for simple selection constructs. (a)
Single-alternative selection (IF/THEN) and (b) double alternative selection
(IF/THEN/ELSE).

MATH122 Module I
14

Although the IF/THEN and the IF/THEN/ELSE constructs are sufficient


to construct any numerical algorithm, two other variants are commonly
used. Suppose that the ELSE clause of an IF/THEN/ELSE contains another
IF/THEN. For such cases, the ELSE and the IF can be combined in the
IF/THEN/ELSEIF structure shown in Fig. 2.3a.
Notice how in Fig. 2.3a there is a chain or “cascade” of decisions.
The first one is the IF statement, and each successive decision is an ELSEIF
statement. Going down the chain, the first condition encountered that tests
true will cause a branch to its corresponding code block followed by an exit
of the structure. At the end of the chain of conditions, if all the conditions
have tested false, an optional ELSE block can be included.
The CASE structure is a variant on this type of decision making (Fig.
2.3b). Rather than testing individual conditions, the branching is based on
the value of a single test expression. Depending on its value, different
blocks of code will be implemented. In addition, an optional block can be
implemented if the expression takes on none of the prescribed values (CASE
ELSE).

FIGURE 2.3 Flowchart and pseudocode for supplementary selection or


branching constructs. (a) Multiplealternative selection (IF/THEN/ELSEIF) and
(b) CASE construct.

MATH122 Module I
15

Repetition. Repetition provides a means to implement instructions


repeatedly. The resulting constructs, called loops, come in two “flavors”
distinguished by how they are terminated.
The first and most fundamental type is called a decision loop because
it terminates based on the result of a logical condition. Figure 2.4 shows the
most generic type of decision loop, the DOEXIT construct, also called a
break loop. This structure repeats until a logical condition is true.
It is not necessary to have two blocks in this structure. If the first
block is not included, the structure is sometimes called a pretest loop
because the logical test is performed before anything occurs. Alternatively,
if the second block is omitted, it is called a posttest loop. Because both
blocks are included, the general case in Fig. 2.4 is sometimes called a
midtest loop.
It should be noted that the DOEXIT loop was introduced in Fortran 90
in an effort to simplify decision loops. This control construct is a standard
part of the Excel VBA macro language but is not standard in C or MATLAB,
which use the so-called WHILE structure.
The break loop in Fig. 2.4 is called a logical loop because it
terminates on a logical condition. In contrast, a count-controlled or DOFOR
loop (Fig. 2.5) performs a specified number of repetitions, or iterations.
The count-controlled loop works as follows. The index (represented
as i in Fig. 2.5) is a variable that is set at an initial value of start. The
program then tests whether the index is less than or equal to the final
value, finish. If so, it executes the body of the loop, and then cycles back to
the DO statement. Every time the ENDDO statement is encountered, the
index is automatically increased by the step. Thus, the index acts as a
counter. Then, when the index is greater than the final value (finish), the
computer automatically exits the loop and transfers control to the line
following the ENDDO statement. Note that for nearly all computer
languages, including those of Excel and MATLAB, if the step is omitted, the
computer assumes it is equal to 1.

FIGURE 2.4 The DOEXIT or break loop.

MATH122 Module I
16

FIGURE 2.5 The count-controlled or DOFOR construct


III. EXCEL
Excel is the spreadsheet produced by Microsoft, Inc. Spreadsheets are
a special type of mathematical software that allow the user to enter and
perform calculations on rows and columns of data. As such, they are a
computerized version of a large accounting worksheet on which large
interconnected calculations can be implemented and displayed. Because the
entire calculation is updated when any value on the sheet is changed,
spreadsheets are ideal for “what if?” sorts of analysis.
Excel has some built-in numerical capabilities including equation
solving, curve fitting, and optimization. It also includes VBA as a macro
language that can be used to implement numerical calculations. Finally, it
has several visualization tools, such as graphs and three-dimensional surface
plots, that serve as valuable adjuncts for numerical analysis. In the present
section, we will show how these capabilities can be used to solve the
parachutist problem.
Example: 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.

Before we write a macro program to calculate the numerical value,


we can make our subsequent work easier by attaching names to the
parameter values. To do this, select cells A3:B5 (the easiest way to do this
is by moving the mouse to A3, holding down the left mouse button and

MATH122 Module I
17

dragging down to B5). Next, go to the Formulas tab and in the Defined
Names group, click Create from Selection. This will open the Create
Names from Selection dialog box, where the Left column box should be
automatically selected. Then click OK to create the names. To verify that
this has worked properly, select cell B3 and check that the label “m”
appears in the name box (located on the left side of the sheet just below
the menu bars).
Move to cell C8 and enter the analytical solution
𝑚𝑚 𝑐𝑐𝑐𝑐
= 9.81 ∗ ∗ (1 − exp �− ∗ 𝐴𝐴8�)
𝑐𝑐𝑐𝑐 𝑚𝑚
When this formula is entered, the value 0 should appear in cell C8. Then
copy the formula down to cell C9 to give a value of 16.42175 m/s.
All the above is typical of the standard use of Excel. For example, at this
point you could change parameter values and see how the analytical
solution changes.
IV. MATLAB
MATLAB is the flagship software product of The MathWorks, Inc., which was
cofounded by the numerical analysts Cleve Moler and John N. Little. As the
name implies, MATLAB was originally developed as a matrix laboratory. To
this day, the major element of MATLAB is still the matrix. Mathematical
manipulations of matrices are very conveniently implemented in an easy-to-
use, interactive environment. To these matrix manipulations, MATLAB has
added a variety of numerical functions, symbolic computations, and
visualization tools. As a consequence, the present version represents a fairly
comprehensive technical computing environment.
For example, suppose that we wanted to determine the analytical solution
to the parachutist problem. This could be done with the following series of
MATLAB commands.
>> g=9.81;
>> m=68.1;
>> cd=12.5;
>> tf=2;
>> v=g*m/cd*(1−exp(−cd/m*tf))

with the result being displayed as

v=
16.4217

MATH122 Module I
18

V. MATHCAD

Mathcad attempts to bridge the gap between spreadsheets like Excel


and notepads. It was originally developed by Allen Razdow of MIT who
cofounded Mathsoft, Inc., which published the first commercial version in
1986. Today, Mathsoft is part of Parametric Technology Corporation (PTC)
and Mathcad is in version 15.
Mathcad is essentially an interactive notepad that allows engineers
and scientists to perform a number of common mathematical, data-
handling, and graphical tasks. Information and equations are input to a
“whiteboard” design environment that is similar in spirit to a page of paper.
Unlike a programming tool or spreadsheet, Mathcad’s interface accepts and
displays natural mathematical notation using keystrokes or menu palette
clicks—with no programming required. Because the worksheets contain live
calculations, a single keystroke that changes an input or equation instantly
returns an updated result.
Mathcad can perform tasks in either numeric or symbolic mode. In
numeric mode, Mathcad functions and operators give numerical responses,
whereas in symbolic mode results are given as general expressions or
equations. Maple V, a comprehensive symbolic math package, is the basis of
the symbolic mode and was incorporated into Mathcad in 1993.

Learning Activity

Develop well-structured programs to (a) determine the square root of


the sum of the squares of the elements of a two-dimensional array (i.e., a
matrix) and (b) normalize a matrix by dividing each row by the maximum
absolute value in the row so that the maximum element in each row is 1.

MATH122 Module I
19

Lesson 3

 Approximations and Round-off


Errors

The concept of errors is very important to the effective use of


numerical methods. Usually we can compare the numerical result with the
analytical solution. However, when the analytical solution is not available
(which is usually the case), we have to estimate the errors. The first step to
minimize the errors is to apply simplifications to our problem and use simple
formulations that can be solved analytically. However, sometimes the results
are far from the reality. Hence, more complex formulations are needed, but
as a consequence, it is more difficult to solve them analytically. Solving these
problems will be then only possible by using numerical methods.

However, the problem with numerical methods is that they yield approximate
results. It is, therefore, important to develop criteria to determine if our
approximation of the solution is acceptable.

Accuracy and precision


The errors associated with computation or measurements can be
characterized by their accuracy and their precision.
Accuracy: how closely a computed or measured value agrees with the true
value.
Precision: how closely individual computed or measured values agree with
each other.

Figure.3.1. accuracy and precision


(a) inaccurate and imprecise; (b)
accurate and imprecise; (c)
inaccurate and precise; (d) accurate
and precise.

In engineering problems, we try to minimize both imprecision and inaccuracy.

MATH122 Module I
20

Errors definition

The errors encountered in numerical methods can be classified into:


Truncation errors: defined as the errors due the fact that we used an
approximation to solve the problem instead of solving the problem
analytically.
Round-off errors: appears when numbers having limited significant figures
are used to represent exact numbers (example: π; e; …).
When considering the errors due to the fact that we are using numerical
methods, the true value for the solution can be written as:
True value = approximation + error
Hence, the error can be computed as:

Error (Et) = True value – approximation

Et is the true error since we are comparing the approximation with the true
value.

To take into account the magnitude of the error, it is preferable to normalize


the error to the true value:
𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻 𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆
𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻 𝒇𝒇𝒇𝒇𝒇𝒇𝒇𝒇𝒇𝒇𝒇𝒇𝒇𝒇𝒇𝒇𝒇𝒇𝒇𝒇 𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒕𝒕𝒕𝒕𝒕𝒕𝒕𝒕 𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆 =
𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻 𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗

We can express this in percentage as:


𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻 𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗 − 𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨
𝜺𝜺𝒕𝒕 = � � 𝒙𝒙 𝟏𝟏𝟏𝟏𝟏𝟏%
𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻 𝑽𝑽𝑽𝑽𝑽𝑽𝑽𝑽𝑽𝑽

Where 𝜀𝜀𝑡𝑡 is the relative error.

An important point to notice is that in the definition of the true error, we


used the true value of the solution. However, the true value is not always
available and we have, therefore, to compute an approximation of the error.
For that, we normalize the error using the best available estimate of the true
value:

MATH122 Module I
21

𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨 𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆
𝜺𝜺𝒂𝒂 = 𝒙𝒙 𝟏𝟏𝟏𝟏𝟏𝟏%
𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨

However, in real life it is not obvious to know the approximation.


As several numerical methods include an iterative process, we will define the
error as:

𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪 𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨 − 𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷 𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨


𝜺𝜺𝒂𝒂 = � � 𝒙𝒙 𝟏𝟏𝟏𝟏𝟏𝟏%
𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪 𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨𝑨

You can notice, from the above formulation, that the error can be negative
or positive. But in reality the most important thing for us is that the absolute
error has to be lower than a certain limit εs (this limit is very dependent upon
the application and the computational time):

|𝜀𝜀𝑎𝑎 | < 𝜀𝜀𝑠𝑠

A. Round-off errors

These errors originate from the fact that computers retain only a fixed
number of significant figures during calculation. These errors are, therefore,
directly related to the manner in which numbers are stored in a computer.
In fact, remember that instead of using decimal number system (or base-10)
as we do, a computer uses a binary system (or base-2). Why? Because, this
corresponds to the on/off positions of electronic components.

In a 16-bit computer word, the numbers will be stored as:

B. Floating point representation

MATH122 Module I
22

The floating-point representation is used to store fractional quantities. The


number is expressed under the following form:
m.be

where (m) is the mantissa; (b) is the base of the number system used and (e)
is the exponent. As an example, the number 156.76 could be represented as
0.15676. 103 in a floating point base10 system.
Usually for the storage of fractional quantities, the first bit is reserved to the
sign, then the signed exponent, and the last bits for the mantissa. Therefore,
for an optimal storage, if the mantissa has leading zero digits, they are
removed and transferred to the exponent.
Example

1/34 = 0.0294117

Would be stored as: 0.0294. 100 However, because the zero before the 2, we
lose the digit (1). A better storage is:

0.2941. 10-1

Floating-point representation allows both fractions and large numbers to be


stored, however, this has a computational cost since floating-point numbers
take more time to be processed than integer numbers, and it has also a
precision price, since only a finite number of figures can be stored in the
mantissa.
In 64 bits using IEEE 754 standard

C. Limited range of quantities that may be represented

As the number of bits is limited some very large or very small numbers can
not be represented. If you try to store a number outside this range you will
generate an overflow error.

- How to deal the problem of 𝜋𝜋?

MATH122 Module I
23

𝜋𝜋 = 3.141592653558

To be stored on a base-10 system carrying seven significant figures:


we can omit the figures after the seventh: 𝜋𝜋 = 3.141592; this is called
chopping.
This will generate an error of 0.0000065
Or
we can round the eighth figure: 𝜋𝜋 = 3.141593
This will generate an error of -0.0000035
Therefore, rounding reduces the error

D. Comparison between two numbers

When comparing two numbers, it is wiser to test that the difference is less
than an acceptably small tolerance rather than to test for equality:
Example
If you want to test if a=b, the best solution is to write in your program:
If
|𝑎𝑎 − 𝑏𝑏 | ≤ 𝜀𝜀

Machine epsilon can be used as a criterion to ensure a certain portability of


the code, since it will not depend on the storage characteristics of the
machine used.

Machine epsilon can be used as a criterion to ensure a certain portability of


the code, since it will not depend on the storage characteristics of the
machine used.

𝜀𝜀 = 𝑏𝑏𝑏𝑏𝑏𝑏𝑏𝑏 1−𝑡𝑡 t: is the number of digits in the mantissa

MATH122 Module I
24

Arithmetic manipulation of computer numbers


Basic arithmetic operations such as addition, subtraction or multiplication can
lead to significant round off errors.

- Addition

The mantissa of the number of the smaller exponent is modified so that the
exponents are the same. If we consider a computer with just 4-digit mantissa
and a 1-digit exponent, if we add 0.1557 . 101 to 0.4381 . 10-1, the following
process will occur if chopping is used:
0.4318 . 10-1 0.004318 . 101
Then,
0.1557 . 101
0.0043 . 101
---------------
0.1600 . 101

- Subtraction

The same thing as for addition happens with subtraction:


0.3641 . 102
- 0.2686 . 102
---------------
0.0955 . 102

Due to the presence of the zero just before the (9), the result is normalized:
0.0955 . 102 0.9550 . 101
Note that we added a zero to fill the space of the 4-digit mantissa.

- Multiplication
normalization

0.1363 . 103 × 0.6423 . 10-1 = 0.08754549 . 102


0.8754549 . 101
chopping

0.8754 . 101

MATH122 Module I
25

The errors produced by these arithmetic manipulations may seem negligible,


but, several methods in engineering require an iterative process to find the
solution. The computations are, therefore, interdependent and this might
lead to a dramatic increase in the round-off errors.

Errors due to addition of large and small numbers

Example

4000 + 0.0010
Is computed as:
0.4000 . 104
0.0000001 . 104
chopping
----------------------
0.4000001 . 104 0.4000 . 104 The small
number is completely ignored

This kind of problems usually occurs in the computation of infinite series


where the first terms are large. To avoid this problem, you have to compute
the series in an ascending order.

Subtractive cancellation

This error occurs when we perform the substraction of nearly equal floating-
point numbers.

Example

Calculate √9.01 − 3 on a 3-decimal-digit computer.

To avoid the problem of subtractive cancellation,


use double precision (use the function Double(X) with SciLab or Matlab ).
Single precision [32 bits] - 24 bits assigned to mantissa (first bit
assumed =1 and not stored). - 8 bits to signed exponent.

MATH122 Module I
26

Double precisions [64 bits] - 56 bits assigned to mantissa.


- 8 bits to signed exponent.

Learning Activity

1. Convert the following base-2 numbers to base-10: (a) 101101, (b)


101.011, and (c) 0.01101.

2. Convert the following base-8 numbers to base-10: 71,263 and 3.147.

3. Differentiate accuracy from precision.

Summative Test

1. For the free-falling parachutist with linear drag, assume a first jumper
is 70 kg and has a drag coefficient of 12 kg/s. If a second jumper has a
drag coefficient of 15 kg/s and a mass of 80 kg, how long will it take
him to reach the same velocity the first jumper reached in 9 s?
2. The average daily temperature for an area can be approximated by the
following function,
𝑇𝑇 = 𝑇𝑇𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚 + (𝑇𝑇𝑝𝑝𝑝𝑝𝑝𝑝𝑝𝑝 − 𝑇𝑇𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚 ) 𝑐𝑐𝑐𝑐𝑐𝑐 (𝜔𝜔(𝑡𝑡 − 𝑡𝑡𝑝𝑝𝑝𝑝𝑝𝑝𝑝𝑝 ))
where 𝑇𝑇𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚 = the average annual temperature, 𝑇𝑇𝑝𝑝𝑝𝑝𝑝𝑝𝑝𝑝 = the
peak temperature, 𝜔𝜔 = the frequency of the annual variation (=
2𝜋𝜋/365), and 𝑡𝑡𝑝𝑝𝑝𝑝𝑝𝑝𝑝𝑝 = day of the peak temperature (≅ 205 𝑑𝑑). Develop
a program that computes the average temperature between two days
of the year for a particular city. Test it for (a) January–February (t = 0
to 59) in Miami, Florida (𝑇𝑇𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚 = 22.18C; 𝑇𝑇𝑝𝑝𝑝𝑝𝑝𝑝𝑝𝑝 = 28.38C), and (b) July–
August (t = 180 to 242) in Boston, Massachusetts (𝑇𝑇𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚 = 10.78C;
𝑇𝑇𝑝𝑝𝑝𝑝𝑝𝑝𝑝𝑝 = 22.98C).
3. (a) Evaluate the polynomial

MATH122 Module I
27

𝑦𝑦 = 𝑥𝑥 3 − 5𝑥𝑥 2 + 6𝑥𝑥 + 0.55


at x = 1.37. Use 3-digit arithmetic with chopping. Evaluate the percent
relative error.
(b) Repeat (a) but express y as
𝑦𝑦 = �(𝑥𝑥 − 5)𝑥𝑥 + 6�𝑥𝑥 + 0.55
Evaluate the error and compare with part (a).

 MODULE SUMMARY

There are three lessons in module I.


Lesson 1. The engineering applications are designed to illustrate how
numerical methods are actually employed in the engineering problem-solving
process. As such, they will permit us to explore practical issues that arise in
real-world applications. Making these connections between mathematical
techniques such as numerical methods and engineering practice is a critical
step in tapping their true potential.

Lesson 2 deals with programming and software that are widely used in
Numerical Analysis.

Lesson 3 deal with Approximations and round-off of errors. It contains


the different computation of errors that will be needed in the next modules.

Congratulations! You have just studied Module I.

MATH122 Module I

You might also like