A Python project implementing and comparing two numerical interpolation methods on elevation profile data: Lagrange interpolation and cubic spline interpolation.
The program visualizes both methods across three datasets with distinct characteristics:
| File | Description |
|---|---|
genoa_rapallo.txt |
Large, frequent elevation oscillations |
Obiadek.csv |
Two sharp spikes with small fluctuations |
chelm.txt |
Smooth, gradual changes |
Each dataset contains 512 (distance, elevation) point pairs.
A global method — constructs a single polynomial passing through all selected nodes. Simple to implement, but susceptible to the Runge effect at higher node counts. Tested configurations:
- Evenly spaced nodes: 6, 9, 12, 15, 18, 21
- Chebyshev nodes (improved stability): 60, 100
A local method — connects neighboring nodes with third-degree polynomials while enforcing continuity of the first and second derivatives. Immune to the Runge effect and highly scalable. Tested node counts: 6, 10, 20, 30, 50, 100
- Lagrange with 100 nodes for
genoa_rapallo— Runge effect demonstration - Lagrange (6–21 nodes) for each of the three profiles
- Lagrange with Chebyshev nodes (60 and 100 nodes) for each profile
- Cubic spline (6–100 nodes) for each profile
- Python 3.x
- numpy
- pandas
- matplotlib
python3 -m venv venvLinux / macOS:
source venv/bin/activate
pip3 install -r requirements.txtWindows:
.\venv\Scripts\activate
pip install -r requirements.txtLinux / macOS:
python3 main.pyWindows:
py main.pyLagrange interpolation works well for smooth, simple functions — especially when combined with Chebyshev nodes. For highly oscillatory data, cubic spline interpolation is the clear winner: it produces no Runge effect and maintains accuracy regardless of the number of nodes.