You are on page 1of 6

04‐08‐2022

You Can Lead a Horse to Water …

CE‐603 
Numerical Methods
Prof. Ravi Sinha
(rsinha@civil.iitb.ac.in)

Lecture 03 – Thursday, August 4, 2022

CE‐603 Numerical Methods | Autumn Semester 2022‐23 2

1. Mathematical Background – Functions
Taylor’s Theorem
Let f(x) have n continuous derivatives on [a, b] for some n, and let  x , x0 a , b]
Mathematical Background:  Then, f (x)  pn (x)  Rn1 (x)
where,

Functions & Vectors Norms (x  x0 )
pn (x)  f ( x0 ) 
1!
f ( x0 )   
( x  x0 )n (n)
n!
f ( x0 )
Any continuous function can 
be approximated by a 
(n 1)
polynomial function and a 
( x  x0 )
x
1
Rn1 (x)   ( x  t )n f (n1) (t )dt  f (n1) ( ) remainder term (whose 
n! x0 (n  1)! value is generally unknown)
            for some   between x0  and x
pn (x) is a polynomial of order n
CE‐603 Numerical Methods | Autumn Semester 2022‐23 3 CE‐603 Numerical Methods | Autumn Semester 2022‐23 4
04‐08‐2022

1. Mathematical Background – Functions 2. Mathematical Background –Vectors Norm


Taylor’s Theorem (contd.) Real vectors are represented as:
This can be used to derive standard series formulae (with x0  0):   x1  
 
x2 x n x (n1)  x
e x  1  x   ...   e n   x     | x1 ,..., xn  real numbers 
n! (n  1)!  
2!  x  
  n 
x2 x 4 x 2n x (2 n2)
cos(x)  1    ...  (1)n  (1)n1 cos( x ) How does one measure the size of a vector?
2! 4! (2n)! (2n  2)!
Vector Norms are used to measure the magnitude or size of a vector.
As simple mathematical calculations can be done very fast on a computer (or a calculator),  Why is this needed?
even the most complex function can be evaluated using their series approximation.  oWhen comparing two or more vectors, we need a way to determine which is larger or 
ALL functions can be evaluated on a computer using their polynomial approximation smaller without comparing element by element (which would be meaningless).

CE‐603 Numerical Methods | Autumn Semester 2022‐23 5 CE‐603 Numerical Methods | Autumn Semester 2022‐23 6

2. Mathematical Background –Vectors Norm Know your mobile device!
Most important vector norms: 1. How much memory (RAM) dues your mobile phone have?
x 1  x1  ...  xn , x n 1‐Norm
2. Is the amount of memory a round number? Why not?
    xT x  ,
1/2 1/2
x 2  x12  ...  xn2 x n 2‐Norm 3. How many bytes does a kilobyte consist of?
x 
 max xi , x n ‐Norm
1i n
Note: All vector norms are considered equivalent even if their numerical values differ! 
Some characteristic properties of vector norms are:
v  0, if and only if v  0 , the null vector
 v   . v , for all vectors v  and real numbers 
v  w  v  w , for all vectors v  & w n

CE‐603 Numerical Methods | Autumn Semester 2022‐23 7 CE‐603 Numerical Methods | Autumn Semester 2022‐23 8
04‐08‐2022

Number Representation
It is essential to understand how numbers are represented in computers, and the 
consequences on computer arithmetic.

Computer Representation  Number representation:
1. Integer (Fixed point) mode – Used to exactly represent integer numbers. Not of much 
interest in Numerical Methods course. 
of Numbers 2. Floating point mode – Used to represent real numbers. The permitted numbers can vary 
greatly in size. However, there are limitations on both (a) magnitude of numbers, and (2) 
accuracy of their representation.
Number base used in computers in not decimal (Order of magnitude does not change by 10).
a) Most computers – binary (base 2)
b) Some computers – Hexadecimal (base 16)

CE‐603 Numerical Methods | Autumn Semester 2022‐23 9 CE‐603 Numerical Methods | Autumn Semester 2022‐23 10

Integer (Fixed Point) Number Representation Floating Point Number Representation
Integer Mode: Floating point numbers are stored on a computer as follows:
oNot of much interest in this course. x   .a1a2 ...at    e
oIntegers are represented exactly.
where
oImportant ‐ Integers can only be represented within a range.
  radix (or base being used)
L  Smallest integer represented in computer (negative number)
  Sign function (  1 or   1)
U  Largest integer represented in computer (positive number)
.a1a2 ...at   mantissa;    values  are 0  ai    1
e  exponent (an integer)
The numbers in parenthesis (mantissa) represent the following number:
a a a
.a1a2 ...at   11  22  ...  tt
  
CE‐603 Numerical Methods | Autumn Semester 2022‐23 11 CE‐603 Numerical Methods | Autumn Semester 2022‐23 12
04‐08‐2022

Floating Point Number Representation Floating Point Number Representation
Binary Numbers: Example 1 (binary to decimal number)
ai can have values of 0 or 1 11011.012  1  24  1  23  0  22  1  21  1  20  0  21  1  22
Hexadecimal Numbers:  16  8  2  1  0.25  27.25
ai can have values of 0, 1, 2, 3, 4, 5, 6, 
7, 8, 9, A, B, C, D, E, F
Example 2 (hexadecimal to decimal number)
oThe hexadecimal numbers A‐F are 
equivalent to decimal numbers 10‐15  56C .F 16  5  162  6  161  12  160  15  161
oCheck your scientific calculator for   1280  96  12  0.9375  1388.9375
hexadecimal keys

CE‐603 Numerical Methods | Autumn Semester 2022‐23 13 CE‐603 Numerical Methods | Autumn Semester 2022‐23 14

Concept:
Floating Point Number Representation Floating‐Point Number Representation
When writing a large number of digits 
Example 3 (decimal to binary number) Decimal by hand, they should be grouped with 
Example (decimal to binary number) Decimal
516.4 32910  1  29  ...  1  29  ...
516.432910space between groups. This makes 
29 28 27 26 25 24 23 22 21 20 2‐1 comprehension of numbers easier
29 28 27 26 25 24 23 22 21 20 2‐1
ai 1 0 0 0 0 0 0 1 0 0 0 ai 1 0 0 0 0 0 0 1 0 0 0
Value 512 4 Value 512 4
Sum 512 516 Sum 512 516
Remainder 4.432 9 0.4329 Remainder 4.432 9 0.4329
Group of 4 digits are most commonly 
2‐2 2‐3 2‐4 2‐5 2‐6 2‐7 2‐8 2‐9 2‐10 2‐11 2‐12 2‐2 2‐3 2‐4 2‐5 2‐6 2‐7 2‐8 2‐9 2‐10 2‐11 2‐12
adopted.
ai 1 1 0 1 1 1 0 1 1 0 1 ai 1 1 1 1 1 1 1 1
0.0312 5 0.0156 25 0.0078 125 0.0019 5312 5
Check your bank’s debit or credit card 
0.0312 5 0.0156 25
0.0078 125 0.0019 5312 5
Value 0.25 0.125 … … Value 0.25 0.125 … …
Sum 516.2 5 516.3 75 516.4 0625 516.4 2187 5 516.4 2968 75 516.4 3165 06
… … Sum 516.2 5 516.3 75
number for its grouping!
516.4 0625 516.4 21875 516.4 2968 75
… 516.4 3165 06

0.0266 5 0.0110 25 0.0032 125 0.0012 5937 5 0.0266 5 0.0110 25 0.0032 125 0.0012 5937 5
Remainder 0.1829 0.0579 … … Remainder 0.1829 0.0579 … …

CE‐603 Numerical Methods | Autumn Semester 2022‐23 15 CE‐603 Numerical Methods | Autumn Semester 2022‐23 16
04‐08‐2022

Floating Point Number Representation Floating Point Number Representation
Example 3 (decimal to binary number) (contd.) Decimal to binary number conversion
1
516.4 32910  1  29  ...  oAs observed in the example, very large number of binary digits or terms may 
215
After 25 binary digits, we get the following: be required to represent a typical decimal number.
sum  516.4 3289 18 oSo, can we use any number of digits to convert a decimal number to binary?
remainder  0.0000 0818 2 oNo
Note that even after using 25 binary digits, the number is not exactly represented in binary  oAre there limits on number of binary digits used on a computer?
form. oYES!
After 25 digits, the conversion to binary form is:
oThe number of available binary digits depends on precision of floating point 
516.4 32910  1000 0001 00.01 1011 1011 0100 1 2 number representation.

CE‐603 Numerical Methods | Autumn Semester 2022‐23 17 CE‐603 Numerical Methods | Autumn Semester 2022‐23 18

Precision of Number Representation Single Precision Number Representation


oIt is not possible to use arbitrarily large number of digits for binary representation of  oThe storage of 32 bits is as follows:
decimal numbers. 31 30 … 23 22 … 0 Bits
oLong back, based on experience, it was decided that at least 7 digits of decimal numbers 
(including digits after decimal points) should be used for all calculations on a computer in  Sign Exponent (8 bits) Mantissa (23 bits stored)
order to maintain reasonable accuracy (two digits more than log tables then in use!). 
oNow, 7 digit numbers require about 23 binary bits to represent the numbers. Since the  x   .a1a2 ...at    
e
 7 bits for e
next power of 2 larger than 23 is 32, it was decided that 28 or 32 bits will be used to  231 bits
represent numbers in binary format on a computer.
oOut of this, only 23 bits are required to represent the mantissa (t=23+1=24). oThis representation of numbers (using 32 bits, is known as Single Precision)

x   .a1a2 ...at    e oIt is known that first bit of mantissa should be 1. As a result, it is not shown or stored. The 


Leading bit, a1 actual size of mantissa is therefore [(t=23) + 1=24].
(always =1) Not stored.

CE‐603 Numerical Methods | Autumn Semester 2022‐23 19 CE‐603 Numerical Methods | Autumn Semester 2022‐23 20
04‐08‐2022

Double Precision Number Representation Number Representation


oIt was found that only a limited range of numbers can be represented in Single Precision  oDue to binary representation of numbers using a certain size of mantissa, most real 
number system. numbers can not be represented exactly as a floating‐point number. Each floating point 
number represents a range of real numbers.
oIt was also soon found that larger number of decimal digits should be used for calculations.
oLarger range of numbers can be represented if more bits are used for representation.
oDouble Precision number representation was adopted with 64‐bit representation.
oThe representation of the 64 bits is as follows:
63 62 … 52 51 … 0 Bits

Sign Exponent (11 bits) Mantissa (52 bits stored)


oThe actual size of mantissa in double precision is [(t=52) + 1=53].

CE‐603 Numerical Methods | Autumn Semester 2022‐23 21 CE‐603 Numerical Methods | Autumn Semester 2022‐23 22

End of Lecture 03

CE‐603 Numerical Methods | Autumn Semester 2022‐23 23

You might also like