You are on page 1of 93

METODOS NUMERICOS I

Ing. William Chauca Nolasco

2016-I

REPRESENTACIN BINARIA

Cmo se representa un nmero decimal


1

257.76 2 10 5 10 7 10 7 10 6 10
2

http://numericalmethods.eng.usf.edu

Base 2
(1 23 0 2 2 1 21 1 2 0 )

(1011.0011) 2
1
2
3
4

(
0

2
)

11.1875

10

CONVERSION DE UN ENTERO EN BASE 10 A


BINARIA
Table 1 Converting a base-10 integer to binary representation.
Cociente
11/2

5/2

2/2

1/2

Por lo tanto

Resto

1 a0
1 a1
0 a2
1 a3

(11)10 ( a 3 a 2 a1 a 0 ) 2
(1011) 2

Start

Integer N to be converted to
binary format

Input (N)10

i=0

Divide N by 2 to get quotient Q &


remainder R

i=i+1,N=Q

ai = R

No
Is Q = 0?
Yes
n=i
(N)10 = (an. . .a0)2

STOP

NMERO DECIMAL FRACCIONARIO A


BINARIO
Table 2. Converting a base-10 fraction to binary representation.

Number

Number
despues
decimal

0.1875 2

0.375

0.375

0 a1

0.375 2

0.75

0.75

0 a 2

0.75 2

1.5

0.5

1 a 3

0.5 2

1.0

0.0

1 a 4

Number antes
decimal

Por lo tanto

(0.1875)10 ( a1a 2 a 3a 4 ) 2
7

(0.0011) 2

Start
Fraction F to be converted
to binary format

Input (F)10

i 1

Multiply F by 2 to get
number before decimal, S
and after decimal, T

i i 1, F T
ai = R

No

Is T = 0?

Yes
n=i
(F)10 = (a-1. . .a-n)2

STOP

NMERO DECIMAL A BINARIO

11.1875 10

?.?

Entonces

(11)10 (1011) 2
y

(0.1875)10 (0.0011) 2
tenemos

(11.1875)10 (1011.0011) 2
9

Todos los nmeros decimales fraccionarios no se


pueden representar exactamente
Table 3. Converting a base-10 fraction to approximate binary
representation.

0.3 2
0.6 2
0.2 2
0.4 2
0.8 2

Number

Number after
decimal

0.6

0.6

1.2

0.2

0.4

0.4

0.8

0.8

1.6

0.6

Number
before
Decimal

0 a1
1 a 2
0 a3
0 a 4
1 a 5

(0.3)10 (a1a 2 a3 a 4 a5 ) 2 (0.01001) 2 0.28125


10

Otra manera de ver la


conversin
Convert

11.187510

to base 2

1110 23 3
23 21 1
2 2 2
3

1 2 0 2 1 2 1 2
1011 2
3

11

0.187510 2

0.0625

2 2

0 2 1 0 2 2 1 2 3 1 2 4
.0011 2

11.187510 1011.0011 2
12

13

REPRESENTACIN DEL PUNTO


FLOTANTE

14

Punto flotante decimal: Forma


Cientfica

256.78 is written as 2.5678 10

0.003678 is written as 3.678 10

256.78 is written as 2.5678 10

15

Ejemplo
La forma es:
o

m 10e

Ejemplo: Para

2.5678 10 2

1
m 2.5678
e2
16

sign mantissa 10

exponent

Formato de la coma flotante para los


nmeros binarios

y m2
sign of number 0 for ve, 1 for - ve
m mantissa 1 2 m 10 2
e

1 no se almacena mientras que se da siempre para ser 1.

e integer exponent
17

Ejemplo
Palabra hipotetica de 9 bits

the
the
the
the

first bit is used for the sign of the number,


second bit for the sign of the exponent,
next four bits for the mantissa, and
next three bits for the exponent

54.75 10

110110.11 2 1.1011011 2 25

1.1011 2 101 2

We have the representation as

mantissa
Sign of the
number

18

Sign of the
exponent

exponent

Epsilon de la Maquina
Definido como la medida de exactitud y
calculado por diferencia entre 1 y el nmero
siguiente que pueden ser representados

19

Example
Diez bit word
Signo del numero
Signo del exponente
Siguiente cuatro bits para el exponente
Siguiente cuatro bits para la mantissa

Next
number

1 10

1.0001 2 1.0625 10

mach 1.0625 1 2 4
20

Error relativo y epsilon de la maquina


El error verdadero relativo absoluto en la representacin
de un nmero ser menor entonces el psilon de la
mquina

Example

0.02832 10 1.1100 2 2 5
1.1100 2 2 0110

10 bit word (sign, sign of exponent, 4 for exponent, 4 for mantissa)

Sign of the
number

exponent
Sign of the
exponent

mantissa

1.1100 2 2 0110
a

21

0.0274375

0.02832 0.0274375
0.02832

0.034472 2 4 0.0625

IEEE 754 estndares para la


representacin de simple
precisin

IEEE-754 Floating Point


Standard
Estandariza la representacin de los nmeros de
punto flotante en diversas computadoras en
simple y doble precisin

Estandariza la representacin de las operaciones


de punto flotante en diversas computadoras.

REFERENCIA IMPORTANTE
Cada profesional en ciencia e ingeniera (e
incluso si usted no lo es) debe saber sobre
aritmtica de punto flotante!

IEEE-754 Format Single


Precision
32 bits for single precision
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Sign Biased
(s) Exponent (e)

Mantissa (m)

Value ( 1) 1 m 2 2
s

25

e ' 127

Example#1
1 1 0 1 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Sign Biased
(s) Exponent (e)

Mantissa (m)

Value 1 1. m 2 2e ' 127


s

1 1.10100000 2 2
1 1.625 2162127
1 1.625 235 5.5834 1010
1

26

(10100010) 2 127

Example#2
Represent -5.5834x1010 as a
precision floating point number.

single

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

Sign Biased
(s) Exponent (e)

Mantissa (m)

5.5834 10 1 1. ? 2
10

27

Exponent for 32 Bit IEEE-754

8 bits would represent

0 e 255
Bias is 127; so subtract 127 from
representation

127 e 128

28

Casos especiales de exponentes

Actual range of

1 e 254
e 0

and

e 255

are reserved for special numbers

Actual range of

126 e 127

Special Exponents and Numbers

e 0
e 255

all zeros
all ones
m

Represents

all zeros

all zeros

all zeros

all zeros

-0

all ones

all zeros

all ones

all zeros

0 or 1

all ones

non-zero

NaN

IEEE-754 Format
The largest number by magnitude

1.1........1 2 2

127

3.40 10

38

The smallest number by magnitude

1.00......0 2 2

126

2.18 10

38

Machine epsilon

mach 2
31

23

1.19 10

32

Fuentes de ERROR

33

Dos son las Fuentes de errores en


calculo numrico
1)
2)

Round off error


Truncation error

34

Round off Error


Causado
por
representar
aproximadamente un numero.
1
0.333333
3

2 1.4142...

35

Problemas creados por error de


redondeo
28 americanos son asesinados en febrero el 25
de 1991 por un misil Scud iraqu en Dhahran,
Arabia saudi.

El sistema de defensa PATRIOT no pudo rastrear


e interceptar el Scud. Por qu?

36

Problema
con el Misil Patriot
El ciclo de reloj de 1/10 de segundos

fue
representado en registro de punto fijo 24-bit
cre un error de 9,5 x 10 -8 segundos.

La batera era encendido por 100 horas


consecutivas, as causando una inexactitud
de

9.5 108

s
3600s
100hr
0.1s
1hr

0.342 s
37

El rango calculado en el sistema que se


alcanzaba el misil era 687 metros
El blanco considerado era para una distancia
mayor de 137 metros

38

Encontrar la contraccion del diametro


D D

Tc

(T ) dT

Ta

Ta=80oF; Tc=-108oF; D=12.363

= a0+ a1T + a2T2

39

Thermal Expansion Coefficient vs Temperature

D D T

40

T(oF)

(in/in/oF)

-340

2.45

-300

3.07

-220

4.08

-160

4.72

-80

5.43

6.00

40

6.24

80

6.47

Regressing Data in Excel


(general format)

= -1E-05T2 + 0.0062T + 6.0234


41

Observed and Predicted Values


= -1E-05T2 + 0.0062T + 6.0234

42

T(oF)

(in/in/oF)
Given

(in/in/oF)
Predicted

-340

2.45

2.76

-300

3.07

3.26

-220

4.08

4.18

-160

4.72

4.78

-80

5.43

5.46

6.00

6.02

40

6.24

6.26

80

6.47

6.46

Regressing Data in Excel


(scientific format)

= -1.2360E-05T2 + 6.2714E-03T + 6.0234


43

Observed and Predicted Values


= -1.2360E-05T2 + 6.2714E-03T + 6.0234

44

T(oF)

(in/in/oF)
Given

(in/in/oF)
Predicted

-340

2.45

2.46

-300

3.07

3.03

-220

4.08

4.05

-160

4.72

4.70

-80

5.43

5.44

6.00

6.02

40

6.24

6.25

80

6.47

6.45

Observed and Predicted Values


= -1.2360E-05T2 + 6.2714E-03T + 6.0234

= -1E-05T2 + 0.0062T + 6.0234


T(oF)

45

(in/in/oF)
Given

(in/in/oF)
Predicted

(in/in/oF)
Predicted

-340

2.45

2.46

2.76

-300

3.07

3.03

3.26

-220

4.08

4.05

4.18

-160

4.72

4.70

4.78

-80

5.43

5.44

5.46

6.00

6.02

6.02

40

6.24

6.25

6.26

80

6.47

6.45

6.46

Error de Truncamieno

46

Truncation error
Error Causado por Truncamiento o aproximado
en un procedimiento matemtico.

47

Example of Truncation Error


Taking only a few terms of a Maclaurin series to
x

approximate

2
3
x
x
e x 1 x ....................
2! 3!

If only 3 terms are used,

x
x
Truncation Error e 1 x
2!

48

Another Example of Truncation Error


Using a finite

f (x)

to approximate

f ( x)

f ( x x) f ( x)
x

secant line

P
tangent line
Q

Figure 1. Approximate derivative using finite x

49

Another Example of Truncation


Error
Using finite rectangles to approximate an integral.

50

Example 1 Maclaurin series

e1.2

Calculate the value of

with an absolute

relative approximate error of less than 1%.

1.2

1.2 2 1.2 3
1 1.2

...................
2!
3!

e1.2

Ea

a %

__

___

2.2

1.2

54.545

2.92

0.72

24.658

3.208

0.288

8.9776

3.2944

0.0864

2.6226

3.3151

0.020736

0.62550

6 terms are required. How many are required to get at least 1 significant
digit correct in your answer?
51

Example 2 Differentiation
Find
and

f (3)

for

f ( x) x 2

x 0.2
f ' (3)

using

f ( x)

f (3 0.2) f (3)
0.2

f (3.2) f (3)
3.2 2 32

0.2
0.2
The actual value is

f ( x x) f ( x)
x

f ' ( x ) 2 x,

10.24 9
1.24

6. 2
0.2
0. 2

f ' (3) 2 3 6

Truncation error is then,

6 6.2 0.2
x 0.1

Can you find the truncation error with

52

Example 3 Integration
Use two rectangles of equal width to approximate the area under the
curve for

f ( x) x 2

over the interval

[3,9]

2
x
dx
3

53

Choosing a width of 3, we have


9

2
2
x
dx

(
x
)

x 3

(6 3) ( x 2 )

x 6

(9 6)

(3 2 )3 (6 2 )3
27 108 135
Actual value is given by
9

x3
2
3 x dx 3

93 33

234
3

Truncation error is then

234 135 99
Can you find the truncation error with 4 rectangles?
54

Medicion de Errores

55

PORQUE MEDIR
ERRORES?
Para determinar la exactitud del resultados
numrico.
Para desarrollar
iterativos.

56

los

criterios

de

algoritmos

ERROR VERDADERO
Definido como la diferencia entre el valor verdadero
obtenido en un clculo y el valor aproximado
encontrado con un mtodo numrico etc.

True Error = True Value Approximate Value

57

ExampleTrue Error
f (x)

The derivative,
can be

f ( x) 7e 0.5 x

and

f ( x h) f ( x)
h

h 0.3

a) Find the approximate value of


b) True value of
c) True error for part (a)

58

f (x)

approximated by the equation,


f ' ( x)

If

of a function

f ' ( 2)

f ' ( 2)

Solution:
a) For

x2

and

h 0.3

f ( 2 0.3) f ( 2)
f ' ( 2)
0. 3

f (2.3) f (2)

0.3
7e 0.5( 2.3) 7e 0.5( 2 )

0.3
22.107 19.028

0.3

59

10.263

Solution:
f ' ( 2)

b) The exact value of

can be found by using

our knowledge of differential calculus.

f ( x) 7e 0.5 x
f ' ( x ) 7 0.5 e 0.5 x
3.5e 0.5 x

So the true value of

f ' ( 2)

f ' ( 2) 3.5e 0.5( 2 )


9.5140
True error is calculated as

Et

True Value Approximate Value

9.5140 10.263 0.722


60

is

Error Relativo

Verdadero

Definido como el cociente entre el error verdadero, y el valor


verdadero.

Error.Verdadero
r
Valor.Verdadero

61

ExampleRelative True Error


Following from the previous example for true error,
f ( x) 7e 0.5 x find the relative true error for
at

f ' (2)

with

h 0.3

From the previous example,

Et 0.722
Relative True Error is defined as

0.722
9.5140

0.075888

as a percentage,
t 0.075888 100%

62

7.5888%

True Error
True Value

Error de aproximacion

Qu podemos hacer si los valores verdaderos no se


saben o son muy difcil de obtener?
El error aproximado se define como la diferencia
entre la aproximacion actual y la aproximacin
anterior.

Ea Aprox. Actual Aprox. Anterior

63

ExampleApproximate Error
f ( x) 7e 0.5 x

For

at x 2 find the following,

a)

f (2)

using

h 0.3

b)

f (2)

using

h 0.15

c) approximate error for the value of

Solution:
a) For

x2

and

h 0.3

f ( x h) f ( x)
f ' ( x)
h
f ' ( 2)
64

f ( 2 0.3) f ( 2)
0.3

f (2)

for part b)

f (2.3) f (2)

0 .3

(cont.)

7e 0.5( 2.3) 7e 0.5( 2)

0 .3

22.107 19.028 10.263

0.3
b) For

x2

and

f ' ( 2)

h 0.15
f (2 0.15) f ( 2)
0.15

f (2.15) f (2)

0.15
65

(cont.)
7e 0.5( 2.15) 7e 0.5( 2 )

0.15

20.50 19.028

0.15

9.8800

c) So the approximate error,

Ea

is

Present Approximation Previous Approximation

9.8800 10.263
0.38300

66

Ea

Error Relativo aproximado

Definido como el cociente entre el error


aproximado y la actual aproximacin.

67

Error . Aproximado

Aproximacion.acual

ExampleRelative Approximate Error


f ( x) 7e 0.5 x at

For

error using values from

x2

, find the relative approximate

h 0.3

and

h 0.15

Solution:

f (2) 10.263

From Example 3, the approximate value of


using

Ea

h 0.3

and

using

Present Approximation Previous Approximation

9.8800 10.263
0.38300

68

f (2) 9.8800

h 0.15

cont.
Approximate Error

Present Approximation

as a percentage,

0.38300
9.8800

0.038765

a 0.038765 100% 3.8765%

Absolute relative approximate errors may also need to be


calculated,
a | 0.038765 | 0.038765 or 3.8765 %

69

Cmo utilizar el error relativo absoluto como


criterio de paro?
If

|a | s

where

is a pre-specified tolerance, then

no further iterations are necessary and the process is stopped.


If at least m significant digits are required to be correct in the final
answer, then

|a | 0.5 10 2m %

70

Table of Values
For

71

f ( x) 7e 0.5 x

at x 2 with varying step size,

f (2)

0.3

10.263

N/A

0.15

9.8800

3.877%

0.10

9.7558

1.273%

0.01

9.5378

2.285%

0.001

9.5164

0.2249%

72

REPASO DE LA SERIE DE
TAYLOR

WIWIDATA ING.

73

Qu es la serie de Taylor?
Algunos de los ejemplos de la serie de Taylor que Ud. debe
haber visto

x2 x4 x6
cos( x) 1


2! 4! 6!

x3 x5 x7
sin( x) x
3! 5! 7!
2

x
x
e 1 x

2! 3!
x

74

WIWIDATA ING.

General Taylor Series


The general form of the Taylor series is given by

f x h f x f x h

f x 2 f x 3
h
h
2!
3!

Con la condicin de que todas sus derivadas de f(x) son continuas y


exista en el intervalo [x,x+h]

Como habra dicho Arqumedes, " dame el valor de la funcin en


un solo punto, y al valor de todos los (primero, segundo,
etctera) de sus derivados en ese solo punto, puedo darle el
valor de la funcin en cualquier otro punto

75

WIWIDATA ING.

ExampleTaylor Series
f 6

Find the value of

f 4 30,
of

f x

f 4 6
at

given that

f 4 125,

f 4 74,

and all other higher order derivatives

x4

are zero.

Solution:

x4

h2
h3
f x h f x f x h f x f x
2!
3!

h 64 2

76

WIWIDATA ING.

Solution: (cont.)
Since the higher order derivatives are zero,
22
23
f 4 2 f 4 f 4 2 f 4
f 4
2!
3!

22
23
6

f 6 125 74 2 30
2!
3!
125 148 60 8 341
Note that to find

f 6

exactly, we only need the value

of the function and all its derivatives at some other point, in this case

x4

77

WIWIDATA ING.

Derivation for Maclaurin Series for


ex
Derive the Maclaurin series

2
3
x
x
ex 1 x

2! 3!

The Maclaurin series is simply the Taylor series about the point
x=0

h2
h3
h4
h5
f x h f x f x h f x
f x
f x
f x

2!
3!
4
5
h2
h3
h4
h5
f 0 h f 0 f 0 h f 0
f 0
f 0
f 0

2!
3!
4
5

78

WIWIDATA ING.

Since

f ( x) e x , f ( x) e x , f ( x) e x , ... , f n ( x) e x and f n (0) e 0 1

the Maclaurin series is then

(e 0 ) 2
(e 0 ) 3
f ( h ) (e ) ( e ) h
h
h ...
2!
3!
0

1 2 1 3
1 h h h ...
2!
3!
So,

79

x 2 x3
f ( x) 1 x ...
2! 3!

WIWIDATA ING.

Error in Taylor Series


The Taylor polynomial of order n of a function f(x) with
(n+1) continuous derivatives in the domain [x,x+h] is
given by
h2
hn
n
f x h f x f x h f ' ' x f x Rn x
2!
n!
where the remainder is given by

where

x c xh

Rn

n 1

x h
x

that is, c is some point in the domain [x,x+h]

80

WIWIDATA ING.

(n 1)!

f n 1 c

Exampleerror in Taylor series


The Taylor series for

ex

at point

x0

is given by

2
3
4
5
x
x
x
x
ex 1 x

2! 3! 4! 5!

De la serie cuantos mas trminos se tome el error disminuye y


por lo tanto se tendr una mejor estimacin de la funcin a ser
calculada.
Cuntos
trminos
se
requeriran
para
conseguir
una
aproximacin de e1 dentro de una magnitud del error verdadero
de menos de 10-6.

81

WIWIDATA ING.

Solution:
Using

n 1

terms of Taylor series gives error

n 1

x h
Rn x
n 1!

n 1

0 1
Rn 0
n 1!

n 1

x 0, h 1, f ( x ) e x

f n 1 c

n 1

ec
n 1!

Since
x c xh
0 c 0 1
0 c 1

82

1
e
Rn 0
(n 1)!
(n 1)!

WIWIDATA ING.

bound of

Solution: (cont.)
So if we want to find out how many terms it would

e1

require to get an approximation of

within a

10 6

magnitude of true error of less than


e
10 6
(n 1)!

(n 1)! 10 6 e
(n 1)! 10 6 3

n9
So 9 terms or more are needed to get a true error
10 6
less than

83

WIWIDATA ING.

84

PROPAGACION DE
ERRORES

85

Propagacion de errores
En mtodos numricos, los clculos no
se hacen con nmeros exactos. Cmo
estas inexactitudes se propagan en los
clculos?

86

Example 1:
Encontrar los limites de Propagacion en la suma de dos numeros. Ejemplo si
uno esta calculando X +Y donde
X = 1.5 0.05
Y = 3.4 0.04
Solution
Maximum possible value of X = 1.55 y Y = 3.44
Maximum possible value of X+Y=1.55+3.44=4.99
Minimum possible value of X=1.45 y Y = 3.36.
Minimum possible value of X+Y=1.45+3.36=4.81
Por lo tanto
4.81 X + Y 4.99.

87

Propagacin de errores en
frmulas
SI f es una funcin de varias variables x1, x2, x3, .xn-1,
xn
entonces el valor mximo posible del error en f esta
dado:

f
f
f
f
f
X 1
X 2 .......
X n 1
X n
X 1
X 2
X n 1
X n

88

Example 2:
La tensin en un miembro axial de una seccin
representativa cuadrada esta dado:

F
2
h E
Encuentre el error mximo posible mximo en la
medida de la
la tension.

F 72 0.9 N

h 4 0.1 mm
E 70 1.5 GPa
89

Solucion

72

3 2
9
( 4 10 ) (70 10 )
64.286 10

64.286


F
h
E
F
h
E
90


2F
3
h
h E

1
2
F h E

F
2 2
E
h E

as

1
2F
F
E 2 F 3 h 2 2 E
h E
hE
h E
1
2 72

0.9
0.0001
( 4 10 3 ) 2 (70 109 )
( 4 10 3 ) 3 (70 10 9 )

72
9

1
.
5

10
( 4 10 3 ) 2 (70 109 ) 2

5.3955
Por lo tanto

91

(64.286 5.3955 )

Example 3:
La substraccin de los nmeros que son muy cercanos o casi iguales crea
inexactitudes indeseadas. Usaremos la frmula para la propagacin de
error, el cual se demuestra que esto es verdad.

Solution
Sea:
Entonces:

z x y
z

z
z
x
y
x
y

(1)x (1)y
x y
El cambio relativo esta dado por:

x y
z

z
x y
92

Por ejemplo si:

x 2 0.001
y 2.003 0.001

0.001 0.001
z

z
| 2 2.003 |
= 0.6667
= 66.67%

93

You might also like