This repository studies how mathematically equivalent-looking approximations of sin(x) behave under finite-precision arithmetic. The project question is: how accurately and efficiently can sine be approximated when algorithm design, range reduction, basis choice, and floating-point effects are all considered? MATLAB's built-in sin is the practical reference implementation; this project does not claim to replace it.
| Method | Main idea |
|---|---|
| Direct Taylor | Explicit powers and factorials as a transparent baseline. |
| Recurrence Taylor | Reuses consecutive terms to avoid repeated powers and factorials. |
| Reduced Taylor | Reduces arguments to approximately [-pi/4, pi/4] and reconstructs by quadrant symmetry. |
| Chebyshev | Computes interval-specific coefficients from Chebyshev nodes. |
| Clenshaw | Evaluates Chebyshev expansions by backward recurrence. |
The numerical routines validate finite real inputs and evaluate them in MATLAB double precision; compatible numeric inputs may be converted to double by MATLAB argument validation. The simple range reducer is intended for moderate arguments, not arbitrary huge arguments or correctly rounded argument reduction.
The study connects Taylor remainder bounds, interval approximation, cancellation, range reduction, recurrence evaluation, Clenshaw evaluation, machine spacing, unit roundoff u = eps/2, and accuracy–runtime trade-offs. Safeguarded relative error near a zero of sine is reported separately from ordinary relative error because its denominator is max(abs(reference),eps).
src/+numapprox: reusable numerical algorithms.tests:matlab.unittesttests, including invalid-input and shape tests.experiments: convergence, range-reduction, Chebyshev, and floating-point studies.benchmarks: degree-sweep accuracy/runtime benchmark.report: technical study.results/raw: generated machine-specific outputs.results/reference: selected outputs suitable for review after real execution.results/figures: generated plots..github/workflows: MATLAB test and reproduction workflows.
From the repository root in MATLAB:
addpath('src');
results = runtests('tests', 'IncludeSubfolders', true);
assert(all([results.Passed]), 'One or more tests failed.');The tests cover zero, positive and negative inputs, row/column/matrix shapes, odd symmetry, degree handling, range-reduction boundaries, invalid intervals, non-finite inputs, Chebyshev coefficient sizes, known Chebyshev polynomials, Clenshaw, error metrics, and Taylor remainder bounds.
generateAllFigures is a function, so add its directory and call it directly:
addpath('src');
addpath('experiments');
generateAllFigures;This generates raw CSV files, selected reference CSV summaries, and PNG figures under results/. It also runs the benchmark degree sweep. The workflow can run the same entry point on demand and uploads the generated files as an artifact; it does not commit generated files automatically.
VERIFIED MATLAB EXECUTION. The test suite and full reproduction pipeline completed successfully in GitHub Actions on MATLAB R2026a Update 5 (GLNXA64). Selected generated CSV summaries are committed under results/reference/, and reviewed figures are committed under results/figures/.
Observed reference results include:
- Taylor recurrence convergence minima of approximately
1.39e-17atx=0.1, exact agreement at double precision for the testedx=1case,5.55e-17atx=3, and5.44e-15atx=7. - On
[-pi,pi], degree-17 Chebyshev approximation achieved maximum absolute error of approximately1.56e-13. - Range-reduced Taylor reached near machine-precision maximum error on the benchmark grid by degree 15.
Runtime measurements are environment-specific. Chebyshev benchmark timings exclude coefficient construction and measure evaluation using precomputed coefficients.
The range reducer uses nearest-integer arithmetic with MATLAB's pi and is documented only for moderate arguments. Chebyshev coefficients are interval-specific and are not intended for extrapolation. Runtime depends on MATLAB release, hardware, JIT warm-up, and vector size. The experiment scripts are evidence-generation tools, not production replacements for MATLAB's numerical library.
MIT. See LICENSE.