18.01.2015 Views

Appunti di Calcolo Numerico - Esercizi e Dispense - Università degli ...

Appunti di Calcolo Numerico - Esercizi e Dispense - Università degli ...

Appunti di Calcolo Numerico - Esercizi e Dispense - Università degli ...

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.

3. RAPPRESENTAZIONE DEI NUMERI NEL CALCOLATORE<br />

Se invece, consideriamo y n−1 = 1<br />

10 ( 1 n − y n), partendo da un valore <strong>di</strong> n molto grande e andando a<br />

ritroso, l’errore <strong>di</strong>minuisce. Perciò, dato un valore <strong>di</strong> accuratezza ɛ > 0 e fissato un intero n 1 è possibile<br />

determinare l’intero n 0 tale che, partendo da y n0 = 0 e andando a ritroso, gli integrali y n saranno<br />

valutati con un errore in valore assoluto minore <strong>di</strong> ɛ per 0 < n ≤ n 1 . Infatti:<br />

y n0 = 0<br />

y n0 −1 = 1 1<br />

10<br />

n 0<br />

y n0 −2 = 1<br />

10 ( 1<br />

n 0 − 1 − 1<br />

10<br />

. . .<br />

y n =<br />

1<br />

) =<br />

n 0<br />

1<br />

(−10) n 0−n n 0<br />

+ cost ante n0 −n<br />

1<br />

(−10) 2 n 0<br />

+ cost ante<br />

L’errore al passo n <strong>di</strong>pende, quin<strong>di</strong>, (in valore assoluto) da<br />

ɛ = 10 −6 , e fissiamo un valore n 1 , per calcolare n 0 dovrà essere<br />

1<br />

10 n 0−n 1<br />

< ɛ cioè 10 n 1−n 0<br />

< ɛ<br />

Passando al logaritmo in base 10:<br />

n 1 − n 0 < logɛ =⇒ n 0 > n 1 − logɛ<br />

1<br />

10 n 0−n<br />

Fissato n 1 = 20 si ricava n 0 = 26.<br />

Questa volta i calcoli danno gli stessi risultati sia in Matlab sia in Fortran:<br />

n y n n y n<br />

26 0.000000 11 7.62944e-3<br />

25 3.84615e-3 10 8.32797e-3<br />

24 3.61538e-3 9 9.16720e-3<br />

23 3.80513e-3 8 1.01944e-2<br />

22 3.96731e-3 7 1.14806e-2<br />

21 4.14872e-3 6 1.31377e-2<br />

20 4.34703e-3 5 1.53529e-2<br />

19 4.56530e-3 4 1.84647e-2<br />

18 4.80663e-3 3 2.31535e-2<br />

17 5.07489e-3 2 3.10180e-2<br />

16 5.37486e-3 1 4.68982e-2<br />

15 5.71251e-3 0 9.53102e-2<br />

14 6.09542e-3<br />

13 6.53332e-3<br />

12 7.03898e-3<br />

Osserviamo come il valore y 0 coincida con il valore teorico noto.<br />

. Se richie<strong>di</strong>amo una tolleranza<br />

L’esempio appena visto ci porta a dare alcune considerazioni sui criteri su cui si deve basare un algoritmo:<br />

un algoritmo deve essere accurato, efficiente e robusto, accurato nel senso che bisogna essere in grado<br />

<strong>di</strong> sapere la grandezza dell’errore che si commette nell’algoritmo stesso; efficiente in termini <strong>di</strong> velocità <strong>di</strong><br />

esecuzione e <strong>di</strong> richiesta <strong>di</strong> spazio <strong>di</strong> memoria per le variabili utilizzate; robusto nel dare il risultato corretto<br />

34

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

Saved successfully!

Ooh no, something went wrong!