You are on page 1of 43

1

Lecture 1 - Introduction
Dr. Nasir M Mirza
Numerical Methods
Email: nasirmm@yahoo.com
2
Lectures Goals
General Introduction to Computer Applications in
Engineering and Sciences
Introduction to numerical analysis
Why you should be able to write and understand
computer programs for numerical methods?
Computer languages C & C++ and Matlab a
Mathematical Laboratory
3
Books on Numerical Analysis
Text Books:
1. Numerical Analysis, By Burden & Faires, Recent
Edition.
2. Numerical methods for engineers and scientists by A.
C. Bajpai, I.M. Calus and J.A.Fairley;

Softwares: C++ or Matlab & SIMULINK
4
Introduction
Professor: Dr. Nasir M Mirza
Office : 104 BLOCK-A; PIEAS, P.O.
Nilore, Islamabad, 45650.

Email: nasirmm@yahoo.com
URL: http://www.pieas.edu.pk
5
Grade Breakdown
Homework: 20 %
Exam 1: 20 %
Exam 2: 20 %
Final : 40 %

6
Topics
Matlab or C++
Computer Errors
Roots f(x) = 0
Linear Methods
Nonlinear Methods
Linear Systems
LU Decomposition
Eigenvalue Analysis
Fitting Data
Interpolation
Curve Fitting
Numerical Integration
ODEs
Initial Value Problems
Systems of ODEs
Boundary Value
Problems
7
Why numerical analysis and methods?
Integration becomes easy by use of numerical methods;
When you wish to solve simultaneous linear equations, you need
to find inverse of a matrix A. Thou can is is easy when you have
three equations and three unknown. If say you have 50 equations
and fifty unknowns then with help of digital computers and
numerical analysis you can solve this.
Say you have to solve one equation exp(x)=10 x. it will be very
troublesome or impossible to solve it analytically. However,
numerically it is very easy to solve it.
Complex differential equations can be solved very easily using
numerical analysis. Event set of coupled differential equations
can be solved very quickly and easily using numerical methods.
When Discrete data is given, one can differentiate and integrate
using numerical techniques.
8
What you need for numerical analysis
A good scientific calculator for numericals.
When you wish to solve simultaneous linear equations,
say 50 equations and fifty unknowns then you will need
digital computers (say a good PC).
You will also need good knowledge of one computer
programming language (say C or C++ or MATLAB).
Good knowledge of mathematics will also help.
A neat software to plot results is also needed.
9
Applications

Signal Processing
CFD (Computational
Fluid Dynamics)
Structural Analysis
Finite Element Analysis


Interpolation
Optimization
CAD (Computer Aided-
Drafting)
Data Collection
10
Numerical Accuracy and Errors
Whenever calculations are performed there are
many possible sources of errors. These include
Mistakes made by person carrying out calculations,
The use of inaccurate formula;
The use of inaccurate data (or round-off errors).
The first type of error should not be there at all.
The second type is due to chopping off an
infinite series and this error is called truncation
error.


11
Truncation Errors
This type is due to chopping off an infinite series. For example; let us
approximate the first derivative at a point x = a by following form:
The accuracy will increase when h is decreased. To show this, consider
f(x) =exp(2x) ; we also know, df/dx =2exp(2x)

For x =2; exact answer is 109.1963.
Now using above approximate formula, we find values
h
a f h a f
dx
dy ) ( ) ( +
=
2635 . 134
2 . 0
5982 . 54 4509 . 81
2 . 0
) 2 2 exp( ) 2 . 2 2 exp( ) ( ) (
=

=

=
+
=
h
a f h a f
dx
dy
8412 . 114
05 . 0
5982 . 54 3403 . 60
05 . 0
) 2 2 exp( ) 05 . 2 2 exp( ) ( ) (
=

=

=
+
=
h
a f h a f
dx
dy
2906 . 110
01 . 0
5982 . 54 7011 . 55
01 . 0
) 2 2 exp( ) 01 . 2 2 exp( ) ( ) (
=

=

=
+
=
h
a f h a f
dx
dy
12
Roundoff Errors
When we were computig exp(4) or exp(4.1) we were rounding off the
results. That is how many digits are written after the decimal places or
significant figures.



When rounding off one digit:
if digit lies in the range 0 4 , the previous digit is unchanged.
if the digit lies in the range 6 9, the previous digit is increased by
one.
For example, 7.4727 becomes 7.473
76.34 becomes 76.34
15.235 becomes 15.24
When rounding off two digit:
if digit lies in the range 0 49 , the previous digit is unchanged.
if the digit lies in the range 51 99, the previous digit is increased by
one.
13
What is Error
Hence in rounding off 7.4727 becomes 7.473 and error is -0.0003
76.34 becomes 76.34 and error is 0.000
15.235 becomes 15.24 and error is -0.005

18.496 becomes 18.50 introducing error 0.004
17.208 becomes 17.21 introducing error -0.002
value e approximat value exact = c
The error, , in any quantity is given by
18.50 + 17.21 = 35.71 introducing error 0.006
18.50 - 17.21 = 1.29 introducing error -0.007
The individual errors may be positive or negative but when they are
added or subtracted they may reinforce each other.
14
Numerical Errors
Precision Limits
Stability
Convergence
Divergence
Alaising
Round-off Errors
Truncation Errors
Machine Precision
15
Example; first rounding
Let p = 0.54617 and q = 0.54601.
The exact value of r = p q
r = 0.54617 0.54601 = 0.00016
Here subtraction is performed using four-digit arithmetic.
Rounding p and q to four digits gives
p* = 0.5462 & q* - 0.5460,
r* = p* - q* = 0.0002
25 . 0
00016 . 0
0002 . 0 00016 . 0 *
=

=
r
r r
error relative
16
Example; now chopping
Let p = 0.54617 and q = 0.54601.
The exact value of r = p q
r = 0.54617 0.54601 = 0.00016
If chopping is used to obtain the four digits, then the four-
digit approximations to p, q, and r are
p* = 0.5461,
q* = 0.5460, and
r* = p* - q* = 0.0001.
375 . 0
00016 . 0
0001 . 0 00016 . 0 *
=

=
r
r r
error relative
17
Example 2
The loss of accuracy due to round-off error can often be
avoided by a reformulation of the problem, as illustrated
in the next example.
The quadratic formula states that the roots of ax
2
+ bx +
c = 0, when a 0, are
a
ac b b
x
a
ac b b
x
2
4
;
2
4
2
2
2
1

=
+
=
Using four-digit rounding arithmetic, consider this formula
applied to the equation x
2
+ 62.10x + 1 = 0, whose roots
are approximately

x
1
= -0.01610723 ; x
2
= -62.08390
18
Example 2
06 . 62 . 3852 000 . 4 . 3856
) 000 . 1 )( 000 . 1 )( 000 . 4 ( ) 10 . 62 ( 4
2 2
= = =
= = ac b
0200 . 0
2
06 . 62 10 . 62
2
4
) 1 (
2
=
+
=
+
=
a
ac b b
x fl
In this equation, b
2
is much larger than 4ac, so the
numerator in the calculation for x involves the subtraction
of nearly equal numbers. Since
We then have
Then relative error for x
1
= -0.01611 is
1
10 4 . 2
01611 . 0
02000 . 0 01611 . 0

=

+
= r
19
Example 2
10 . 62
000 . 2
2 . 124
2
06 . 62 10 . 62
2
4
) 1 (
2
=

=

=
+
=
a
ac b b
x fl
On the other hand, the calculation for x
2
involves the
addition of the nearly equal numbers. This presents no
problem since
Then relative error for x
1
= -0.01611 is
4
10 2 . 3
08 . 62
10 . 62 08 . 62

=

+
= r
This relative error is small.
20
Example 2
( )
( ) ac b b
c
x
ac b b a
ac
ac b b
ac b b
a
ac b b
x
4
2
4 2
4
4
4
2
4
2
1
2 2
2 2
1


=


=
|
|
.
|

\
|

+
=
4
10 2 . 6
01611 . 0
01610 . 0 01611 . 0

=

+
= r
The rationalization of the numerator can help in reducing
error in x
1
:
Using this we get
This relative error is small.
01610 . 0
2 . 124
000 . 2
06 . 62 10 . 62
000 . 2
) 1 ( =

=
+

= x fl
21
Example 2
( )
( ) ac b b
c
x
ac b b a
ac
ac b b
ac b b
a
ac b b
x
4
2
4 2
4
4
4
2
4
2
2
2 2
2 2
2


=
+

=
|
|
.
|

\
|
+
+
=
1
10 9 . 1
08 . 62
00 . 50 08 . 62

=

+
= r
If we use this formula for x
2
, it will be a mistake
Using this we get
This relative error is large due to
subtraction of nearly equal
numbers and a division.
00 . 50
0400 . 0
000 . 2
06 . 62 10 . 62
000 . 2
) 2 ( =

= x fl
22
Example 3
Accuracy loss due to roundoff error can also be reduced by rearranging
calculations, as shown in this example.
Evaluate: f(x) = x
3
6.1x
2
+ 3.2x + 1.5 at x = 4.71
Use the three-digit arithmetic.
Table gives the intermediate results in the calculations.
Note that the three-digit chopping values simply retain the leading
three digits, with no rounding involved, and differ significantly from the
three-digit rounding values.
x x
2
x
3
6.1x
2
3.2x
Exact 4.71 22.1841 104.487111 135.32301 15.072
(chopping) 4.71 22.1 104. 134. 15.0
(rounding) 4.71 22.2 105. 135. 15.1
23
Example 3
05 . 0
263899 . 14
5 . 13 263899 . 14
=

+
= r
Exact: f(4.71) = 104.487111 - 135.32301 + 15.072+ 1.5 = -14.263899;
Three-digit (chopping): f(4.71) = ((104. - 134.) + 15.0) + 1.5 = -13.5;
Three-digit (rounding): f(4.71) = ((105. - 135.) + 15.1) + 1.5 = -13.4.
The relative errors for the three-digit:
06 . 0
263899 . 14
4 . 13 263899 . 14
=

+
= r
For chopping:
For rounding:
As an alternative approach, f(x) can be written in a nested manner.
24
Example 3
As an alternative approach, f(x) can be written in a nested manner as
f(x) = x
3
- 6.1x
2
+ 3.2x + 1.5 = ((x - 6.1)x + 3.2)x + 1.5.
This gives Three-digit (chopping):
f(4.71) = ((4.71 - 6.1)4.71 + 3.2)4.71 + 1.5 = -14.2
and a three-digit rounding answer of -14.3.
The new relative errors are
Three-digit (chopping): relative error = 0.0045;
Three-digit (rounding): relative error = 0.0025
Nesting has reduced the relative error for the chopping approximation
to less than 10% of that obtained initially. For the rounding
approximation the improvement has been even more dramatic; the
error in this case has been reduced by more than 95%.
25
Computer Hardware Types

Personal Computer
Supercomputers
Vector Processors
Array Processors
Parallel Processor
26
Software

Operating Systems
Windows - NT, ME, Windows
Unix
VMS - VAX
Linux
27
Software
Languages
Fundamental Assembler (Bit manipulations)
Engineering Languages
Fortran
Cobol
Pascal
C++
Basic
HTML and Java
28
Software
Higher-Order Programming
Maple - Mathematical Programming Language
Mathematica - Mathematical Programming
Language
Java - Internet Programming Language
Matlab - Matrix Laboratory
29
Software
Tools
Word Processors
Spreadsheets
Database Management
Graphics
Mathematical Computer Codes
30
Matlab -Matrix Laboratory
Currently Matlab 7.0 is available on
This will be available on the network with a
SIMULINK tool box
Student Version is also available in the maket.

31
What is a program?
Program consist of three main components:

Input
Main Program - Numerical methods and
analysis and/or evaluation.
Output - Results.
32
Inputs
Numerical values
Initialization of the variables
Conditions
Equations

33
Main Program
Using flow charts, the programs can be designed
to perform a task. Using:

Loops
Conditions
Error Convergence
34
Output
Outputs are the results of the program. They can go
through a series of post-processing methods.
Numerical Values
Decisions
Graphs and Plots
35
MatLab
Variable Types
Integers
Real Values (Float)
Complex Numbers (a + ib)
a - real value
b - imaginary value (i is the square root of -1)
36
Matlab
Data types
Numerical
Scalars
Vectors
Matrices
Logic Types
Alpha/Numerical Types
37
Matlab
A scalar value is the simple number, a, 2,
3.14157,
A vector is a union of a
x = (x
1
, x
2
, x
3
, x
4
)
Transpose vector x
T
= x
1

x
2

x
3

x
4

38
Matlab
Matrix is a combination of vectors and scalars.
Scalar and vectors are subsets of matrices.
Matlab uses matrix to do mathematical
methods.
39
Matlab
Set of computer functions
Circular functions - sin(x),cos(x), tan(x), asin(x),
acos(x), atan(x)
Hyperbolic functions - sinh(x), cosh(x), tanh(x)
Logarithmic functions - ln(x), log(x), exp(x)
Logic functions - abs(x), real(x), imag(x)
40
Matlab
Simple commands
clc - clears window
clg - clear graphic window
clear - clears the workspace
who - variable list
whos - variable list with size
help - when doubt use it!
41
Matlab
Simple commands and symbols
^C - an escape from a loop
inf - infinity
NaN - No numerical value
42
Scalar Operations
Addition - a + b
Subtraction - a - b
Multiplication - a * b
Right Division - a / b
Left Division - b \ a
Exponential - a^b
43
Order of Precedence of Arithmetic
Operations
Precedence
( 1 ) - Parenthesis
( 2 ) - Exponential from left to right
( 3 ) - Multiplication and division from left
to right.
( 4 ) - Addition and subtraction from left to
right.

You might also like