Algebra Lineare Numerica - A.A. 2012

annuncio pubblicitario
Algebra Lineare Numerica - A.A. 2012-2013
Esercitazione n◦ 6
• Esercizio 1
Verificare i valori discussi a lezione relativi all’aritmetica IEEE in doppia precisione di
MATLAB. Quanto valgono realmax, realmin, il più piccolo numero positivo denormalizzato, eps e la precisione macchina?
• Esercizio 2
Si consideri il seguente codice MATLAB
f(1)=1; f(2)=1;
for i=2:n-1
f(i+1)=f(i)+f(i-1);
end
g(n)=f(n);
g(n-1)=f(n-1);
for i=(n-1):-1:2
g(i-1)=g(i+1)-g(i);
end
Al variare di n il programma calcola i primi n numeri di Fibonacci e successivamente calcola la stessa sequenza in ordine inverso.
Qual è l’indice del più grande numero di Fibonacci che può essere rappresentato esattamente come numero a doppia precisione di MATLAB senza essere affetto da errore di
roundoff ?
Qual è l’indice del più grande numero di Fibonacci che può essere approssimato come
numero a doppia precisione MATLAB senza overflow ?
Per valori di n compresi tra i due valori trovati, f(i) e g(i) sono molto diversi. Si dia
una spiegazione del perché ciò accada.
Si ricorda che MATLAB usa lo standard IEEE a doppia precisione.
• Esercizio 3(pag. 110 TB)
Verificare l’instabilità del calcolo degli autovalori come radici del polinomio caratteristico,
considerando la matrice
1 + 10−14 0
A=
.
0
1
1
• Esercizio 4
Verificare la stabilità backward della fattorizzazione QR di Householder come segue.
- Definire una matrice R = triu(randn(50)) triangolare superiore 50 × 50 con elementi
casuali distribuiti secondo una normale.
- Definire una matrice ortogonale Q ottenuta calcolando la fattorizzazione QR di una
matrice random 50 × 50, cioè [Q, X] = qr(randn(50)).
- Costruire A = QR.
- Calcolare la fattorizzazione QR di A con il metodo di Householder. Siano Q2 e R2 i
fattori trovati.
a) Calcolare l’accuratezza di Q2 e R2 rispetto ai fattori (quasi) esatti Q e R, cioè kQ2 − Qk
e kR2 − Rk/kRk. Assicurarsi che le colonne di Q e Q2 abbiano gli stessi segni, altrimenti
imporre tale proprietà moltiplicando le colonne di Q e le righe di R per i segni opportuni.
b) Calcolare l’accuratezza di Q2 R2 , cioè kA − Q2 R2 k/kAk.
c) Ripetere a), b) con le matrici Q2 , R2 perturbate in modo random come Q3 = Q2 + 1e −
4 · randn(50), R3 = R2 + 1e − 4 · randn(50), rendendo Q3 ortogonale ed R3 triangolare
superiore.
• Esercizio 5
Sia A ∈ Cn×n non singolare.
Si dimostri che
kδAk2
1
n×n
min
: δA ∈ C
A + δA è singolare =
.
kAk2
k2 (A)
2
Algebra Lineare Numerica - A.A. 2012-2013
Esercitazione n◦ 6
• Exercise 1
Verify the values in IEEE arithmetic double precision in MATLAB of the following quantities. How much are realmax, realmin, the smallest denormalized number, eps and the
machine epsilon?
• Exercise 2
Consider the MATLAB program
f(1)=1;
f(2)=1;
for i=2:n-1
f(i+1)=f(i)+f(i-1);
end g(n)=f(n);
g(n-1)=f(n-1);
for i=(n-1):-1:2
g(i-1)=g(i+1)-g(i);
end
For any input n, the program computes the first n Fibonacci numbers in the normal order
and it the compute the same sequence in reverse order.
What is the index of the largest Fibonacci number that can be represented exactly as a
MATLAB double-precision quantity without roundoff error?
What is the index of the largest Fibonacci number that can be represented approximately
as a Matlab double-precision quantity without overflowing?
Finally, for values of n between those found, the f(i) differs very much from the g(i).
Provide an explanation.
Note tha MATLAB uses IEEE double precision.
• Exercise 3(p. 110 TB)
Consider the following matrix
A=
1 + 10−14 0
0
1
.
Verify that computing the eigenvalues of A as the roots of the characteristic polynomial is
an unstable algorithm.
3
• Exercise 4
Verify the backward stability of the QR factorization by Householder as described below.
- Define an upper triangular matrix R = triu(randn(50)) 50 × 50, whose elements are
normally distributed.
- Define an orthogonal matrix Q obtained through a QR factorization of a random matrix
50 × 50, that is [Q, X] = qr(randn(50)).
- Build A = QR.
- Compute the QR factorization of A, using Householder. Q2 and R2 are the computed
factors.
a) Compute the accuracy of Q2 ed R2 with respect to Q and R, kQ2 − Qk and kR2 2 −
Rk/kRk. Make sure that Q and Q2 have the same sign, otherwise multiply the columns
of Q and rows of R by appropriate factors ±1.
b) Compute the accuracy of Q2 R2 , kA − Q2 R2 k/kAk.
c) Repeat a), b) using , instead of Q2 and R2 , Q3 = Q2 + 1e − 4 · randn(50) and R3 =
R2 + 1e − 4 · randn(50), take the trouble to make Q3 orthogonal and R3 upper triangular.
• Exercise 5
Let A ∈ Cn×n be nonsingular.
Then
kδAk2
1
n×n
min
.
: δA ∈ C
A + δA is singular =
kAk2
k2 (A)
4
Scarica