# example_pkg.grid

*module*

A uniform 1D grid.

[View source](https://github.com/max-models/starlight-theme/blob/devel/src/example_pkg/grid.py#L1-L1)

## example_pkg.grid.Grid

*class* · *dataclass*

```python
class Grid
```

A uniform grid of cells on ``[start, stop]``.

**Attributes**

- `start` (`float`) — Left end of the domain.
- `stop` (`float`) — Right end of the domain.
- `cells` (`int`) — Number of cells.

[View source](https://github.com/max-models/starlight-theme/blob/devel/src/example_pkg/grid.py#L11-L36)

### example_pkg.grid.Grid.cells

*attribute* · *instance attribute*

```python
cells: int
```

[View source](https://github.com/max-models/starlight-theme/blob/devel/src/example_pkg/grid.py#L23-L23)

### example_pkg.grid.Grid.start

*attribute* · *instance attribute*

```python
start: float
```

[View source](https://github.com/max-models/starlight-theme/blob/devel/src/example_pkg/grid.py#L21-L21)

### example_pkg.grid.Grid.stop

*attribute* · *instance attribute*

```python
stop: float
```

[View source](https://github.com/max-models/starlight-theme/blob/devel/src/example_pkg/grid.py#L22-L22)

### example_pkg.grid.Grid.spacing

*property*

```python
spacing: float
```

The cell width $h = (b - a) / n$.

[View source](https://github.com/max-models/starlight-theme/blob/devel/src/example_pkg/grid.py#L26-L28)

### example_pkg.grid.Grid.nodes

*method*

```python
def nodes() -> np.ndarray
```

The ``cells + 1`` cell boundaries.

**Returns**

- (`np.ndarray`) — The node coordinates.

[View source](https://github.com/max-models/starlight-theme/blob/devel/src/example_pkg/grid.py#L30-L36)

## example_pkg.grid.linspace_midpoints

*function*

```python
def linspace_midpoints(start: float, stop: float, cells: int) -> np.ndarray
```

The midpoints of ``cells`` uniform cells on ``[start, stop]``.

**Parameters**

- `start` (`float`) — Left end of the domain.
- `stop` (`float`) — Right end of the domain.
- `cells` (`int`) — Number of cells.

**Returns**

- (`np.ndarray`) — An array of length ``cells``.

[View source](https://github.com/max-models/starlight-theme/blob/devel/src/example_pkg/grid.py#L39-L51)

## example_pkg.grid.midpoint_integral

*function*

```python
def midpoint_integral(f, start: float, stop: float, cells: int) -> float
```

The integral of ``f`` on ``[start, stop]`` by the composite midpoint rule.

**Parameters**

- `f` — The integrand, called on an array of points.
- `start` (`float`) — Left end of the domain.
- `stop` (`float`) — Right end of the domain.
- `cells` (`int`) — Number of cells.

**Returns**

- (`float`) — The approximate integral.

**Numerics**

*rule*

$$
\int_a^b f(x)\,dx \approx h \sum_{i=0}^{n-1} f\left(\frac{x_i + x_{i+1}}{2}\right)
$$

*error*

$$
\left|E\right| \le \frac{(b - a) h^2}{24} \max_{[a, b]} |f''|
$$

Order of accuracy: 2.

Assumptions:

- f twice continuously differentiable on [a, b]

References:

- Süli and Mayers, An Introduction to Numerical Analysis (2003), section 7.2

[View source](https://github.com/max-models/starlight-theme/blob/devel/src/example_pkg/grid.py#L54-L76)
