Вы находитесь на странице: 1из 12

Introduction

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

Process of solving an engineering problem


Problem statement
Definition of the problem Parameters and variables involved Constraints/conditions, if any Specifications

o Required quality of the solution


M.G. Sideris, 2012 ENGG 407 - Numerical Methods in Engineering 1.1

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

Programming algorithm for obtaining the solution


Selection of numerical method/technique that will yield the solution, depending on

o accuracy, efficiency (computing time), programming difficulty


Computer implementation

o Algorithm: plan/steps of carrying out the numerical method o Code: List of computer commands for the execution of the algorithm

Interpretation of the solution


Validation of the solution Quality of the estimated solution

o Error analysis and error propagation


M.G. Sideris, 2012 ENGG 407 - Numerical Methods in Engineering 1.2

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:

For D < 0, there are no real roots

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

M.G. Sideris, 2012

ENGG 407 - Numerical Methods in Engineering

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

corresponding to multiples of powers of as follows:

Common base- representations

o Decimal ( = 10) or base-10 representation digits: 0,1,2,3,4,5,6,7,8,9


12345.6710 = 1104+2103+3102+4101+5100 + 610-1+710-2 The RHS of the formula above converts a number from any base to the decimal one

o Binary ( = 2) or base-2 representation digits: 0,1


11111.1112 = 124+123+122+121+120 + 12-1 + 12-2+ 12-3 = = 16+8+4+2+1 + (7/8) = 31.87510

M.G. Sideris, 2012

ENGG 407 - Numerical Methods in Engineering

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

o Hexadecimal ( = 16) or base-16 representation: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F


7AF2.C9E16 = 7163+10162+15161+2160 + 1216-1+916-2+1416-3 = = 28762+2560+240+2 + (3230 /4096) = 31564.7885742187510
Hex Dec Oct Bin 0 0 00 0000 1 1 01 0001 2 2 02 0010 3 3 03 0011 4 4 04 0100 5 5 05 0101 6 6 06 0110 7 7 07 0111 8 8 10 1000 9 9 11 1001 A 10 12 1010 B 11 13 1011 C 12 14 1100 D 13 15 1101 E 14 16 1110 F 15 17 1111

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)

o n+1 is the number of significant digits (where dn 0) o Example 1.4:


standard notat. 4519.23 732.5051 -0.00012 -0.005612
M.G. Sideris, 2012

scientific notat. 4.51923 103 7.325051102 -1.210-4 -5.61210-3

order of magn. O(103) O(103) O(10-4) O(10-2)

# of sign. digits 6 7 2 4
1.7

ENGG 407 - Numerical Methods in Engineering

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

binary notat. 1.1001 2101 1.01 2-10 1.0101 21010

# 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

M.G. Sideris, 2012

ENGG 407 - Numerical Methods in Engineering

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

o Example 1.6: How is the number 22.5 stored in double precision?


normalization: 22.5/24 24 = 22.5/16 24 = 1.40625 24 binary 1-bit sign: 0 binary 11-bit exponent + bias: 4+1023 = 1027 = [10000000011]2 binary52-bit mantissa: 0.40625 = [0.0110100000000] 2

M.G. Sideris, 2012

ENGG 407 - Numerical Methods in Engineering

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

M.G. Sideris, 2012

ENGG 407 - Numerical Methods in Engineering

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

and the true absolute error is

when the solution x of a numerical problem has been estimated by n iterations

Round-off errors and loss of significance/precision


Due to the limited bits available in a computer to store the mantissa, 'longer'

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

Вам также может понравиться