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 />

Esempio<br />

Esempio 3.6.4 Consideriamo il problema <strong>di</strong> approssimare la derivata della funzione f (x) = sin x nel<br />

punto x = 1.2.<br />

Supponiamo <strong>di</strong> non poter valutare <strong>di</strong>rettamente la derivata della f e <strong>di</strong> volerla approssimare applicando<br />

la formula polinomiale <strong>di</strong> Taylor:<br />

Allora<br />

f (x 0 + h) = f (x 0 ) + h f ′ (x 0 ) + h2<br />

2 f ′′ (x 0 ) + h3<br />

6 f ′′′ (x 0 ) + h4<br />

24 f IV (x 0 ) + ...<br />

f ′ (x 0 ) = f (x 0 + h) − f (x 0 )<br />

− ( h h<br />

2 f ′′ (x 0 ) + h2<br />

6 f ′′′ (x 0 ) + h3<br />

24 f IV (x 0 ) + ...)<br />

Approssimiamo, quin<strong>di</strong>, la f ′ (x 0 ) calcolando f (x 0 + h) − f (x 0 )<br />

.<br />

h<br />

L’errore, detto errore <strong>di</strong> <strong>di</strong>scretizzazione, che si commette è<br />

|f ′ (x 0 ) − f (x 0 + h) − f (x 0 )<br />

| = | h h<br />

2 f ′′ (x 0 ) + h2<br />

6 f ′′′ (x 0 ) + h3<br />

24 f IV (x 0 ) + ...|<br />

Supponendo <strong>di</strong> conoscere il valore della derivata seconda in x 0 , per piccoli valori <strong>di</strong> h possiamo dare una<br />

stima dell’errore <strong>di</strong> <strong>di</strong>scretizzazione,<br />

|f ′ (x 0 ) − f (x 0 + h) − f (x 0 )<br />

| ≈ h h<br />

2 |f ′′ (x 0 )|<br />

Ci aspettiamo, anche senza conoscere il valore <strong>di</strong> f ′′ (x 0 ) (purchè <strong>di</strong>verso da 0) che l’errore <strong>di</strong><br />

<strong>di</strong>scretizzazione <strong>di</strong>minuisca proporzionalmente con il passo h, al decrescere <strong>di</strong> h.<br />

Nel nostro caso, in cui f (x) = sin(x), noi conosciamo il valore esatto della derivata in 1.2, cos(1.2) =<br />

0.362357754476674... e possiamo dunque calcolare l’errore esatto che commettiamo approssimando la<br />

derivata <strong>di</strong> sin x con la formula che abbiamo ricavato.<br />

Per h = 0.1 non abbiamo un’approssimazione accurata. Ci aspettiamo che <strong>di</strong>minuendo il passo h l’errore<br />

che commettiamo <strong>di</strong>minuisca.<br />

Riportiamo gli errori della formula (in valore assoluto) e confrontiamoli con l’errore <strong>di</strong> <strong>di</strong>scretizzazione<br />

h<br />

2 |f ′′ (x 0 )| (i conti sono fatti in singola precisione):<br />

h errore<br />

h<br />

2 |f ′′ (x 0 )|<br />

1.e-1 4.7167e-2 4.6602e-2<br />

1.e-2 4.6662e-3 4.6602e-3<br />

1.e-3 4.6608e-4 4.6602e-4<br />

1.e-4 4.6603e-5 4.6602e-5<br />

1.e-5 4.6602e-6 4.6602e-6<br />

1.e-6 4.6597e-7 4.6602e-7<br />

L’errore commesso dall’algoritmo decresce come h e, in particolare, come h 2 |f ′′ (1.2)| = 0.46602h.<br />

Possiamo pensare <strong>di</strong> ottenere un’accuratezza grande quanto vogliamo a con<strong>di</strong>zione <strong>di</strong> prendere valori <strong>di</strong><br />

h sempre più piccoli. In realtà, per valori <strong>di</strong> h molto piccoli, gli errori iniziano ad aumentare!<br />

30

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

Saved successfully!

Ooh no, something went wrong!