Академический Документы
Профессиональный Документы
Культура Документы
nalytical Methods Advantages Direct and exact solutions Efficient solutions Numerical Methods Can be used with complex functions/problems Easy to include constraints
Disadvantages
Practical only for simple Require considerable functions/problems amount of iterations/time Become complex when Solutions are not exact and constraints are involved require initial estimates
Introduction
Problem modeling (formulation of the solution)
Physical law that describes the problem Equation(s) that need to be solved Choice of analytical or numerical solution
o Algorithm: plan/steps of carrying out the numerical method o Code: List of computer commands for the execution of the algorithm
Introduction
Example 1.2: Show the problem modeling, simple programming algorithm and code for finding the real roots of the quadratic equation ax2 + bx + c = 0
Modeling:
o
Algorithm:
o Calculate the value of D o If D 0, calculate x1 and x2 from the equation above, and display their values o If D < 0, display message "The equation has no real root"
Code: o a = input('Enter a '); b = input('Enter b '); c = input('Enter c '); o D = b^2 4*a*c o if D >= 0 o x1 = (-b+sqrt(D))/(2*a); x2 = (-b-sqrt(D))/(2*a) o fprintf('x1 = %f, x2 = %f ', x1, x2) o else o disp('Equation has no real roots.') o end
M.G. Sideris, 2012 ENGG 407 - Numerical Methods in Engineering 1.3
Introduction
How numbers are represented on a computer
Base- number representation
Any integer digit > 1 can be used as the base (or radix) for a number system
o If > 10, then usually letters like A,B,C,D,E,F, are introduced to represent
10,11,12,13,14,15, , -1, respectively;
Hexadec imal Decimal 0 1 2 3 4 5 6 7 8 9 A B C D E F
10
11
12
13
14
15
Octal
00
01
02
03
04
05
06
07
10
11
12
13
14
15
16
17
Binary
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
1.4
Introduction
How numbers are represented on a computer
Base- number representation
Numbers N in base are represented by a sequence of digits 0, 1, 2, , -1
1.5
Introduction
o Octal ( = 8) or base-8 representation digits: 0,1,2,3,4,5,6,7
12345.678 = 184+283+382+481+580 + 68-1 + 78-2 = = 4096+1024+192+32+5 + (55/64) = 5349.85937510
Notes:
o Numbers with finite representation in one base my have infinite representation in ano There is also a need to store very large and very small numbers, for which we use a
floating point representation with signs, exponents and mantissas overflow and underflow errors
M.G. Sideris, 2012 ENGG 407 - Numerical Methods in Engineering
other, e.g., [0.1]10 = [0.0 0011 0011 0011 ]2 truncation and round-off errors
1.6
Introduction
Floating point representation
Used in order to accommodate real numbers that are very small or very large Decimal floating point representation or scientific notation
o o o o
Form: 0. d1d2d3d4dn is called the mantissa p (an integer) is called the exponent 10p represents the number's order of magnitude
If d0. d1d2d3d4dn < 5, then the number is of order 10p, denoted as O(10p) If d0. d1d2d3d4dn > 5, then the number is of order 10p+1, O(10p+1)
# of sign. digits 6 7 2 4
1.7
Introduction
Binary floating point representation (BFPR)
o o o o
Form: The digits di in the mantissa and bi in the exponent are binary digits n+1 is the number of significant digits (where dn 0) A decimal number is converted to binary floating point representation in two steps:
1st step: The number is normalized by dividing it by the largest power of 2 that is smaller than the number itself. Its new (decimal) form is q 2p , where 2 q > 1 and p is an integer 2nd step: Then p and the mantissa part of q are converted from decimal to binary
o Example 1.5:
Dec. number 50 0.3125 1344 normalization 50/25 25 = 1.5625 25 (50/32 25 ) 0.3125/2-2 2-2 = 1.25 2-2 (0.3125/0.25 2-2 ) 1344/210 210 = 1.3125 210 (1344/1024 210 )
M.G. Sideris, 2012 ENGG 407 - Numerical Methods in Engineering 1.8
# of sign. digits 5 3 5
Introduction
Storing numbers in single or double precision
IEEE-754 standard of storing numbers in a computer
o Single precision (SP) and double precision (DP) numbers are stored in strings of 32 bits
(or 4 bytes) and 64 bits (or 8 bytes), respectively, as follows:
the leading 1 in front of the decimal point is not stored 1st bit in SP and in DP is for storing the sign: 0 for + and 1 for next 8 bits in SP and 11 bits in DP are for the exponent plus bias of 127 in SP and 1023 in DP last 23 bits in SP and 52 bits in DP are for storing the mantissa
1.9
Introduction
o The bias is introduced in order to avoid using one of the bits for the sign of the
exponent
The largest exponent that can be stored with 11 bits is 211-1 = 2047. Thus with a bias of 1023: the largest positive actual exponent is 1024, resulting in exp.+bias = 2047 = [11111111111]2 the smallest negative actual exponent is -1023, resulting in exp.+bias = 0 = [00000000000]2
1.10
Introduction
Overflow and underflow errors
o Due to the limited number of bits available to store numbers in a computer, the range of
numbers is also limited. In double precision
the smallest mantissa, and smallest mantissa difference between numbers, is 2-52 2.2 10-16
for numbers of O(1), this constant is called the machine epsilon: eps = 2.2204460492500313 10-16
the largest number is 21024 1.8 10308 the smallest number is 2-1023 1.1 10-308
o Numbers outside this range cause overflow or underflow errors as shown in the graph o Errors are also caused when storing numbers that have non-finite BFPR
1.11
Introduction
Errors in numerical solutions
Absolute and relative errors
For a number x and its numerical approximation
the true error is the true relative error is the estimated relative error is
numbers need to be shortened by rounding or chopping them in order to fit resulting in a round-off error ERO
Round-off errors are occurring when subtracting two nearly identical numbers or
when two vastly different numbers are involved in a calculation, and are the reason for the resulting loss of significance/precision
M.G. Sideris, 2012 ENGG 407 - Numerical Methods in Engineering 1.12