20.05.2013 Views

Esercizi sull'aritmetica di macchina e la rappresentazione

Esercizi sull'aritmetica di macchina e la rappresentazione

Esercizi sull'aritmetica di macchina e la rappresentazione

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ESERCIZI CAPITOLO 1<br />

<strong>Esercizi</strong>o 1 Calco<strong>la</strong>re il minimo e il massimo numero rappresentabile e <strong>la</strong> car<strong>di</strong>nalità<br />

dell’insieme <strong>di</strong> numeri <strong>macchina</strong> F(2, 4, −2, 3). Quanto vale <strong>la</strong> <strong>di</strong>stanza re<strong>la</strong>tiva<br />

massima tra due numeri consecutivi ɛM e quanto <strong>la</strong> precisione <strong>di</strong> <strong>macchina</strong><br />

u?<br />

<strong>Esercizi</strong>o 2 Supponendo <strong>di</strong> avere a <strong>di</strong>sposizione 3 bit per l’esponente e 5 bit per <strong>la</strong><br />

mantissa, e usando lo standard IEEE-754r<br />

1. Si <strong>di</strong>ca qual è l’insieme dei numeri <strong>macchina</strong>.<br />

2. Si determini il minimo e il massimo numero rappresentabile, <strong>la</strong> <strong>di</strong>stanza re<strong>la</strong>tiva<br />

massima tra due numeri consecutivi ɛM e <strong>la</strong> precisione <strong>di</strong> <strong>macchina</strong><br />

u.<br />

3. Si <strong>di</strong>ca quale numero rappresenta <strong>la</strong> configurazione <strong>di</strong> bit 0 101 1011.<br />

4. Si <strong>di</strong>a <strong>la</strong> <strong>rappresentazione</strong> binaria in virgo<strong>la</strong> mobile normalizzata dei seguenti<br />

numeri reali: (a) 6.5 (b) -7.3 (c) 16<br />

5. Quantificare gli errori <strong>di</strong> <strong>rappresentazione</strong> commessi ai punti 4.a) e 4.b).<br />

6. Quanto vale <strong>la</strong> <strong>di</strong>stanza assoluta tra x = 6.5 e il suo successivo numero<br />

<strong>macchina</strong> x+?<br />

Soluzioni:<br />

2. realmin= 2 −2 = 0.25 con <strong>rappresentazione</strong> binaria 0 001 0000<br />

realmax = (2 − 2 −4 ) · 2 3 = 15.5 con <strong>rappresentazione</strong> binaria 0 110 1111<br />

ɛM = 2 1−t = 2 1−5 = 2 −4<br />

u = ɛM/2 = 2 −5 .<br />

3. 6.75<br />

4.a. 0 101 1010, 4.b. 1 101 1101, 4.c. 0 111 0000 (Inf).<br />

<strong>Esercizi</strong>o 3 Cosa sucede se si prova a calco<strong>la</strong>re a 2 − b 2 con a = 1.4 · 10 154 e b =<br />

1.3 · 10 154 in un calco<strong>la</strong>tore con aritmetica IEEE-754r in doppia precisione? Come<br />

si potrebbe realizzare questo calcolo in maniera stabile?<br />

<strong>Esercizi</strong>o 4 Si <strong>di</strong>mostri con un esempio che <strong>la</strong> proprietà associativa del prodotto<br />

non è verificata in aritmetica <strong>di</strong> <strong>macchina</strong>. (Suggerimento: ricordare che in<br />

F(2, 53, −1022, 1023) il numero più grande rappresentabile è ≈ 1.7977 · 10 308 ).


CALCOLO NUMERICO LT INFORMATICA AA.2011–2012 2<br />

<strong>Esercizi</strong>o 5 Si faccia un esempio in cui <strong>la</strong> proprietà associativa del<strong>la</strong> somma in<br />

aritmetica <strong>di</strong> <strong>macchina</strong> non sia verificata per effetto <strong>di</strong> cancel<strong>la</strong>zione numerica in<br />

F(10, 6, L, U).<br />

√n <br />

<strong>Esercizi</strong>o 6 Si definisca an = n 2 + 1 − n . Sapendo che lim<br />

n→∞ an = 1<br />

, quale<br />

2<br />

sarà il valore fornito da MATLAB/OCTAVE per an quando n = 10 8 ? Rispondere al<br />

quesito senza calco<strong>la</strong>re an, e quantificare gli errori assoluto e re<strong>la</strong>tivo commessi<br />

assumendo come valore vero quello del limite.<br />

<strong>Esercizi</strong>o 7 Sia x = 10 −15 . Si calcoli l’espressione<br />

(1 + x) − 1<br />

.<br />

x<br />

Perché il risultato è meno accurato che prendendo x = 8.88178419700125 · 10 −16<br />

(x = 4ɛM) ?<br />

<strong>Esercizi</strong>o 8<br />

exp(x) − 1<br />

1. Se si calco<strong>la</strong> il valore del<strong>la</strong> funzione ϕ(x) = nei punti x = 10<br />

x<br />

−i , i =<br />

5, · · · , 16 in aritmetica in doppia precisione (per esempio usando MATLAB/OC-<br />

TAVE ) si ottengono i seguenti risultati:<br />

x valore calco<strong>la</strong>to valore vero errore re<strong>la</strong>tivo<br />

con 15 cifre significative<br />

1e − 05 1.00000500000696 1.00000500001667 9.7017e-12<br />

1e − 06 1.00000049996218 1.00000050000017 3.7983e-11<br />

1e − 07 1.00000004943368 1.00000005000000 5.6632e-10<br />

1e − 08 0.999999993922529 1.00000000500000 1.1077e-08<br />

1e − 09 1.00000008274037 1.00000000050000 8.2240e-08<br />

1e − 10 1.00000008274037 1.00000000005000 8.2690e-08<br />

1e − 11 1.00000008274037 1.00000000000500 8.2735e-08<br />

1e − 12 1.00008890058234 1.00000000000050 8.8900e-05<br />

1e − 13 0.999200722162641 1.00000000000005 7.9927e-04<br />

1e − 14 0.999200722162641 1.00000000000001 7.9927e-04<br />

1e − 15 1.11022302462516 1.00000000000000 1.1022e-01<br />

1e − 16 0 1.00000000000000 1.0000e+00<br />

Perché i risultati sono inaccurati?<br />

Suggerimento: Quanto vale exp(x) per x ≈ 0?


CALCOLO NUMERICO LT INFORMATICA AA.2011–2012 3<br />

2. Usando l’espansione in serie <strong>di</strong> Taylor exp(x) = ∞ x<br />

i=0<br />

i<br />

si ha che ϕ(x) =<br />

i!<br />

∞ x<br />

i=1<br />

i−1<br />

. Usare questo risultato per ricavare una formu<strong>la</strong> stabile per il<br />

i!<br />

calcolo <strong>di</strong> ϕ(x) negli stessi punti <strong>di</strong> prima.<br />

<strong>Esercizi</strong>o 9 Implementare in MATLAB/OCTAVE il calcolo <strong>di</strong> sin x me<strong>di</strong>ante <strong>la</strong> serie:<br />

per x = π<br />

2 (4k + 1), k = 0, · · · , 8.<br />

sin x = x − x3<br />

3!<br />

+ x5<br />

5!<br />

− x7<br />

7!<br />

Si può usare, ad esempio, l’algoritmo seguente:<br />

s =0;t=x;n=1;<br />

while abs(t) > 2^-53<br />

s=s+t; t=-x.^2/((n+1)*(n+2))*t;<br />

n=n+2;<br />

end<br />

+ · · ·<br />

dove s è il valore accumu<strong>la</strong>to approssimante sin x, t è il valore del termine n-esimo.<br />

Il proce<strong>di</strong>mento si arresta quando il termine n + 1-esimo è inferiore in modulo al<strong>la</strong><br />

precisione <strong>di</strong> <strong>macchina</strong>. Calco<strong>la</strong>re l’errore re<strong>la</strong>tivo dei risultati ottenuti rispetto al<br />

valore vero sin x = 1.<br />

Un esempio <strong>di</strong> output è il seguente:<br />

k : 0 n : 23 s : 1.000000000000000 ERR : 2.22e − 16<br />

k : 1 n : 47 s : 0.999999999999999 ERR : 9.99e − 16<br />

k : 2 n : 65 s : 0.999999999993139 ERR : 6.86e − 12<br />

k : 3 n : 85 s : 1.000000002337549 ERR : 2.34e − 09<br />

k : 4 n : 103 s : 1.000000916919246 ERR : 9.17e − 07<br />

k : 5 n : 119 s : 0.999866764041850 ERR : 1.33e − 04<br />

k : 6 n : 137 s : 0.365329077658930 ERR : 6.35e − 01<br />

k : 7 n : 155 s : 128.376726646796300 ERR : 1.27e + 02<br />

k : 8 n : 173 s : 105749.827986279837205 ERR : 1.06e + 05<br />

Si <strong>di</strong>a una interpretazione dei risultati ottenuti.<br />

<strong>Esercizi</strong>o 10 Data <strong>la</strong> seguente successione <strong>di</strong> integrali definiti<br />

In =<br />

1<br />

0<br />

x n<br />

x + 5 dx,


CALCOLO NUMERICO LT INFORMATICA AA.2011–2012 4<br />

1. Si calcoli I0.<br />

2. Si calcoli I1 sapendo che<br />

x<br />

a<br />

= 1 −<br />

x + a x + a .<br />

3. Si consideri <strong>la</strong> seguente formu<strong>la</strong> ricorsiva per il calcolo <strong>di</strong> In:<br />

s0 = ln(1.2)<br />

sn = 1<br />

n − 5sn−1<br />

n<br />

> 0<br />

Si stu<strong>di</strong> <strong>la</strong> stabilità <strong>di</strong> tale formu<strong>la</strong> esprimendo l’errore al passo n, |en| in<br />

funzione dell’errore iniziale |e0|.<br />

4. Si ricavi una formu<strong>la</strong> stabile per il calcolo del<strong>la</strong> successione In giustificando<br />

<strong>la</strong> risposta.<br />

<strong>Esercizi</strong>o 11 Date le funzioni<br />

f1(x) = 1 − 1 − x 2 , f2(x) = 1 − x<br />

se ne calcoli analiticamente il con<strong>di</strong>zionamento<br />

Ki(fi, x) = |x|<br />

|fi(x)| |f ′ i(x)|, i = 1, 2.<br />

• Per quali valori <strong>di</strong> x le rispettive funzioni saranno malcon<strong>di</strong>zionate?<br />

• Per quali valori <strong>di</strong> x <strong>la</strong> funzione f1 presenta invece problemi <strong>di</strong> cancel<strong>la</strong>zione<br />

numerica?

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!