This project implements a closed-form solution to the least squares approximation problem, applied to the function
-
Closed-Form Solutions: Effective when the design matrix
$A$ is of moderate size and well-conditioned, allowing efficient direct computation with factorization techniques. -
Iterative Solutions (e.g., Gradient Descent): Preferable for very large systems where matrix factorization is computationally prohibitive, or when data is sparse and iterative refinement provides a faster path to convergence without requiring full decomposition of
$A$ .
Given data points
where
-
Modified Gram-Schmidt (MGS)
Solves$A c = f$ using QR Factorization via Modified Gram-Schmidt. Here,$A = QR$ where$Q$ is orthogonal, and$R$ is upper triangular. The back-substitution is implemented for solving the system$Rc = Q^T f$ . -
Householder Transformation (HHT)
Uses Householder reflections to obtain an orthogonal factor$Q$ and an upper triangular$R$ such that$A = QR$ . The system is then solved by back-substitution. -
Singular Value Decomposition (SVD)
Using SVD,$A$ is decomposed as$A = U \Sigma V^T$ . The least squares solution is obtained by solving the system with$\Sigma$ and$V$ . -
Normal Equations
Using normal equations, we solve$A^T A c = A^T f$ , which is computed directly with MATLAB’s backslash operator ($\backslash$ ).
We evaluate the least squares error for each method:
The observed errors and stability properties are summarized below:
-
MGS: Moderate accuracy; prone to instability due to loss of orthogonality in
$Q$ . - Householder: High accuracy; stable due to robust orthogonalization.
- SVD: High accuracy and stability, though computationally intensive.
-
Normal Equations: Lowest accuracy; unstable for ill-conditioned problems due to squaring of the condition number
$\kappa(A)^2$ .
The stability and accuracy of each method were measured by comparing the predicted coefficients and relative errors. The SVD and Householder methods yielded the best approximations, with stability preserved by their orthogonalization properties. Normal Equations showed significant instability due to amplified rounding errors in
Method | Least Squares Error |
---|---|
Modified Gram-Schmidt | |
Householder | |
SVD | |
Normal Equations |
For simplicity, we are going to compare the coefficient of
Method | Relative Error (Coefficient of |
---|---|
Modified Gram-Schmidt | |
Householder | |
SVD | |
Normal Equations |
Table 1: Relative error for
Condition Component | ||
---|---|---|
Table 2: Condition numbers of
At first glance, the observed relative error growth seems problematic, but this can be explained with the following arguments (with machine epsilon
-
Modified Gram-Schmidt (MGS):
The rounding error is on the order of$10^{-3}$ , indicating an amplification of$10^{13}$ , which greatly exceeds the condition number of the matrix. This error results from instability in the Modified Gram-Schmidt process, which often fails to produce a perfectly orthonormal$Q$ , adversely affecting the algorithm's accuracy. Therefore, MGS is UNSTABLE. -
Householder Transformation (HHT):
The rounding error here is around$10^{-9}$ , suggesting amplification by$10^7$ . Given that the condition number of$x$ with respect to perturbations in$A$ is approximately$3 \times 10^8$ , the inaccuracy in the$x^{14}$ coefficient can be entirely attributed to ill-conditioning, not instability. Thus, HHT is STABLE. -
Singular Value Decomposition (SVD):
The SVD method yields similar results to Householder; the observed error can be attributed to the condition number of the system, indicating that SVD is also STABLE. -
Normal Equations:
The error growth here is on the order of$10^{16}$ , explained by the squared condition number$\kappa(A)^2 \approx 10^{16}$ , which amplifies the error significantly. This behavior aligns with the theoretical result:$$\frac{| \tilde{x} - x |}{| x |} = O \left[( \kappa(A) + \kappa(A)^2 \frac{\tan\theta}{\eta} ) \epsilon_m\right]$$ Depending on
$\theta$ and$\eta$ ,$\frac{| \tilde{x} - x |}{| x |}$ could be either$\kappa(A)^2$ or$\kappa(A)$ . Thus, Normal Equations are typically UNSTABLE for ill-conditioned problems with close fits.