This interactive calculator computes the least-squares polynomial approximation of user-specified degree (up to 50) for either discrete data points or continuous functions over an interval $[a,b]$.
Discrete points (including uploaded CSV/TXT/XLSX/ODS files):
- Constructs the Vandermonde matrix $V$.
- Uses stable Householder QR decomposition to solve the overdetermined system $Vp = y$ (no normal equations).
- Numerically robust even for high degrees or poorly spaced points.
Continuous functions $f(x)$ on $[a,b]$:
- Finds the orthogonal projection of $f$ onto the space of polynomials of degree $\leq n$ with respect to the unweighted $L^2([a,b])$ inner product.
- Employs Legendre polynomials $P_k(x)$ (Jacobi polynomials with $\alpha=\beta=0$) as an orthogonal basis.
- Coefficients computed directly via high-order composite Gauss–Legendre quadrature (no matrix formation or normal equations).
- Legendre coefficients converted to monomial basis for display and evaluation.
- Extremely stable for high degrees (up to 50) and arbitrary intervals.
Features:
- Interactive D3 visualization with data points, fitted polynomial, and original function.
- Relative and absolute $\|f-p\|_{L^2}$, $\|f-p\|_{L^1}$, $\|f-p\|_{L^\infty}$ error norms (for continuous case).
- Polynomial evaluation at arbitrary points.
- PNG plot download.
- Export fitted polynomial in LaTeX, Python, NumPy, or MATLAB format.
- All methods avoid ill-conditioned normal equations for maximum numerical stability.