0% found this document useful (0 votes)
36 views

Advanced Computational Methods: ENGR 680

The document discusses numerical representations and computations in computers. It covers properties of real numbers, binary and decimal number systems, integer and floating point representations, and sources of errors in floating point computations. MATLAB commands for working with real numbers are also presented.

Uploaded by

Tulong Zhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Advanced Computational Methods: ENGR 680

The document discusses numerical representations and computations in computers. It covers properties of real numbers, binary and decimal number systems, integer and floating point representations, and sources of errors in floating point computations. MATLAB commands for working with real numbers are also presented.

Uploaded by

Tulong Zhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 19

WIDENER UNIVERSITY School of Engineering

Third Edition
Tradition & Excellence Since 1821 Mechanical Engineering

TOPIC

ENGR 680

02 Advanced Computational
Methods

Numbers and Vectors

© Tulong Zhu, All rights reserved.


Properties of Real Numbers, R
Real Number • Integers, rational numbers, and irrational numbers.
 The real numbers can be represented as points on the real
number line.
-1/2 2 
-4 -3 -2 -1 0 1 2 3 4

Associative ( x  y)  z  x  ( y  z)
( x  y)  z  x  ( y  z)
Commutative x y  yx
x y  y x

Identity x0  x
elements
1 x  x
Inverse x  ( x)  0
Element
if x  0, x  (1 / x)  1
02 - 2
Numbers in Computers: Binary Numbers
Binary • In computers, numbers are stored in the binary number system.
Number Only digits 0 & 1 are stored in memory to represent all possible
numbers.

Example 1= 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1

2= 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0

3= 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1

13= 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1

02 - 3
Covert from Binary to Decimal: Integers
Integers • Integers: For a binary number dm-1 dm-2 … d2 d1d0, the decimal
value, N, is
m 1
N   di 2i  d 0  d1  2  d 2  2 2    d m 1  2 m 1
i 0

dm-1 dm-2 … d2 d1 d0
N=     
+ + +
2m-1 2m-2 … 22 21 20
 Since dm-1 , dm-2 , …, d2, d1 and d0 are either 1 or 0, N is the
sum of those 2i with a non-zero di , i = 1,  2,…,  m.

1 1 … 1 0 1
N= 2m-1+ 2m-2 …
+ 22 + 20
Example • (1101)2 = 1 + 0(21) + 1(22) + 1(23) = 13

0 0 0 0 1 1 0 1

02 - 4
23 + 22 + 20 = 8 + 4 + 1 = 13
Covert from Binary to Decimal: Fractions
Integers • Fractions: For a binary number .d-1 d-2 … d-(m+1) d-m, the decimal
value, N, is
m
N   d i 2 i  d 1  2 1  d  2  2  2    d  m  2  m
i 1

d-1 d-2 … d-(m+1) d-m


N=    
+ + +
2-1 2-2 … 2-(m+1) 2-m
 Since d-1 , d-2 , …, d-(m+1), and d-m are either 1 or 0, N is the
sum of those 2i with a non-zero di, i = 1,  2,…,  m.

1 1 … 1 0 1
N= 2-1 + 2-2 … + 2-(m+2)+ 20
Example • (.1101)2 = 1(2-1) + 1(2-2) + 0(2-3)+ 1(2-4) = 0.8125

1 1 0 1 0 0 0 0

02 - 5
2-1 + 2-2 + 2-4 =0.5+0.25+0.0625= 0.8125
Fixed Point Notation
Fixed Point • The binary point is not stored in the computer, but is remembered
Notation by the programmer (program), e.g., for a 8-bit number, the
program can assume the binary point is after the 5th bit.
Example The binary point is not stored

1 0 0 1 1 1 0 1
23 20 2-1 2-2 2-4 = 9.8125
Number • The biggest positive number is stored in the computer, when
Range every bit is stored with a digit 1.

1 1 1 1 1 1 1 1
27 26 25 24 23 22 21 2 0 = 255 ~28
 For a m-bit computer, the range of positive fixed-point
integers is about 2m

02 - 6
Fixed Point Notation: Limitations
Limit • If N bits are used, then only 2N things can be represented. 8 bits can
Precision represent 256 positive integers, 256 fractional numbers, and so on.

• For the 8-bit computer, with the binary point after the 4th bit, here is
a number line showing the 256 values that can be represented with
this fixed notation:

• The smallest value is zero (00000000); the largest value is 15.9375


(11111111). The smallest non-zero value is 0.0625. Every
represented value is a multiple of 0.0625.
Que  How many real numbers lie between 0 and 15.9375?

Conclu • For m bit, fractions include errors from 0 to 2-m.

Number • Very large numbers and very small fractions cannot be represented
Range with this limited bits (2m for a m-digit computer).
02 - 7
Floating Point Notation: Decimal
Decimal • In the decimal system we can get round the range problem using
Floating scientific notation or float point notation.
Notation
Scientific Floating Point
Notation Notation
1,245,000,000,000 = 1.2451012 = 0.12451013
0.00001245 = 1.24510-5 = 0.124510-4
-0.00001245 = -1.24510-5 = -0.124510-4

(e.g., 1.245 = + 0.1245  10-1 )


N.n =  M  BE

Decimal Value Sign bit Mantissa Base Exponent

02 - 8
Floating Point Notation: Binary Numbers
Binary • If we change the base into 2 in the previous slide, a decimal
Number number can always be written as:
N.n =  M  2 E
Decimal Value Sign bit Mantissa Base Exponent
 Only the Sign bit, Mantissa, the exponent and its sign need to
be stored in the computer.
Example • 5.75 = 5.75  20 = 101.11  20 = 101.11  20
= 2.875  21 = 10.111  21 = 10.111  21
= 1.4375  22 = 1.0111  22 = 1.0111  210 Binary
=0.71875  23 = .10111  23 = .10111  211 numbers
In a  Suppose we use 16-bits words, with 5 bits for the exponent:
Computer + . 10111  2 + 11

0 1 0 1 1 1 0 0 0 0 0 0 0 0 1 1
Sign bit Mantissa, M Sign of E Exponent, E
 The above scheme is for illustration only, the real storage
02 - 9 scheme in a computer is different (see IEEE 754).
Floating Point Notation: MATLAB©
Donald E. Floating-point computation is by nature inexact, and it is not
Knuth: difficult to misuse it so that the computed answers consist
almost entirely of 'noise'.
Range • Only a finite number of bits (32 for most PCs) are available for
a computer. The range of decimal numbers stored is also finite.
MATLAB© uses a double precision format (64 bits) to store
floating point numbers (with 16 significant decimal digits) and
32 bits to store integers, The ranges floating numbers is
 Floating numbers: ~ 1.7*10–308 to 1.7*10308 (or ~ 2–1024 to
21024) .
Precision • As with the binary fixed point notation, use a finite number of
bits in the binary floating point notation can also represent only
a finite number of decimal numbers in a computer.
• Therefore, a binary floating point representation in a computer
is always an approximation for most numbers.
• Floating point relative accuracy in MATLAB© is
>> eps=2.2204e-016 (machine dependent = the distance
from 1.0 to the next largest floating point number which is
smaller than 1.0).
02 - 10
Number in Computers: Errors

• Binary Floating Point computations will always bring errors. These


may include:
 Rounding
o Non-representable numbers: for example, the literal 0.1 cannot
be represented exactly by a binary floating-point number using
a finite number of bits.
o Rounding of arithmetic operations: for example 2/3 might
yield 0.6666667
 Absorption: 1×1015 + 1 = 1×1015
 Cancellation: subtraction between nearly equivalent operands
 Overflow / Underflow (number is too small or too big).
• Some axioms for real numbers may not exactly apply, e.g.,
(a + b) + c = a + ( b + c) ??
• Consequently, binary floating-point should not be used for financial
calculations, or indeed for any calculations where the results achieved
are required to match those which might be calculated by hand.

See Comp_error.m for errors


02 - 11
Useful MATLAB© Commands for Real Numbers

Command Format Example: -4.503, 3.491


abs Absolute value 4.5030, 3.4910
ceil Round toward infinity -4, 4
fix Round toward zero -4, 3
floor Round toward minus infinity -5, 3
round Round towards nearest integer -5, 3
sign Signum function -1, 1

See Real_num_command.m

02 - 12
Complex Numbers: Basic Concepts
Complex z  x  iy, i   1 Im
Num x = Re z = real part, z
y = Im z = imaginary part y
r
Magnitude r  z  x 2  y 2 (Length or Modulus) 
Argument,  x  (Multi-valued:  +2k)
  arctan 
 y  (Principal: [– , ])
Polar angle x Re

Complex z  x  iy
Conjugate  ( z )   ( z ), r ( z )  r ( z ) z
Basic z1  x1  iy1 , z2  x2  iy2
Operations
z1  z2  ( x1  x2 )  i ( y1  y2 )
2
z1z2  ( x1x2  y1 y2 )  i ( x1 y2  y1x2 ) z  zz
z1 z1 z2 z1z2 x1x2  y1 y2 y x x y
   i 1 2 1 2
z2 z2 z2 z2 2 x12  y12 x12  y12

z n  ??? e z  ??? z1 / n  ??? 


02 - 13
Complex Numbers: Polar Form
i Im
Preliminary e  cos  i sin 
z
De Moivre (cos  i sin  ) n  cos n  i sin n y
r
Polar Form z  x  iy  r (cos  i sin  )  re i 

 i
x Re
z  x  iy  r (cos  i sin  )  re

Remember? z n  ??? e z  ??? z1 / n  ??? 


z

 z n  (re i ) n  r n ein  r n (cos n  i sin n )

e z  e x iy  e x eiy  e x (cos y  i sin y )

z1 / n  (rei )1 / n  [rei (  2k ) ]1 / n


  2k   2k
 r1 / n (cos  i sin ), k  1,2, ,n-1
n n
02 - 14
Complex Numbers: MATLAB© Commands

Command Format
z=x+iy, z=x+jy Complex number
z=r*exp(i*theta) Polar form

abs(z) Magnitude z  x2  y 2
angle(z) Angle in radians (-, );  = tan–1(y/x)
conj(z) Complex conjugate x - iy
imag(z) Complex imaginary part y
real(z) Complex real part x
Plotting
compass(x,y) Draw complex numbers as arrows on polar plot
feather(x,y) Draw complex numbers as arrows on linear plot

See Complex_num.m

02 - 15
Vectors in High Dimensions
Definition • An n dimensional vector x  Rn (Rn is the set of of all vectors
with n real components) of real numbers is defined as
x = [x1, x2, …, xn] = x1e1 + x2e2 + … + xnen
e1 , e2 , … , en is a set of base (orthonormal) vectors

Addition x  y  x1  y1 x2  y2  xn  yn 

Scalar Mult kx  kx1 kx2  kxn 


Norm x  x12  x22    xn2 (also called the length)
x
Unit Vector u
x
n
Dot Product x  y  x, y  x1 y1  x2 y2    xn yn   xi yi
Inner Prod. i 1
2
x  xx
Cross Prod. x  y  ??? (Only applied to a 3D space)
02 - 16
Vectors: Orthogonal
Orthogonal • The nonzero vectors x and y are said to be orthogonal if the dot
product or inner product is zero, i.e., x·y = <x, y> = 0.
Orthonormal • Mutually orthogonal vectors in Rn with unit length are called
orthonormal.

 If m vectors v1 , v2 , … , vm in Rn are mutually


orthonormal, then
1 i  j
vi  v j  vi , v j   ij  
0 i  j
ij is the Kronecker delta.

 The three base vector i, j and k in a three dimensional space


are orthonormal.

 The n base vectors e1 , e2 , … , en in an n-dimensional space


are orthonormal.

02 - 17
Vectors: Linear Dependence
Linear • Let x1, x2, …, xm be a set of n-vectors in Rn. Then a linear
Combination combination of these vectors is a sum of the form
k1x1  k2x2    kmxm
where k1, k2, …, km are nonzero scalars.
Linear • Let x1, x2, …, xm be a set of vectors in Rn. Then the set is said
Dependence to be linearly independent if and only if none of the vectors can
be expressed as a linear combination of the remaining vectors.
Theorem • Let x1, x2, …, xm be a set of vectors in Rn . The set is linearly
independent if the vector equation
k1x1  k2x2    kmxm  0
is only true when k1= k2 = … = km = 0
 Linearly DEPENDENT: at least one non-zero scalar, ki,
exists such that
k1x1  k2x2    kmxm  0
Notes • The highest number of linear independent vectors in Rn is n.
• A mutually orthogonal set of vectors is linearly independent.
02 - 18
Vectors: MATLAB© Commands
Operation MatLab Command Math Form
Standard Addition (subs) xy [x1y1, x2y2, …, xnyn]
Linear Scalar Multpl k*x [kx1 , kx2 , … , kxn]
Algebra
Operation Transpose x’ Column Vector
Dot/inner Prod x*y’, dot(x,y) x1 y1 + x2 y2 + … + xn yn
Cross Prod (3D) cross(x,y) xy
Norm norm(x) x
Special Multiplication x.*y [x1 y1 , x2 y2 , …, xn yn]
element-by- Division x./y [x1/y1 , x2/y2 , …, xn/yn]
element
Exponentiation x.^m (m: scalar) [x1m, x2m, …, xnm]
operation in
MATLAB© Function f(x) [f (x1) , f (x2) , …, f (xn) ]
Augment [x y] [x1, x2, …, xn, y1, y2, …, yn]

See Vectors.m for vector operations.

02 - 19

You might also like