maths pack¶
33 nodes, in noodlelab[maths] and above.
Math/Arrays¶
Add Noise¶
maths.add_noise
Add Gaussian noise. A fixed seed keeps runs reproducible (and cacheable).
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
Default |
|
|
Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
Apply Function¶
maths.apply_function
Apply a common function element-wise.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
Array Math¶
maths.array_math
Element-wise math between an array and a scalar or another array.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
Default |
|
|
Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
Clip Values¶
maths.clip_values
Limit values to [minimum, maximum].
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
Default |
|
|
Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
Cumulative Sum¶
maths.cumulative_sum
Running total of an array (NaNs count as zero).
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
Linspace¶
maths.linspace
Evenly spaced numbers over an interval.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
Default |
|
|
Default |
|
|
Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
Math/Calculus¶
Derivative¶
maths.derivative
dy/dx by central differences (numpy.gradient), for uneven spacing too.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
Integrate¶
maths.integrate
The area under y(x) by the trapezoidal rule, and its running total (e.g. rainfall rate to accumulated rain, velocity to distance).
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
Interpolate¶
maths.interpolate
Values of y at new positions: resample onto another grid, or fill gaps. Positions outside the data give NaN.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
Math/Complex¶
Complex Parts¶
maths.complex_parts
The parts of a complex number or array: real and imag,
magnitude |z| and phase arg z (in radians, from −π to π), and
the conjugate. Each keeps the value’s unit, except the phase. A real
value gives itself, an imaginary part of 0 and a phase of 0 or π.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
A complex number or array, with a unit or without: 3+4j ohm Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Math/Fitting¶
Curve Fit¶
maths.curve_fit
Non-linear least squares fit of a standard model (scipy.optimize.curve_fit).
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
|
|
|
Default |
|
|
Starting values, comma-separated; empty: estimated from the data Default |
|
|
Optional. |
|
|
Default |
|
|
Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Inverse Prediction¶
maths.inverse_prediction
Calibration: fit the standards (x = known amount, y = signal) with a straight line, then estimate the amount in each sample from its signal.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
The measured signal column Default |
|
|
Readings per sample Default |
|
|
Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
Linear Regression¶
maths.linear_regression
Ordinary least squares y = slope·x + intercept, with standard errors,
R², the p-value of the slope and the residual standard deviation. Pairs
with a NaN are left out. through_origin fixes the intercept at zero.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
Numbers, or a quantity holding them (a column with a unit) |
|
|
Numbers, or a quantity holding them (a column with a unit) |
|
|
Default |
|
|
Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Polynomial Fit¶
maths.polynomial_fit
Least-squares polynomial fit, highest power first. Pairs with a NaN
are left out; fitted has a value for every x.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
|
|
|
Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
|
|
|
Statistics¶
maths.statistics
Summary statistics of an array, ignoring NaNs: mean, standard
deviation, minimum, maximum, sum (total) and the number of values.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Math/Fourier¶
Fourier Transform¶
maths.fourier_transform
The frequencies in a signal, with the discrete Fourier transform
(NumPy’s FFT). amplitude is in the signal’s unit, scaled so that a
sine of amplitude a reads a at its frequency (with a window, exactly so
only at a bin; flattop reads amplitudes best, hann separates peaks best).
spectrum is the complex DFT itself, for Inverse Fourier Transform.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
Evenly sampled values: an array, or a quantity holding one |
|
|
When each sample was taken, evenly spaced; else use sample_spacing Optional. |
|
|
Time (or distance) between samples, when time is not linked Default |
|
|
Tapers the ends against leakage; none for an exact inverse Default |
|
|
Taken off before transforming Default |
|
|
Pad with zeros to this many times the length Default |
|
|
One-sided: frequencies from 0 (real signals); two-sided: ± Default |
|
|
amplitude: a sine of amplitude a reads a; rms: a/√2; raw: |DFT| Default |
|
|
How many peaks to find Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Inverse Fourier Transform¶
maths.inverse_fourier_transform
The signal back from its complex spectrum (the spectrum of Fourier
Transform, perhaps filtered on the way). One-sided or two-sided is told
from the frequencies. The round trip is exact with window none and
detrend none; otherwise the result is the windowed, detrended signal.
With a one-sided spectrum of an odd-length signal, give samples.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
|
|
|
Length of the signal; 0: from the spectrum Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
|
|
|
Power Spectrum¶
maths.power_spectrum
How the power of a signal is spread over frequency: its power spectral
density (unit² per Hz), or with spectrum scaling the power of each
tone (unit²). rms is the signal’s root mean square about its mean,
from the whole spectrum (Parseval).
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
Evenly sampled values: an array, or a quantity holding one |
|
|
When each sample was taken, evenly spaced; else use sample_spacing Optional. |
|
|
Time (or distance) between samples, when time is not linked Default |
|
|
welch: averaged over overlapping segments, less noisy Default |
|
|
Default |
|
|
Welch: samples per segment (finer frequency: longer) Default |
|
|
density: power per Hz (noise); spectrum: power per peak (tones) Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Math/Matrices¶
Determinant¶
maths.determinant
The determinant, in the matrix’s unit to the power of its size. Zero means the matrix is singular: its equations are not independent.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
A matrix: a quantity holding a 2-D array (one unit for every entry), or plain numbers |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
Diagonal Matrix¶
maths.diagonal_matrix
A matrix with diagonal on its diagonal and zeros elsewhere, such as
the mass matrix of masses on springs. A linked vector replaces the text.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
The diagonal, comma separated: 1, 1 Default |
|
|
One unit for every entry; empty: plain numbers Default |
|
|
A vector for the diagonal, instead of the text (and its unit) Optional. |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
Eigenvalues¶
maths.eigenvalues
The eigenvalues λ and eigenvectors v of A (A v = λ v), or of A against B
(A v = λ B v). λ is in A’s unit over B’s. Column j of vectors belongs
to value j, scaled to length 1.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
A matrix: a quantity holding a 2-D array (one unit for every entry), or plain numbers |
|
|
For the generalized problem A v = λ B v, such as K v = ω² M v Optional. |
|
|
Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Element¶
maths.element
One entry of a matrix or vector, with its unit. Rows and columns are numbered from 1, so row 2 of a solution vector is x2. An entry of a complex matrix is complex.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
A matrix: a quantity holding a 2-D array (one unit for every entry), or plain numbers |
|
|
Numbered from 1 Default |
|
|
Numbered from 1; 1 for a vector Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
Identity Matrix¶
maths.identity_matrix
The identity matrix: ones on the diagonal, zeros elsewhere.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
Default |
|
|
One unit for every entry; empty: plain numbers Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
Inverse¶
maths.inverse
The inverse A⁻¹, in the reciprocal unit: the inverse of a stiffness matrix (N/m) is a flexibility matrix (m/N). To solve A x = b, Solve Linear System is more accurate than multiplying by the inverse.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
A matrix: a quantity holding a 2-D array (one unit for every entry), or plain numbers |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
Matrix¶
maths.matrix
A matrix typed as text, MATLAB style: 2, -1; -1, 2 is a 2×2 matrix,
10; 0 a column. Every entry has the one unit.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
Rows end at ; or a new line, entries are separated by commas or spaces: 2, -1; -1, 2 Default |
|
|
One unit for every entry; empty: plain numbers Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
Matrix Multiply¶
maths.matrix_multiply
The matrix product A B, with the units multiplied too: a stiffness matrix times a displacement vector is a force vector. A vector counts as a column. For element-by-element products use Quantity Math.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
A matrix: a quantity holding a 2-D array (one unit for every entry), or plain numbers |
|
|
A matrix: a quantity holding a 2-D array (one unit for every entry), or plain numbers |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
Natural Frequencies¶
maths.natural_frequencies
The natural frequencies and mode shapes of an undamped system of
masses and springs, from its stiffness matrix K and mass matrix M: the
solutions of K φ = ω² M φ. Frequencies are in ascending order, and column
j of shapes is mode j, the way the masses move at that frequency.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
A matrix: a quantity holding a 2-D array (one unit for every entry), or plain numbers |
|
|
A matrix: a quantity holding a 2-D array (one unit for every entry), or plain numbers |
|
|
Scale each mode shape so its largest entry is 1, or so φᵀ M φ = 1 Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Solve Linear System¶
maths.solve_linear
Solve A x = b for x, such as K x = F for the displacements of a structure. x is in b’s unit over A’s (N over N/m is m), and has b’s shape.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
A matrix: a quantity holding a 2-D array (one unit for every entry), or plain numbers |
|
|
A matrix: a quantity holding a 2-D array (one unit for every entry), or plain numbers |
|
|
Unit of x; empty: b’s unit over A’s Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Transpose¶
maths.transpose
Rows become columns. A vector (a column) becomes a row, 1×n.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
A matrix: a quantity holding a 2-D array (one unit for every entry), or plain numbers |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
Math/Plot¶
Heatmap¶
maths.heatmap
A matrix as coloured cells, such as a correlation matrix. A first text column names the rows; the other columns must be numeric.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
Default |
|
|
Default |
|
|
Centre the colours on zero (for correlations, anomalies) Default |
|
|
Default |
|
|
Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
Histogram Plot¶
maths.histogram_plot
Distribution of values, optionally with the normal curve of the same mean and standard deviation for comparison.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
Default |
|
|
Overlay a normal distribution Default |
|
|
Default |
|
|
Default |
|
|
Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
XY Plot¶
maths.xy_plot
Plot y (and optionally y2, e.g. a fitted curve or marked peaks) against x.
A y with uncertainties gets error bars of ±u unless error is linked.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
|
|
|
Optional. |
|
|
x for y2, if it differs from x Optional. |
|
|
Error bars for y Optional. |
|
|
Default |
|
|
Default |
|
|
Default |
|
|
Default |
|
|
Default |
|
|
Default |
|
|
Default |
|
|
Default |
|
|
markers: e.g. to mark peaks on y Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|
Output¶
Save Figure¶
maths.save_figure
Write a figure into this run’s output folder. The extension picks the format: .png, .svg or .pdf.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
|
|
|
Default |
|
|
Default |
Outputs
Name |
Type |
Description |
|---|---|---|
|
|