Mathematics
jetfuelburn.utility.mathematics ¶
_interpolate ¶
_interpolate(x_val, x_list, y_list)
Given two sorted lists of x/y-pairs, performs one-dimensional linear interpolation for a given x-value:
The interpolation is performed using the formula:
\[
y = y_{i-1} + \frac{y_i - y_{i-1}}{x_i - x_{i-1}} \cdot (x_{val} - x_{i-1})
\]
where
\((x_{i-1}, y_{i-1})\) and \((x_i, y_i)\) are the known data points surrounding \(x_{val}\).
See Also
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_val
|
float | int
|
The x value to interpolate for. |
required |
x_list
|
list[float | int]
|
The list of x values (must be sorted). |
required |
y_list
|
list[float | int]
|
The list of y values (corresponding to x_list). |
required |
Returns:
| Type | Description |
|---|---|
float | int
|
The interpolated y value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If x_val is out of bounds of x_list. |
Example
import jetfuelburn
from jetfuelburn.utility.mathematics import _interpolate
_interpolate(
x_val=5,
x_list=[0, 10, 20],
y_list=[0, 100, 200]
)
Source code in jetfuelburn/utility/mathematics.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |