Skip to content

Improve numerical stability of polynomial fitting by replacing normal equations with QR decomposition #7

@gbowne1

Description

@gbowne1

Summary

The current implementation of PolynomialSurface::fit() uses normal equations to solve the least squares problem:

Eigen::VectorXd coeffs = (A.transpose() * A).ldlt().solve(A.transpose() * b);

While this works for well-conditioned data, it can be numerically unstable for poorly distributed or nearly collinear input points.
Suggested Fix

Replace the normal equations with QR decomposition for better numerical stability:

Eigen::VectorXd coeffs = A.colPivHouseholderQr().solve(b);

This change improves robustness without significantly impacting performance.

Impact

  • More accurate results for edge cases

  • Better behavior with noisy or ill-conditioned data

  • This should not require major API changes

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or requestgood first issueGood for newcomershelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions