Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 40

Numerical Methods

Lecture 1 - Introduction

NADIA IMRAN

Nadia.imran@bui.edu.pk

1
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

2
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.

3
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.

4
Applications

• Signal Processing • Interpolation


• CFD (Computational • Optimization
Fluid Dynamics) • CAD (Computer Aided-
• Structural Analysis Drafting)
• Finite Element Analysis • Data Collection

5
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.

6
• R= 2.1567346
• R1=2.157 (roundoff upto 2 decimal digits)
• R2=2.156 (chopping off upto 3 decimal digits)

• Abs Error= Exact- approximate.
• =2.1567346-2.16
• =0.0003654
• Abs error= 0.000734
7
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:
dy f (a  h)  f (a )

dx h
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. f(2+0.2)=f(2.2)=e^(4.4)
Now using above approximate formula, we find values

dy f (a  h)  f (a) exp(2  2.2)  exp(2  2) 81.4509  54.5982


    134.2635
dx h 0.2 0.2
dy f (a  h)  f (a) exp(2  2.05)  exp(2  2) 60.3403  54.5982
    114.8412
dx h 0.05 0.05
dy f (a  h)  f (a ) exp(2  2.01)  exp(2  2) 55.7011  54.5982
    110 .2906
dx h 0.01 0.01 8
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.
9
What is Error
The error, ε, in any quantity is given by
  exact value  approximate value
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

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.
10
Numerical Errors
• Round-off Errors
• Truncation Errors
• Machine Precision

• Precision Limits
• Stability
• Convergence
• Divergence
• Alaising In signal processing and related disciplines,aliasing is
an effect that causes different signals to become indistinguishable
(or aliases of one another) when sampled. 
11
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
r  r * 0.00016  0.0002
relative error    0.25
r 0.00016
12
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.
r  r * 0.00016  0.0001
relative error    0.375
r 0.00016
13
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 ax2 + bx +
c = 0, when a ≠ 0, are
 b  b 2  4ac  b  b 2  4ac
x1  ; x2 
2a 2a
Using four-digit rounding arithmetic, consider this formula
applied to the equation x2 + 62.10x + 1 = 0, whose roots
are approximately

x1 = -0.01610723 ; x2 = -62.08390
14
Example 2
In this equation, b2 is much larger than 4ac, so the
numerator in the calculation for x involves the subtraction
of nearly equal numbers. Since
b 2  4ac  (62.10) 2  (4.000)(1.000)(1.000) 
 3856.  4.000  3852.  62.06
We then have
 b  b 2  4ac  62.10  62.06
fl ( x1)    0.0200
2a 2
Then relative error for x1= -0.01611 is
 0.01611  0.02000
r  2.4  10 1
 0.01611
15
Example 2
On the other hand, the calculation for x2 involves the
addition of the nearly equal numbers. This presents no
problem since
 b  b 2  4ac  62.10  62.06  124.2
fl ( x1)     62.10
2a 2 2.000

Then relative error for x1= -0.01611 is

 62.08  62.10
r  3.2 10  4
 62.08
This relative error is small.

16
Example 2
The rationalization of the numerator can help in reducing
error in x1:
 b  b 2  4ac   b  b 2  4ac   4ac
x1 
2a


  b  b 2  4ac  2a  b  b 2  4ac
  
 2c
x1 
 b  b 2  4ac 
Using this we get
 2.000  2.000
fl ( x1)    0.01610
62.10  62.06 124.2
 0.01611  0.01610
r  6.2  10 4 This relative error is small.
 0.01611

17
Example 2
If we use this formula for x2, it will be a mistake
 b  b 2  4ac   b  b 2  4ac   4ac
x2 
2a


  b  b 2  4ac  2a  b  b 2  4ac
  
 2c
x2 
b  b 2  4ac 
Using this we get
 2.000  2.000
fl ( x 2)    50.00
62.10  62.06 0.0400

 62.08  50.00 This relative error is large due to


r  1.9 10 1 subtraction of nearly equal
 62.08 numbers and a division.

18
Example 3
Accuracy loss due to roundoff error can also be reduced by rearranging
calculations, as shown in this example.
Evaluate: f(x) = x3 — 6.1x2 + 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 x2 x3 6.1x2 3.2x
Exact 4.71 22.1841 104.487111 135.32301 15.072
(chopping) 4.71 22.1 104. 135. 15.0
(rounding) 4.71 22.2 105. 135. 15.1

19
Example 3
Exact: f(4.71) = 104.487111 - 135.32301 + 15.072+ 1.5 = -14.263899;
Three-digit (chopping): f(4.71) = ((104. - 135.) + 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:

 14.263899  13.5
For chopping: r  0.05
 14.263899
 14.263899  13.4
For rounding: r  0.06
 14.263899

As an alternative approach, f(x) can be written in a nested manner.

20
Example 3
As an alternative approach, f(x) can be written in a nested manner as

f(x) = x3 - 6.1x2 + 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%.
21
Computer Hardware Types

Personal Computer
Supercomputers
Vector Processors
Array Processors
Parallel Processor

22
Software

• Operating Systems
• Windows - NT, ME, Windows
• Unix
• VMS - VAX
• Linux

23
Software
• Languages
• Fundamental Assembler (Bit manipulations)
• Engineering Languages
• Fortran
• Cobol
• Pascal
• C++
• Basic
• HTML and Java

24
Software
• Higher-Order Programming
• Maple - Mathematical Programming Language
• Mathematica - Mathematical Programming
Language
• Java - Internet Programming Language
• Matlab - Matrix Laboratory

25
Software
• Tools
• Word Processors
• Spreadsheets
• Database Management
• Graphics
• Mathematical Computer Codes

26
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.

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

• Input
• Main Program - Numerical methods and analysis
and/or evaluation.
• Output - Results.

28
Inputs
• Numerical values
• Initialization of the variables
• Conditions
• Equations

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

• Loops
• Conditions
• Error Convergence

30
Output
• Outputs are the results of the program. They can go
through a series of post-processing methods.
• Numerical Values
• Decisions
• Graphs and Plots

31
MatLab
• Variable Types
• Integers
• Real Values (Float)
• Complex Numbers (a + ib)
• a - real value
• b - imaginary value (“i” is the square root of -1)

32
Matlab
• Data types
• Numerical
• Scalars
• Vectors
• Matrices
• Logic Types
• Alpha/Numerical Types

33
Matlab
• A scalar value is the simple number, a, 2,
3.14157…,
• A vector is a union of a
x = (x1, x2, x3, x4)
• Transpose vector x T = x1
x2
x3
x4

34
Matlab
• Matrix is a combination of vectors and scalars.
Scalar and vectors are subsets of matrices.
• Matlab uses matrix to do mathematical
methods.

35
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)

36
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!

37
Matlab
• Simple commands and symbols
• ^C - an escape from a loop
• inf - infinity
• NaN - No numerical value

38
Scalar Operations
• Addition - a+b
• Subtraction - a-b
• Multiplication - a*b
• Right Division - a/b
• Left Division - b\a
• Exponential - a^b

39
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.

40

You might also like