Docsity

MATLAB pre-test summary (LAG), Sintesi del corso di Algebra Lineare e Geometria Analitica

Toggle sidebar
bg1
MATLAB summary
1 Floating Point Arithmetic
•Total Absorption / Mantissa Underflow (Very different magnitudes): a⊕b= ¯aor
a⊖b= ¯a
Before operating, numbers must be aligned by rounding the smaller one to the larger exponent.
The smaller number is shifted completely out of the mantissa digits and becomes zero, leaving
the larger number unchanged.
•Numeric Cancellation (Same magnitude, subtraction): a⊖b=δ
Occurs when subtracting two very close numbers (a≈b). The leading digits cancel out, causing
a drastic loss of significant digits.
•Exponent Overflow (result too large):
Occurs when the exponent of the calculated result exceeds the upper bound (e > U ). The
calculator cannot represent the magnitude, causing a system crash or returning ∞.
•Exponent Underflow (result too small):
Occurs when the exponent of the calculated result drops below the lower bound (e < L). The
number is smaller than the minimum positive representable value and is flushed to 0.
•Machine precision (when rounding): ϵM=1
2N1−t(where t: mantissa digits, N: base)
Why? N1−tis the distance between 1 and the next machine number
•Machine epsilon (when chopping/truncating): ϵM=N1−t(where t: mantissa digits, N: base)
•Positive machine numbers: n= (N−1) ·(Nt−1)·(U−L+ 1) (where t: mantissa digits, N:
base, U: exponent upper bound, L: exponent lower bound)
Why? (N−1) are the choices for the first digit that must be = 0, Nt−1are the remaining
digits, and (U−L+ 1) is the total number of exponents
•Rounding to the even technique:
– If dt+1 <5: Round down (truncate the mantissa to tdigits).
– If dt+1 ≥5: Round up (add 1 to the last kept digit dt).
•Normalized numbers in base N= 10: a=±0.d1d2. . . dt·10e(with d1= 0)
•Absolute error: ϵabs =|x−ˆx|(where x: exact value, ˆx: approximated value)
•Relative error: ϵr el =|x−ˆx|
|x|(where x: exact value, ˆx: approximated value, with x= 0)
•Conditioning of a problem →K = cond(f, x):
– Well-conditioned: K(f, x)≈1→Input errors do not amplify
– Ill-conditioned: K(f , x)≫1→Input errors explode in the output
•Smallest positive (non-zero) machine number: m≈2.2·10−308 →m = realmin
•Largest machine number: M≈1.8·10308 →M = realmax
•Machine epsilon: eps ≈2.2·10−16 →eps
•Machine precision: ϵm≈1.1·10−16
1
pf3
pf4
pf5

Anteprima parziale del testo

Scarica MATLAB pre-test summary (LAG) e più Sintesi del corso in PDF di Algebra Lineare e Geometria Analitica solo su Docsity!

MATLAB summary

1 Floating Point Arithmetic

  • Total Absorption / Mantissa Underflow (Very different magnitudes): a ⊕ b = ¯a or a ⊖ b = ¯a Before operating, numbers must be aligned by rounding the smaller one to the larger exponent. The smaller number is shifted completely out of the mantissa digits and becomes zero, leaving the larger number unchanged.
  • Numeric Cancellation (Same magnitude, subtraction): a ⊖ b = δ Occurs when subtracting two very close numbers (a ≈ b). The leading digits cancel out, causing a drastic loss of significant digits.
  • Exponent Overflow (result too large): Occurs when the exponent of the calculated result exceeds the upper bound (e > U ). The calculator cannot represent the magnitude, causing a system crash or returning ∞.
  • Exponent Underflow (result too small): Occurs when the exponent of the calculated result drops below the lower bound (e < L). The number is smaller than the minimum positive representable value and is flushed to 0.
  • Machine precision (when rounding): ϵM = 12 N 1 −t^ (where t: mantissa digits, N : base) Why? N 1 −t^ is the distance between 1 and the next machine number
  • Machine epsilon (when chopping/truncating): ϵM = N 1 −t^ (where t: mantissa digits, N : base)
  • Positive machine numbers: n = (N − 1) · (N t−^1 ) · (U − L + 1) (where t: mantissa digits, N : base, U : exponent upper bound, L: exponent lower bound) Why? (N − 1) are the choices for the first digit that must be ̸= 0, N t−^1 are the remaining digits, and (U − L + 1) is the total number of exponents
  • Rounding to the even technique:
    • If dt+1 < 5: Round down (truncate the mantissa to t digits).
    • If dt+1 ≥ 5: Round up (add 1 to the last kept digit dt).
  • Normalized numbers in base N = 10: a = ± 0 .d 1 d 2... dt · 10 e^ (with d 1 ̸= 0)
  • Absolute error: ϵabs = |x − xˆ| (where x: exact value, ˆx: approximated value)
  • Relative error: ϵrel = |x|−x|ˆx |(where x: exact value, ˆx: approximated value, with x ̸= 0)
  • Conditioning of a problem → K = cond(f, x):
    • Well-conditioned: K(f, x) ≈ 1 → Input errors do not amplify
    • Ill-conditioned: K(f, x) ≫ 1 → Input errors explode in the output
  • Smallest positive (non-zero) machine number: m ≈ 2. 2 · 10 −^308 → m = realmin
  • Largest machine number: M ≈ 1. 8 · 10308 → M = realmax
  • Machine epsilon: eps ≈ 2. 2 · 10 −^16 → eps
  • Machine precision: ϵm ≈ 1. 1 · 10 −^16

2 Polynomial functions

  • Polynomial fitting yields the coefficients of the polynomial → polyfit(x, y, degree)
  • Polynomial evaluation returns the y value of a function in a x point → polyval(polynomial, abscissa)

3 Cubic spline

  • The cubic spline interpolating f and satisfying not-a-knot conditions is a continuous piecewise polynomial function: - Clamped → spline(x, [y 0 ’ y; yn’], z) (first derivative at boundaries) - Natural → csape(x, y, ’variational’, z), with Curve Fitting Toolbox (second deriva- tive at boundaries) - Not-a-knot → spline(x, y, z) (third derivative at internal nodes)

4 Linear systems Ax = b

  • Gaussian elimination (with partial pivoting), also known as Backslash % Backslash / Gaussian elimination x = A \ b ;
  • LU = P A factorization Ax = b Original system P Ax = P b Multiply by P LU x = P b Substitute P A = LU L(U x) = P b Group y = U x ( Ly = P b U x = y

Lower triangular system (forward substitution) Upper triangular system (backward substitution)

% LU = PA factorization [ L U P ] = lu ( A ) % Lower system y = L \ ( P * b ) % Upper system x = U \ y

  • Cholesky factorization

Ax = b Original system RT^ Rx = b Substitute A = RT^ R RT^ (Rx) = b Group y = Rx

5 Eigenvalues λ

  • Eigenvalues λ ∈ C =⇒ Av = λv =⇒ (A − λI)v = 0 % Compute all eigenvalues and eigenvectors [ eigenvalues , eigenvalues_matrix ] = eig ( A ) % Extract eigenvalues vector from the diagonal matrix eigenvalues = diag ( eigenvalues_matrix ) % Compute only the n largest eigenvalues closest to k n_eigenvalues = eigs (A , n , k )
  • Rayleigh coefficient rA(x) = xxTT^ Ax (^) x
  • Conditioning number (for eigenvalues) → K = condeig(A):
    • Perfect / Normal: K(λ) = 1 → Symmetric/normal matrices, absolute stability
    • Well-conditioned: 1 < K(λ) < 103 → Input errors remain bounded and controllable
    • Ill-conditioned: K(λ) ≫ 103 → High sensitivity, input errors explode in the computed eigenvalues
    • Defective / Degenerate: K(λ) = ∞ → Non-diagonalizable matrix
  • When approximating eigenvalues, if the dominant pair is complex conjugate, the method will not converge because complex conjugate pair have same modulo (λ 1 , 2 = a ± ib =⇒ |λ 1 | = |λ 2 |) and the Rayleigh quotient continuously oscillates between two values
  • Power method: approximation of the dominant eigenvalue

% Power Method implementation for k = 1: iterations % Normalization v = v / norm ( v ) % Matrix - vector product w = A * v % Rayleigh coefficient for dominant eigenvalue lambda = w ’ * v ; % Reassign variables v = w end

  • Inverse power method: approximation of any eigenvalue Ax = λx Original characteristic equation (A − pI)x = Ax − px = (λ − p)x Shifted matrix eigenvalue equation (A − pI)−^1 x = (^) λ−^1 p x Inversion

% Inverse power method implementation [ L U P ] = lu ( A_shifted ) for k = 1: iterations % Normalization

v = v / norm ( v ) % Solve system using LU factors w = U ( L ( P * v ) ) % Rayleigh coefficient mu = w ’ * v % Reconstruct the dominant eigenvalue lambda = 1/ mu + p % Reassign variables v = w end

  • QR method % QR method implementation for k = 1: iterations [ Q R ] = qr ( A ) A = R * Q end % Eigenvalues are on the main diagonal eigenvalues = diag ( A )
  • SVD method (Singular Value Decomposition) ( AV = U S =⇒ A = U SV T U T^ U = Im, V T^ V = In

Compact matrix form transformation Orthogonality of left (U ) and right (V ) singular vectors

% Compute the full Singular Value Decomposition [U , S , V ] = svd ( A ) ; % S contains the singular values on the diagonal ordered decreasingly singular_values = diag ( S ) ; % Mathematical reconstruction verification A_reconstructed = U * S * V ’;