Shelvean Kapita

Rational Least Squares Approximation

Compute least squares rational approximations for continuous functions on a finite interval using a stable SVD-based solver.
Visualize the approximation, assess errors, detect poles, and export results.

About This Tool

This tool computes the best rational approximation of type $[m/n]$ (numerator degree $m$, denominator degree $n$) to a user-specified continuous function $f(x)$ on a closed interval $[a,b]$ in the discrete least-squares sense.

Given $f \in C[a,b]$, we seek coefficients $p_0,\dots,p_m$ and $q_0,\dots,q_n$ (with $q_0 = 1$ for uniqueness) such that the rational function $$ R(x) = \frac{P(x)}{Q(x)} = \frac{\sum_{k=0}^m p_k x^k}{\sum_{k=0}^n q_k x^k} $$ minimizes the discrete $L^2$ error over a large set of points $x_i \in [a,b]$: $$ \sum_{i} \left( f(x_i) - R(x_i) \right)^2 . $$

This leads to a nonlinear least-squares problem, which is linearized by fixing the denominator scaling and solving $$ \sum_{k=0}^m p_k x_i^k - f(x_i) \sum_{k=1}^n q_k x_i^k = f(x_i) $$ for all sample points $i$. The resulting overdetermined linear system is solved using the singular value decomposition (SVD) for maximum numerical stability—no normal equations are formed.

Optional Tikhonov regularization ($\lambda > 0$) penalizes the denominator coefficients to improve conditioning in near-degenerate cases.

Key features and numerical considerations:

Rational approximations often converge faster than polynomial approximations for functions with poles or steep gradients outside the interval and are particularly effective for many special functions (e.g., exponential, trigonometric, and hyperbolic functions).

Examples