# Chapter 2 MATLAB-to-Python conversions

This folder contains literal Python conversions of the supplied MATLAB files.
The original variable names, comments, numerical procedures, plotting colors,
markers, line styles, line widths, axis limits, ticks, labels, and legend
positions were retained where Matplotlib provides an equivalent.

## Font-size adjustment

Every explicit MATLAB font size was reduced by 2 in the Python version. For
example, `FontSize`, 16 became `fontsize=14`, 14 became 12, 18 became 16, and
20 became 18.

## Plot sizing

Each plot uses the original MATLAB pixel dimensions, converted to Matplotlib
inches at 100 dpi. `constrained_layout=True` is used so labels, legends, and
tick text remain inside the plot window.

## Files

- `fig2_3.py`
- `fig2_8.py`
- `fig2_9.py`
- `fig2_10.py`
- `fig2_11.py`
- `fig2_13.py`
- `fig2_14.py`
- `fig2_15.py`
- `fig2_16.py`
- `fig2_20.py`
- `newton.py`
- `secant.py`
- `table2_2.py`
- `table2_3.py`
- `table2_5.py`
- `table2_6.py`
- `table2_9.py`
- `splineA.py`

`fig2_14.py` and `fig2_15.py` import the supplied spline routine from
`splineA.py`, so keep these files in the same directory.

## Installation

Open Terminal, change to this directory, and install the dependencies:

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

## Running a program

For example:

```bash
python3 fig2_3.py
python3 fig2_14.py
python3 newton.py
python3 table2_2.py
```

The figure programs open Matplotlib windows. The table and iterative-method
programs print their results in Terminal. `table2_2.py` both prints a table and
opens a figure.

## Notes on the literal conversion

- MATLAB uses one-based array indexing; Python uses zero-based indexing. The
  index expressions were adjusted while retaining the original variable names.
- MATLAB `subaxis` calls were replaced by Matplotlib constrained layout, so the
  plots fit their windows without requiring `subaxis.m` or `parseArgs.m`.
- MATLAB's default axes color order is represented with the same RGB values.
- The right second-derivative branch in `splineA.py` deliberately preserves the
  original MATLAB use of `Ders(1)` as a literal conversion.
