# example_pkg

*module*

A tiny package, so the example site has an API reference to render.

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

## example_pkg.Drift

*class*

```python
class Drift(Scheme)
```

Bases: `example_pkg.schemes.Scheme`

Re-exported from: `example_pkg.schemes`

Move the position at the current velocity.

**Numerics**

*update*

$$
x^{n+1} = x^n + v^n\,\Delta t
$$

Assumptions:

- velocity constant over the step

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

### example_pkg.Drift.step

*method*

```python
def step(x, v, dt: float, acceleration: Callable) -> tuple
```

Advance the position only.

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

## example_pkg.Grid

*class* · *dataclass*

```python
class Grid
```

Re-exported from: `example_pkg.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.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.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.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.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.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.Kick

*class*

```python
class Kick(Scheme)
```

Bases: `example_pkg.schemes.Scheme`

Re-exported from: `example_pkg.schemes`

Change the velocity by the acceleration at the current position.

**Numerics**

*update*

$$
v^{n+1} = v^n + a(x^n)\,\Delta t
$$

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

### example_pkg.Kick.step

*method*

```python
def step(x, v, dt: float, acceleration: Callable) -> tuple
```

Advance the velocity only.

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

## example_pkg.Leapfrog

*class*

```python
class Leapfrog(Scheme)
```

Bases: `example_pkg.schemes.Scheme`

Re-exported from: `example_pkg.schemes`

Half a kick, a drift and half a kick: the velocity Verlet scheme.

**Numerics**

*half kick*

$$
v^{n+1/2} = v^n + \tfrac{1}{2} a(x^n)\,\Delta t
$$

*drift*

$$
x^{n+1} = x^n + v^{n+1/2}\,\Delta t
$$

*kick*

$$
v^{n+1} = v^{n+1/2} + \tfrac{1}{2} a(x^{n+1})\,\Delta t
$$

*energy*

$$
\left|H(x^n, v^n) - H(x^0, v^0)\right| = \mathcal{O}(\Delta t^2) \quad \text{for all } n
$$

Order of accuracy: x: 2, v: 2.

Assumptions:

- the acceleration depends on the position only

References:

- Hairer, Lubich and Wanner, Geometric Numerical Integration (2006), section I.1.4

Built from:

- `example_pkg.schemes.Kick`
- `example_pkg.schemes.Drift`

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

### example_pkg.Leapfrog.run

*method*

```python
def run(x, v, dt: float, steps: int, acceleration: Callable) -> np.ndarray
```

Take ``steps`` steps and return the positions, ``(steps + 1,)``.

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

### example_pkg.Leapfrog.step

*method*

```python
def step(x, v, dt: float, acceleration: Callable) -> tuple
```

Advance ``(x, v)`` by one leapfrog step.

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

## example_pkg.linspace_midpoints

*function*

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

Re-exported from: `example_pkg.grid`

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.midpoint_integral

*function*

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

Re-exported from: `example_pkg.grid`

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)

**Modules**

- `example_pkg.grid`
- `example_pkg.schemes`
