# Chapter 5 MATLAB-to-Python conversions

This folder contains literal Python conversions of the supplied Chapter 5 MATLAB programs.

## Contents

- `fig5_2L.py`
- `fig5_2R.py`
- `fig5_3.py`
- `fig5_4.py`
- `fig5_5.py`
- `fig5_9.py`
- `fig5_11.py`
- `fig5_12.py`
- `fig5_13.py`
- `fig5_14.py`
- `fig5_15.py`
- `fig5_16.py`
- `fig5_17.py`
- `fig5_18.py`
- `fig5_19.py`
- `fig5_20.py`
- `fig5_21.py`
- `fig5_22.py`
- `fig5_23.py`
- `splineA.py` — Python replacement for the MATLAB `splineA.m` routine
- `hand_nodes.txt` — data used by `fig5_2L.py`

## Conversion conventions

- The MATLAB variable names and loop structure were retained whenever Python syntax allowed.
- MATLAB's reserved or incompatible identifiers were changed minimally. For example, the MATLAB loop variable `in` is written as `in_` because `in` is a Python keyword.
- Plot colors, line styles, line widths, marker styles, marker sizes, axis limits, ticks, labels, legends, and annotations follow the MATLAB files.
- Every explicit font size was reduced by 2 points. For example, MATLAB `FontSize`, 16 becomes Python `fontsize=14`.
- Figure dimensions were converted to practical Matplotlib `figsize` values so the complete plot fits within a normal plot window.
- The custom MATLAB `subaxis` layouts were reproduced with Matplotlib subplots and spacing controls.
- MATLAB's `spline` command is represented by SciPy's default not-a-knot `CubicSpline`.
- The supplied but separate MATLAB `splineA.m` dependency was not included in the upload. The included `splineA.py` implements the behavior used by these examples: a natural cubic spline by default and specified endpoint derivatives when endpoint data are supplied.
- The original comments were retained and adapted to Python comment syntax.

## Installation

From a terminal in this folder, run:

```bash
python3 -m pip install -r requirements.txt
```

## Running a program

For example:

```bash
python3 fig5_14.py
```

or:

```bash
python3 fig5_2L.py
```

Each file can also be imported, and its same-named function can be called from another Python program.

## Notes

- `fig5_5.py` intentionally demonstrates the Runge phenomenon. Large values and loss of accuracy for high-degree equally spaced interpolation are part of the example.
- `fig5_19.py` performs several large interpolation calculations and may take longer than the other files.
- The numerical results that depend on floating-point arithmetic may differ slightly between MATLAB and Python/SciPy.
