You are on page 1of 43

Programa de Ps Graduao

em Engenharia Mecnica - DEMEC/UFPE


Mtodos Numricos e Instroduo aos Mtodos
Numricos
Prof. Jos Maria Andrade

Sistemas de numerao e Erros

MEM977 Prof. Jos Maria

SISTEMAS DE NUMERAO

Objetivos
Relembrar conceitos do sistema decimal de numerao.
Trabalhar com o sistema binrio.
Converter informaes de um sistema para outro.
Estudar os tipos de erros numricos e suas consequncias.

TIPOS PRINCIPAIS DE SISTEMAS


Decimal
Este o sistema que trabalhamos desde os primeiros
anos escolares. Usa dez caracteres (0, 1, 2, 3, 4, 5, 6, 7,
8 e 9), tambm chamados de dgitos, para representar
uma informao qualquer.

Parte Inteira e Fracionria de um numero decimal

Exemplos
Exemplo 1.1 Representao do nmero decimal 581 na
forma polinomial.

Exemplo 1.2 Representao do nmero 135,23 da base 6


na forma polinomial (FP) e obteno do decimal
equivalente.

Sistema Binrio
O sistema binrio usa apenas os caracteres 0 e 1 (base 2)
para representar uma informao qualquer.
Exemplo 1.3 - Representao do binrio 1110 na forma
polinomial (FP) e obteno do decimal equivalente.

Exemplo
Exemplo 1.4 - Representao do binrio 101,11 na forma
polinomial (FP) e obteno do decimal equivalente.

Outras bases de numerao


Numbers we use are DECIMAL (or base 10):
Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
123 = 1*102 + 2*101 + 3*100
But we can always use other bases:
Octal (base 8):
Digits: 0, 1, 2, 3, 4, 5, 6, 7
123 = 1*82 + 2*81 + 3*80
1238 = 64+16+3 = 8310
Binary (base 2):
Digits: 0, 1
1011 = 1*23 + 0*22 + 1*21 + 1*20
10112 = 8+0+2+1 = 1110
1238 = 001 010 011 = 10100112
Hexadecimal (base 16):
Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
123 = 1*162 + 2*161 + 3*160
12316 = 256 + 32 + 3 = 29110
12316 = 0001 0010 0011 = 1001000112
MEM977 Prof. Jos Maria

CONVERSES ENTRE BASES


Decimal inteiro N para a base r

Dr = (Qn Rn Rn-1 Rn-2 ... R1)r

Exemplo
Exemplo 1.5 - Converso do decimal 350 para binrio.

Nmero com parte inteira e fracionria


Exemplo 1.6 - Converso do decimal 350,233 para binrio.

Conhecendo o Byte

A byte is the smallest memory allocation available.


A byte contains 8 bits so that:
Smallest: 0 0 0 0 0 0 0 0 = 0
10

Largest: 1 1 1 1 1 1 1 1 =
1*27+1*26+1*25+1*24+1*23+1*22+1*21+1*20 = 25510 (or 281)
Result: a single byte can be used to store an integer
number ranging from 0 to 255 (256 different numbers)
If negative numbers are included, one bit must be dedicated
to the sign, leaving only 7 bits for the number
Smallest: 0
Largest: +127
10 or -12810

MEM977 Prof. Jos Maria

12

Magnitude com sinal

Example of signed magnitude:

000001012

=> + 5

100001012

=> - 5

Notice also that signed-magnitude gives plus and minus


zero!

000000002 => + 0
100000002 => - 0

MEM977 Prof. Jos Maria

13

Preciso de nmeros em bytes


28- 1 (255) is not a very big number, so computers generally use
multiple bytes to represent numbers:
Here is some new vocabulary:
byte = 8 bits
short (precision) = 2 bytes
Java and other
single (precision) = 4 bytes
languages use
different
double (precision) = 8 bytes
names!
quad (precision) = 16 bytes
char = 2 bytes (used to be 1 byte)

Note: A word is the basic size of the CPU registers and for
Pentium chips it is 4 bytes or 32 bits; it is 8 bytes for the new
Itanium and some unix chipsets. It was 2 bytes for early Intel
chips; some new game consoles use 16 byte words.
MEM977 Prof. Jos Maria

14

Aritimtica de ponto Flutuante

How are fractional numbers (called real or floating point


numbers) stored in a computer?
The IEEE 754 double format consists of three fields:
a 52-bit fraction, f (also called the mantissa)
an 11-bit based exponent, e
and a 1-bit sign, s
These fields are stored contiguously in 8 bytes (or 2
successively addressed 4-byte words = 64 bits):

MEM977 Prof. Jos Maria

15

Padro IEEE de ponto flutuante

MEM977 Prof. Jos Maria

16

Representao dos nmeros


Because only a finite number of bits are used for each part
of the number, not all possible real numbers can be
represented in a computer using IEEE 754

0
Negative numbers greater
than -2-1022
(negative underflow)

Positive numbers greater


than (2-2-52) x 21023
(positive overflow, Matlab
realmax)
Positive numbers smaller than 2-1022
(positive underflow, Matlab realmin)

Negative numbers less than -(2-2-52) x 21023


(negative overflow)

Zero (actually is a special


combination of bits)

RESULT: about 16 digits of precision in the range 10308


MEM977 Prof. Jos Maria

17

Fontes de erro em computao

Others sources of error in computation:

Errors in the input data - measurement errors, errors


introduced by the conversion of decimal data to binary,
roundoff errors;
Roundoff errors during computation (as discussed);
Truncation errors - using approximate calculation is
inevitable when computing quantities involving limits and
other infinite processes on a computer
Never try to compare two floating point numbers for
equality because all 16+ digits would have to match
perfectly

MEM977 Prof. Jos Maria

18

Nmeros: Preciso e Exatido (acurcia)

Good Accuracy
Good Precision

Good Precision
Poor Accuracy

Good Accuracy
Poor Precision

Poor Accuracy
Poor Precision

Low precision: = 3.14


High precision: = 3.140101011
Low accuracy: = 3.10212
High accuracy: = 3.14159
High accuracy & precision: = 3.141592653
MEM977 Prof. Jos Maria

19

Descrevendo Erro no MATLAB


Accuracy

How close your answer is to the actual or real


answer.
Precision

The smallest difference that can be represented on


the computer (help eps)
Recognize:

MATLAB (and other programs that use IEEE


doubles) give you 15-16 good digits

MATLAB will also store exact integer values using


only the mantissa (for about 15-16 digits total)
Matlab commands:

realmin, realmax, eps, bitmax (try with


help)

MEM977 Prof. Jos Maria

20

Memory in MATLAB

MEM977 Prof. Jos Maria

21

What it Means

In the previous slide, we see:


Name

Size

1x1

1x43

1x200

Bytes

8
86
1600

Class

double array
char array
double array

What is the size of the variable i


What does class represent?
How many bytes are used to store the value?

MEM977 Prof. Jos Maria

22

Back to MATLAB - what does all this mean?

We must pay attention to the math! (on any computer!)

Given a finite (limited) number of bits, almost all


computations will result in numbers that cant be
represented exactly.

Remember that the result of a floating-point


computation must be truncated to fit back into its finite
representation.

Always check your results - design programs to allow for


independent verification of computations!

MEM977 Prof. Jos Maria

23

Sistema de ponto flutuante

MEM977 Prof. Jos Maria

24

Sistema de ponto flutuante

MEM977 Prof. Jos Maria

25

Exerccio: Representao dos Nmeros

MEM977 Prof. Jos Maria

26

Exerccio: Representao dos Nmeros

MEM977 Prof. Jos Maria

27

Erros numricos e computacionais


Para avaliao da soluo de um problema fundamental
conhecer todo o processo de resoluo adotado e as
possveis aproximaes inerentes.
Nenhum resultado numrico ou computacional tem valor se
no tivermos conhecimento e controle dos possveis erros
envolvidos no processo.

MEM977 Prof. Jos Maria

28

Tipos de Erros

Uma soluo numrica nem sempre leva a um


nmero exato.

Existe uma diferena entre a soluo numrica e os


valores razoveis analticos ou experimentais.
Problema
Fsico

Algoritimo
Computacional

Problema
matemtico

Representao
dos nmeros na
mquina
MEM977 Prof. Jos Maria

Soluo
Analtica

Soluo
Numrica
29

Erro Absoluto e Relativo

MEM977 Prof. Jos Maria

30

Erro Absoluto e Relativo

Exercicio:
Qual a melhor aproximao das indicadas abaixo ?

MEM977 Prof. Jos Maria

31

Erro Absoluto e Relativo

MEM977 Prof. Jos Maria

32

Fontes de Erros
Erro na Modelagem
Devido expresso matemtica que no reflete perfeitamente o
fenmeno fsico ou aos dados terem sido obtidos com pouca
exatido.

Erro Grosseiro
Devido a erro na elaborao ou implementao do algoritmo ou a
erro de digitao.

MEM977 Prof. Jos Maria

33

Tipos de Erros Computacionais

Exerccio:
Calcular o valor de e1 por meio de uma srie truncada de
segunda ordem. Verificar o erro sabendo-se que o valor com 4
algarismos significativos 2,718.

MEM977 Prof. Jos Maria

34

Tipos de Erros Computacionais

MEM977 Prof. Jos Maria

35

Erros Computacionais - Exemplos


Operaes com diviso e multiplicao

MEM977 Prof. Jos Maria

36

Erros Computacionais - Exemplos


Nmeros fora da faixa de abrangncia

MEM977 Prof. Jos Maria

37

Erros Computacionais - Exemplos


Zero de ponto flutuante

MEM977 Prof. Jos Maria

38

Falhas por erros computacionais


Caso 1 - Guerra do Golfo, 25/fev/91 mssil Patriot dos EUA
falha na interceptao do missil Scud do Iraque
(fonte:http://ta.twi.tudelft.nl/users/vuik/wi211/disasters.html)

Causa:
Limitao na representao numrica
(24 bits)
Erro de 0,34 s no clculo do
tempo de lanamento

Consequncia: O Scud atinge acampamento americano e


28 soldados so mortos, ferindo mais umas 100 pessoas.
MEM977 Prof. Jos Maria

39

Falhas por erros computacionais


Caso 2: Guiana Francesa, 04/jun/96 - Exploso do foguete
Ariane 5. (fonte:http://ta.twi.tudelft.nl/users/vuik/wi211/disasters.html; http://www.around.com/ariane.html)
Causa: Erro de software no sistema de
referencia inercial. Um ponto flutuante de
de 64 bits relacionado a velocidade
horizontal do foguete com respeito
plataforma foi convertido para um
nmero de 16 bits, ocasionando o
desligamento do sistema guia 36,7 s aps
o lanamento.
Consequncia: U$7 bilhes de investimentos perdidos.
MEM977 Prof. Jos Maria

40

Falhas por erros computacionais


Caso 3: Mar do Norte/Noruega, 23/ago/91 - Afundamento
da Plataforma Martima Sleipner)

Causa: Inexatido no clculo de


aproximao pelo de MEF usando um
modelo linear elstico (com o software
NASTRAN). Erro na anlise apontou que
tenses de cisalhamento subestimadas em
47% levando a um projeto deficiente.
Consequncia: Prejuzo de U$700
milhes de investimentos.

MEM977 Prof. Jos Maria

41

Exerccio: Preciso da Mquina

MEM977 Prof. Jos Maria

42

Exerccio: Preciso da Mquina

MEM977 Prof. Jos Maria

43

You might also like