08.11.2014 Views

Approssimazione di funzioni e dati

Approssimazione di funzioni e dati

Approssimazione di funzioni e dati

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.

<strong>Approssimazione</strong> <strong>di</strong> <strong>funzioni</strong> e <strong>dati</strong><br />

Dati<br />

{x i , y i }, i = 1, . . .,N<br />

x i ∈ [a, b], detti no<strong>di</strong> o punti base, y i , valori ivi assunti da una f<br />

non nota o ”<strong>di</strong>fficile” da calcolare, si vuole trovare una F(x),<br />

definita in [a, b] :<br />

F(x i ) = y i .<br />

La funzione F(x) potrà essere usata<br />

• per interpolare i <strong>dati</strong>: stimare il valore assunto da f (x) in ogni<br />

altro punto <strong>di</strong> [a, b]<br />

• per estrapolare i <strong>dati</strong>: stimare il valore che f (x) assume in<br />

punti esterni all’intervallo [a, b].<br />

Il problema dell’estrapolazione è fortemente indeterminato, quello<br />

dell’interpolazione è risolubile se si suppone f (x) sufficientemente<br />

regolare nell’intervallo [a, b].


Dati, ad esempio,<br />

x 0 1 2 3 4 5 6 7 8<br />

f(x) 0.16 0.09 0.86 1.76 1.96 1.28 0.34 0.01 0.59<br />

congiungendoli con una spezzata (spline lineare).<br />

2<br />

1.8<br />

1.6<br />

1.4<br />

1.2<br />

1<br />

0.8<br />

0.6<br />

0.4<br />

0.2<br />

0<br />

0 1 2 3 4 5 6 7 8<br />

si ottiene una funzione interpolatrice continua ma non derivabile<br />

nei no<strong>di</strong> ⇒ molto sensibile agli errori nei <strong>dati</strong>.


In generale si sceglie come funzione interpolatrice<br />

• una funzione ”semplice”, come un polinomio<br />

• una funzione che coincida localmente con un polinomio (spline)<br />

• In qualche caso è opportuno usare <strong>funzioni</strong> trigonometriche o<br />

<strong>funzioni</strong> esponenziali.<br />

• Se si suppone che f (x) sia una funzione <strong>di</strong> variabile aleatoria con<br />

proprietà statistiche rilevabili dai <strong>dati</strong> osservati si puó ricorrere ai<br />

meto<strong>di</strong> della Statistica.


Teorema <strong>di</strong> Lagrange<br />

Data una funzione f (x) ∈ C n+1 ([a, b]), (continua con derivate<br />

continue fino all’or<strong>di</strong>ne n + 1 nell’intervallo [a, b] ed n + 1 coppie <strong>di</strong><br />

numeri reali<br />

{x i , f (x i )}, i = 0, . . .,n con x i ∈ [a, b]<br />

esiste uno ed un solo polinomio <strong>di</strong> grado n P L (x):<br />

P L (x i ) = f (x i ).<br />

P L (x) è detto polinomio interpolatore <strong>di</strong> Lagrange e sod<strong>di</strong>sfa la<br />

relazione<br />

f (x) = P L (x) + R L (x)<br />

R L (x) = f (n+1) (ξ x )<br />

(n + 1)! (x − x 0)...(x − x n ), ξ ∈ [a, b].


Dimostrazione<br />

La <strong>di</strong>mostrazione è costruttiva. In<strong>di</strong>chiamo con F(x) il polinomio<br />

<strong>di</strong> grado n + 1 che si annulla in tutti i no<strong>di</strong><br />

F(x) := ∏ n<br />

i=0 (x − x i)<br />

Per ogni k = 0, 1, 2, . . .,n, consideriamo<br />

F k (x) =<br />

F(x)<br />

(x − x k )<br />

F k (x k ) = ∏ n<br />

i=0,i≠k (x k − x i ).<br />

F k (x) é il polinomio <strong>di</strong> grado n che si annulla in tutti i no<strong>di</strong> <strong>di</strong>versi<br />

da x k ed F k (x k ) é il valore che esso assume per x = x k . Per ogni<br />

k = 0, 1, . . .,n la funzione base relativa al nodo k-esimo è il<br />

polinomio <strong>di</strong> grado n<br />

L k (x) := F k(x)<br />

F k (x k ) tale che L k(x i ) =<br />

cioè vale uno nel nodo x k e zero negli altri.<br />

{ 0 k ≠ i<br />

1 k = i


Il polinomio<br />

è <strong>di</strong> grado n e<br />

P L (x) = L 0 (x)f (x 0 ) + L 1 (x)f (x 1 ) + . . . + L n (x)f (x n )<br />

P L (x i ) = f (x i )<br />

i = 0, 1, . . .,n.<br />

Ogni altro polinomio <strong>di</strong> grado n che sod<strong>di</strong>sfi queste relazioni ha<br />

n + 1 ra<strong>di</strong>ci in comune con P L (x) e quin<strong>di</strong> coincide con esso ⇒<br />

P L (x) é il polinomio interpolatore <strong>di</strong> Lagrange.<br />

Si <strong>di</strong>mostra che l’errore <strong>di</strong> interpolazione che si commette<br />

prendendo P L (¯x) al posto <strong>di</strong> f (¯x) in un punto ¯x ∈ [a, b], <strong>di</strong>verso<br />

dai no<strong>di</strong>, é<br />

R L (x) = f (n+1) (ξ¯x )<br />

(n + 1)! (x − x 0)(x − x 1 )...(x − x n )<br />

resto della formula <strong>di</strong> interpolazione <strong>di</strong> Lagrange.


R L (x) = f (n+1) (ξ¯x )<br />

(n + 1)! (x − x 0)(x − x 1 )...(x − x n )<br />

implica che l’ interpolazione <strong>di</strong> Lagrange è <strong>di</strong> or<strong>di</strong>ne n, cioè esatta<br />

per polinomi <strong>di</strong> grado n<br />

Un polinomio <strong>di</strong> grado n ha la derivata n-esima sempre = 0.<br />

Ha un valore soprattutto teorico, dato che non conosciamo ξ¯x .<br />

Fornisce stime accettabili se f (n+1) è limitata in a, b.<br />

N.B. Non si calcolano esplicitamente i coefficienti delle <strong>funzioni</strong><br />

base L k (x), ma, per ridurre l’influenza degli errori <strong>di</strong><br />

arrotondamento, si usano come prodotto <strong>di</strong> monomi.<br />

Se si aggiungono punti ai <strong>dati</strong> {x i , y i := f (x i )}, i = 0, . . .n per<br />

ottenere un polinomio interpolatore <strong>di</strong> grado più elevato, si devono<br />

ricalcolare tutti i coefficienti.


Esempio<br />

Le <strong>funzioni</strong> base relative ai no<strong>di</strong> sono<br />

x 0 1 2 4<br />

y 0 6 8 48<br />

(x − 1)(x − 2)(x − 4)<br />

L 0 (x) = =<br />

(−1)(−2)(−4)<br />

(x − 0)(x − 2)(x − 4)<br />

L 1 (x) =<br />

(1 − 0)(1 − 2)(1 − 4)<br />

x(x − 1)(x − 4)<br />

L 2 (x) =<br />

2(2 − 1)(2 − 4)<br />

x(x − 1)(x − 2)<br />

L 3 (x) =<br />

4(4 − 2)(4 − 2)<br />

(x − 1)(x − 2)(x − 4)<br />

(−8)<br />

=<br />

x(x − 2)(x − 4)<br />

3<br />

=<br />

x(x − 1)(x − 4)<br />

(−4)<br />

=<br />

x(x − 1)(x − 2)<br />

24<br />

quin<strong>di</strong> il polinomio <strong>di</strong> Lagrange che interpola i <strong>dati</strong> osservati è<br />

P(x) = L 0 (x) · 0 + L 1 (x) · 6 + L 2 (x) · 8 + L 3 (x) · 48<br />

= 2x(x − 2)(x − 4) − 2x(x − 1)(x − 4) + 2x(x − 1)(x − 2).


0 0.5 1 1.5 2 2.5 3 3.5 4<br />

50<br />

45<br />

40<br />

35<br />

30<br />

25<br />

20<br />

15<br />

10<br />

5<br />

0<br />

Si ottiene, ad esempio f (1.75) ≃ P(1.75) = 7.21875.


Esercizio 2<br />

Il polinomio <strong>di</strong> Lagrange <strong>di</strong> grado 8 che interpola i <strong>dati</strong><br />

x 0 1 2 3 4 5 6 7 8<br />

f(x) 0.16 0.09 0.86 1.76 1.96 1.28 0.34 0.01 0.59<br />

2<br />

1.5<br />

1<br />

0.5<br />

0<br />

−0.5<br />

0 1 2 3 4 5 6 7 8


50<br />

45<br />

40<br />

35<br />

30<br />

25<br />

20<br />

15<br />

10<br />

5<br />

0<br />

0 0.5 1 1.5 2 2.5 3 3.5 4<br />

Linea continua: polinomio interpolatore <strong>di</strong> Lagrange<br />

Trattini: spezzata interpolatrice ( spline lineare )


2<br />

1.8<br />

1.6<br />

1.4<br />

1.2<br />

1<br />

0.8<br />

0.6<br />

0.4<br />

0.2<br />

0<br />

0 1 2 3 4 5 6 7 8<br />

Linea continua: polinomio interpolatore <strong>di</strong> Lagrange<br />

Trattini: spezzata interpolatrice ( spline lineare )


Polinomio <strong>di</strong> Newton<br />

Dati n + 1 valori {x i , y i } i=0,...,n , un metodo più efficiente per<br />

determinare il polinomio interpolatore, cioé quel polinomio P(x) <strong>di</strong><br />

grado n che sod<strong>di</strong>sfa tutte le relazioni P(x i ) = y i è il seguente.<br />

p 0 (x) := y 0<br />

sod<strong>di</strong>sfa solo la prima relazione. Aggiungendo a p 0 un termine che<br />

vale 0 in x 0 (in modo da salvare il risultato precedente) definiamo<br />

p 1 (x) := p 0 (x) + t 1 (x − x 0 ), con t 1 := y 1 − y 0<br />

x 1 − x 0<br />

N.B. t 1 é tale che p 1 (x 1 ) = y 1 . Ora p 1 sod<strong>di</strong>sfa le prime due<br />

relazioni ma non le altre. Aggiungiamo un termine che valga 0 sia<br />

in x 0 che in x 1<br />

p 2 (x) = p 1 (x) + t 2 (x − x 0 )(x − x 1 ), t 2 :=<br />

N.B. t 2 é tale che p 2 (x 2 ) = y 2 .<br />

y 2 − p 1 (x 2 ))<br />

8x 2 − x 1 )(x 2 − x 0 )


Al passo k<br />

p k (x) = p k−1 (x) + t k (x k − x 0 )(x k − x 1 ) · · ·(x k − x k−1 )<br />

t k :=<br />

fino ad ottenere il<br />

polinomio <strong>di</strong> Newton<br />

y k − p k−1 (x k )<br />

(x k − x 0 )(x k − x 1 ) · · ·(x k − x k−1 ) . . .<br />

(∗) p N (x) = y 0 +t 1 (x −x 0 )+ . . . t n (x −x 0 )(x −x 1 ) · · ·(x −x n−1 ).<br />

Dato che ha grado n e P N (x i ) = y i per i = 0, 1, . . .,n coincide<br />

con il polinomio interpolatore <strong>di</strong> Lagrange.<br />

Contrariamente a quanto succede per il polinomio <strong>di</strong> Lagrange,<br />

l’introduzione <strong>di</strong> un nuovo punto comporta solo l’aggiunta <strong>di</strong> un<br />

nuovo termine.


Differenze <strong>di</strong>vise<br />

I coefficienti del polinomio <strong>di</strong> Newton si possono calcolare anche<br />

nel modo seguente.<br />

def. Date n + 1 coppie <strong>di</strong> valori {(x i , f (x i ))} i=0,1,2,..n definiamo<br />

• Differenze <strong>di</strong>vise <strong>di</strong> or<strong>di</strong>ne 1 f [x 0 , x 1 ] := f (x 1) − f (x 0 )<br />

x 1 − x 0<br />

,<br />

• Diff. <strong>di</strong>vise <strong>di</strong> or<strong>di</strong>ne due f [x 0 , x 1 , x 2 ] := f [x 1, x 2 ] − f [x 0 , x 1 ]<br />

x 2 − x 0<br />

,<br />

• Diff. <strong>di</strong>vise <strong>di</strong> or<strong>di</strong>ne n<br />

f [x 0 , x 1 , . . .,x n ] := f [x 1, . . .,x n−1 ] − f [x 0 , . . .,x n−2 ]<br />

x n−1 − x 0<br />

.<br />

Le <strong>di</strong>fferenze <strong>di</strong>vise <strong>di</strong> or<strong>di</strong>ne uno sono rapporti incrementali della<br />

f (x), e quin<strong>di</strong> approssimazioni <strong>di</strong> f ′ (x), quelle <strong>di</strong> or<strong>di</strong>ne due sono<br />

rapporti incrementali del secondo or<strong>di</strong>ne, etc. Si <strong>di</strong>mostra che<br />

t i = f [x 0 , x 1 , . . .,x i ]<br />

i = 0, 1, . . .,n.


Tabella delle <strong>di</strong>fferenze <strong>di</strong>vise con n = 4<br />

x 0 f (x 0 )<br />

f [x 0 , x 1 ]<br />

x 1 f (x 1 ) f [x 0 , x 1 , x 2 ]<br />

f [x 1 , x 2 ] f [x 0 , x 1 , x 2 , x 3 ]<br />

x 2 f (x 2 ) f [x 1 , x 2 , x 3 ] f [x 0 , x 1 , x 2 , x 3 , x 4 ]<br />

f [x 2 , x 3 ] f [x 1 , x 2 , x 3 , x 4 ]<br />

x 3 f (x 3 ) f [x 2 , x 3 , x 4 ]<br />

f [x 3 , x 4 ]<br />

x 4 f (x 4 )<br />

Si ha<br />

f [x i , x i+1 ] = f [x i+1 , x i ], i = 0, 1, . . .<br />

e le <strong>di</strong>fferenze <strong>di</strong>vise <strong>di</strong> or<strong>di</strong>ne superiore non cambiano se gli<br />

argomenti vengono permutati ⇒ si possono aggiungere nuovi punti<br />

alla fine della tabella.


Il polinomio <strong>di</strong> Newton si può dunque scrivere anche nel modo<br />

seguente.<br />

p N (x) = f (x 0 ) + (x − x 0 )f [x 0 , x 1 ] + (x − x 0 )(x − x 1 )f [x 0 , x 1 , x 2 ]+<br />

+... + (x − x 0 )...(x − x n−1 )f [x 0 , x 1 , x 2 , . . .,x n ]<br />

Vale la relazione<br />

f (x) = p N (x) + R N (x)<br />

dove R N (x) é il resto della formula <strong>di</strong> Newton<br />

e si ha<br />

R N (x) := f [x 0 , x 1 , x 2 , ..,x n , x] ∏ n<br />

i=0 (x − x i)<br />

R N (x) = R L (x) = f (n+1) (ξ x ) ∏ n<br />

(n + 1)!<br />

(x − x i).<br />

i=0


Esempio<br />

x 0.9 1.1 1.3 1.5 1.7<br />

f (x) 1.3784 1.4491 1.5166 1.5811 1.6432<br />

I coefficienti del polinomio interpolatore <strong>di</strong> Newton sono gli elementi della<br />

prima <strong>di</strong>agonale.<br />

x f (x) f [x i ,x i+1 ] f [x i ,.,x i+2 ] f [x i ,.,x i+3 ] f [x i ,.,x i+4 ]<br />

0.9 1.3784<br />

0.3535<br />

1.1 1.4491 −0.04<br />

0.3375 4.167 · 10 − 3<br />

1.3 1.5166 −0.0375 0.010417<br />

0.3225 0.0125<br />

1.5 1.5811 −0.03<br />

0.3105<br />

1.7 1.6432


Si ha<br />

p 1 (x) = 1.3784 + 0.3535(x − 0.9)<br />

p 2 (x) = p 1 (x) − 0.04(x − 0.9)(x − 1.1)<br />

p 3 (x) = p 2 (x) + 4.167 · 10 −3 (x − 0.9)(x − 1.1)(x − 1.3)<br />

p 4 (x) = p 3 (x) + 0.010417(x − 0.9)(x − 1.1)(x − 1.3)(x − 1.5)<br />

p N (x) = 1.3784 + 0.3535(x − 0.9) − 0.04(x − 0.9)(x − 1.1)+<br />

+4.167 · 10 −3 (x − 0.9)(x − 1.1)(x − 1.3)+<br />

+0.010417(x − 0.9)(x − 1.1)(x − 1.3)(x − 1.5)<br />

Ad es. per f (1) si ottengono le seguenti stime:<br />

p 1 (1) = 1.41375 p 2 (1) = 1.41415<br />

p 3 (1) = 1.4141625 p 4 (1) = 1.4141468745


In questo esempio accademico sappiamo che la funzione tabulata è<br />

f (x) = √ 1 + x ed f (1) = √ 2 ≈ 1.41421356237309, quin<strong>di</strong> gli<br />

errori si possono calcolare e valgono, rispettivamente<br />

e 1 = 0.464 · 10 −3<br />

e 2 = 0.64 · 10 −4<br />

e 3 = 0.51 · 10 −4<br />

e 4 = 0.67 · 10 −4<br />

Si <strong>di</strong>mostra che l’interpolazione con polinomi <strong>di</strong> Lagrange su no<strong>di</strong><br />

equi<strong>di</strong>stanti è più accurata al centro dell’intervallo.


Accuratezza nell’interpolazione polinomiale<br />

Volendo stimare il valore della funzione in un particolare punto,<br />

anziché utilizzare un polinomio <strong>di</strong> grado elevato è meglio usarne<br />

uno <strong>di</strong> grado piú basso, ma costruito su no<strong>di</strong> che costituiscono un<br />

intervallo simmetrico rispetto al punto da interpolare.<br />

Viene spontaneo pensare che l’approssimazione sia tanto migliore<br />

quanto più grande è il numero dei no<strong>di</strong> e quin<strong>di</strong> quanto più è<br />

elevato il grado del polinomio interpolatore. Ma non è così.<br />

Il grafico dei polinomi interpolatori, al crescere del grado, presenta<br />

oscillazioni <strong>di</strong> ampiezza crescente fra i valori nei no<strong>di</strong>, con un<br />

errore particolarmente alto in vicinanza degli estremi dell’intervallo.<br />

Questo comportamento, dell’errore, detto fenomeno <strong>di</strong> Runge, è<br />

tipico dell’interpolazione con polinomi <strong>di</strong> grado elevato quando i<br />

no<strong>di</strong> sono equi<strong>di</strong>stanti e si può spiegare teoricamente.


Fenomeno <strong>di</strong> Runge<br />

2<br />

1.5<br />

1<br />

0.5<br />

0<br />

−0.5<br />

−5 −4 −3 −2 −1 0 1 2 3 4 5<br />

Un esempio classico é la funzione f (x) = 1<br />

1 + x 2 nell’intervallo<br />

[−5, 5]. Il grafico del polinomio P L (x) ottenuto interpolando i<br />

valori <strong>di</strong> f nei no<strong>di</strong> equi<strong>di</strong>stanti {x i = −5 + i}, i = 0, . . .,10} .


No<strong>di</strong> <strong>di</strong> Chebyshev<br />

Se i punti base per l’interpolazione in [−1 1] sono gli zeri del<br />

polinomio <strong>di</strong> Chebyshev <strong>di</strong> grado n, detti no<strong>di</strong> <strong>di</strong> Chebyshev<br />

( 2k + 1<br />

t k = − cos<br />

n + 1 · π )<br />

per k = 0, 1, . . .,n<br />

2<br />

l’ errore <strong>di</strong> interpolazione é uniforme su tutto l’intervallo.<br />

Se x i ∈ [a, b], ed f (x) é nota analiticamente, il cambio <strong>di</strong> variabile<br />

x =<br />

(b − a) · t + (b + a)<br />

2<br />

fornisce i punti base per l’interpolazione,<br />

per − 1 ≤ t ≤ 1<br />

x k := b − a<br />

2 t k + b + a<br />

2<br />

k = 1, ..n.


p C (x), il polinomio interpolatore <strong>di</strong> grado n basato sui no<strong>di</strong> <strong>di</strong><br />

Chebychev, è, fra tutti i polinomi interpolatori <strong>di</strong> grado n, quello<br />

per il quale è minimo il massimo errore <strong>di</strong> interpolazione. Inoltre<br />

lim n→∞ p C (x) = f (x) uniformemente in a, b.<br />

Nell’intervallo [−5, 5] i no<strong>di</strong> <strong>di</strong> Chebishev sono<br />

0.25<br />

0.2<br />

0.15<br />

0.1<br />

0.05<br />

0<br />

−0.05<br />

−0.1<br />

−0.15<br />

−0.2<br />

−0.25<br />

−6 −4 −2 0 2 4 6<br />

I no<strong>di</strong> <strong>di</strong> Chebyshev sono più fitti in prossimità degli estremi<br />

dell’intervallo.


Il grafico del polinomio che interpola i valori <strong>di</strong> f (x) = 1<br />

1+x 2<br />

nell’intervallo [−5, 5] sui no<strong>di</strong> <strong>di</strong> Chebyshev<br />

1.2<br />

1<br />

0.8<br />

0.6<br />

0.4<br />

0.2<br />

0<br />

−0.2<br />

−5 −4 −3 −2 −1 0 1 2 3 4 5


Commenti<br />

• Per poter utilizzare l’interpolazione <strong>di</strong> Chebyshev bisogna<br />

conoscere analiticamente la funzione da interpolare.<br />

• Se si hanno molti no<strong>di</strong> equi<strong>di</strong>stanti è preferibile usare più<br />

polinomi interpolatori <strong>di</strong> grado non troppo elevato, basati su no<strong>di</strong><br />

che costituiscono intervalli il più possibile simmetrici rispetto ai<br />

punti da interpolare oppure <strong>funzioni</strong> interpolatrici ”polinomiali<br />

tratti” (splines).


Derivazione numerica<br />

Se f è una funzione definita tramite una tabella a punti<br />

equi<strong>di</strong>stanti e si vuole stimare f ′ in pochi punti. Sia f ∈ C 3 ([a, b]).<br />

Dallo sviluppo in serie <strong>di</strong> Taylor<br />

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

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

3! f (3) (x) + . . .<br />

si ottiene<br />

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

(x) = − h h 2 f ′′ (ξ).<br />

Introducendo ∆, l’operatore delle <strong>di</strong>fferenze in avanti<br />

(∆f )(x) := f (x + h) − f (x),<br />

si può ricavare una stima <strong>di</strong> f ′ (x) tramite un rapporto incrementale<br />

basato sulle <strong>di</strong>fferenze in avanti<br />

f ′ (∆f )(x)<br />

(x) ≈<br />

h<br />

che fornisce un’approssimazione <strong>di</strong> or<strong>di</strong>ne uno, dato che l’errore è<br />

nullo per polinomi <strong>di</strong> grado uno.


Dallo sviluppo in serie <strong>di</strong> Taylor<br />

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

2 f ′′ (x) − h3<br />

3! f (3) (x) + . . .<br />

si ottiene<br />

f ′ f (x) − f (x − h)<br />

(x) = + h h 2 f ′′ (ξ).<br />

Introducendo ∇, l’operatore delle <strong>di</strong>fferenze all’in<strong>di</strong>etro,<br />

(∇f )(x) := f (x) − f (x − h),<br />

si ottiene la seguente stima, anch’essa <strong>di</strong> or<strong>di</strong>ne uno.<br />

f ′ (x) ≈<br />

(∇f )(x)<br />

.<br />

h


Sottraendo membro a membro i due sviluppi in serie <strong>di</strong> Taylor si<br />

ottiene<br />

e quin<strong>di</strong><br />

f (x + h) − f (x − h) = 2hf ′ (x) + h3<br />

3 · f (3) (ξ)<br />

f ′ (x) =<br />

f (x + h) − f (x − h)<br />

2h<br />

− h2<br />

6 f (3) (ξ).<br />

Introducendo δ, l’operatore delle <strong>di</strong>fferenze centrali,<br />

(δf )(x) := f (x + h) − f (x − h),<br />

si può ricavare una stima <strong>di</strong> f ′ con un’accuratezza <strong>di</strong> or<strong>di</strong>ne due<br />

f ′ (x) ≈<br />

(δf )(x)<br />

2h


Esercizio<br />

Stimare f ′ (4.5) dove f è la funzione definita dalla seguente tabella.<br />

x 4 4.25 4.5 4.75 5<br />

y 0.027 0.166375 0.512 1.157625 2.197<br />

I <strong>dati</strong> della tabella ci consentono <strong>di</strong> stimare f ′ (4.5) tramite ∆, ∇ e<br />

δ, con h = 0.25 ottenendo :<br />

f (4.75) − f (4.5)<br />

F ∆ (h) = = 2.5825<br />

0.25<br />

f (4.5) − f (4.25)<br />

F ∇ (h) = = 1.3825<br />

0.25<br />

f (4.75) − f (4.25)<br />

F δ (h) = = 1.9825<br />

0.5<br />

Sapendo che la funzione tabulata è f (x) = (x − 3.7) 3 , si ha<br />

f ′ (4.5) = 1.92, quin<strong>di</strong> l’errore sulle varie stime è il seguente.<br />

e ∆ = −0.6625, e ∇ = 0.5375 e e δ = −0.0625.


Estrapolazione <strong>di</strong> Richardson<br />

Supponiamo che F(h) in<strong>di</strong>chi il valore <strong>di</strong> una certa quantità<br />

ottenuta con passo h, ad esempio la stima della derivata in un<br />

punto con ∆, e che si conosca l’andamento dell’errore al variare <strong>di</strong><br />

h, potendo scrivere<br />

a 0 = F(h) + a 1 h p + O(h r ), (h → 0, r > p)<br />

dove a 0 è la quantità che cerchiamo <strong>di</strong> calcolare.<br />

Applicando la formula con un passo q · h, si ottiene<br />

a 0 = F(qh) + a 1 (qh) p + O(h r ).<br />

Sottraendo membro a membro si ha<br />

0 ≈ F(h) + a 1 h p − F(qh) − a 1 q p h p .<br />

Si ricava la seguente stima per il primo termine <strong>di</strong> errore<br />

a 1 h p F(h) − F(qh)<br />

≈<br />

q p − 1<br />

e quin<strong>di</strong> una nuova stima, più accurata, è


Nel caso della stima <strong>di</strong> f ′ (x) tramite le <strong>di</strong>fferenze centrali si ottiene<br />

f ′ (x) = F 1 (h) = F δ (h) + a 1 h 2 + a 2 h 4 + . . .<br />

f ′ (x) = F 1 (2h) = F δ (2h) + a 1 · 4h 2 + a 2 · 16h 4 + . . ..<br />

Di conseguenza<br />

a 1 h 2 ≈ F 1(h) − F 1 (2h)<br />

3<br />

F 2 (h) := F 1 (h) + F 1(h) − F 1 (2h)<br />

3<br />

Continuando il proce<strong>di</strong>mento da<br />

f ′ (x) = F 2 (h) + a 2 h 4 + . . .<br />

f ′ (x) = F 2 (2h) + a 2 · 16h 4 + . . .


si ottiene<br />

a 2 h 4 ≈ F 2(h) − F 2 (2h)<br />

15<br />

F 3 (h) := F 2 (h) + F 2(h) − F 2 (2h)<br />

.<br />

15<br />

Le stime fornite dai vari F i (h) sono via via più accurate, dato che<br />

f ′ (x) = F 1 (h) + O(h 2 )<br />

= F 2 (h) + O(h 4 )<br />

= F 3 (h) + O(h 6 )....


Esempio<br />

Riprendendo l’esempio precedente, da<br />

F 1 (h) =<br />

f (4.75) − f (4.25)<br />

0.5<br />

= 1.9825<br />

F 1 (2h) =<br />

si ottiene la stima dell’errore<br />

f (5) − f (4)<br />

1<br />

a 1 h 2 ≈ F 1(h) − F 1 (2h)<br />

3<br />

ed una stima più accurata per la derivata<br />

= 2.17<br />

= −0.0625<br />

f ′ (4.5) ≈ F 2 (h) = F 1 (h)+ F 1(h) − F 1 (2h)<br />

3<br />

= 1.9825−0.0625 = 1.92<br />

con un errore dell’or<strong>di</strong>ne <strong>di</strong> h 4 ≈ 0.25 4 = 0.39 · 10 −2 .

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

Saved successfully!

Ooh no, something went wrong!