Public API
This page lists exported symbols of CTModels.Utils.
From CTModels.Utils
CTModels.Utils
CTModels.Utils — Module
UtilsUtility functions module for CTModels.
This module provides general-purpose utility functions used throughout CTModels, including interpolation, matrix operations, and function transformations.
Public API
The following functions are exported and accessible as CTModels.function_name():
ctinterpolate: Linear interpolation for datactinterpolate_constant: Piecewise-constant interpolation for datamatrix2vec: Convert matrices to vectors
Private API
The following are internal utilities (accessible via Utils.function_name):
to_out_of_place: Convert in-place functions to out-of-place@ensure: Validation macro for preconditions
See also: CTModels
ctinterpolate
CTModels.Utils.ctinterpolate — Function
ctinterpolate(
x,
f
) -> CTModels.Utils.var"#linear_interp#ctinterpolate##0"
Return a linear interpolation function for the data f defined at points x.
This function creates a one-dimensional linear interpolant with flat extrapolation beyond the bounds of x (returns f[1] for t < x[1] and f[end] for t >= x[end]).
Arguments
x: A vector of points at which the valuesfare defined.f: A vector of values to interpolate.
Returns
A callable interpolation object that can be evaluated at new points.
Example
julia> x = [0.0, 1.0, 2.0]
julia> f = [1.0, 2.0, 3.0]
julia> interp = ctinterpolate(x, f)
julia> interp(0.5) # Returns 1.5 (linear interpolation)
julia> interp(-1.0) # Returns 1.0 (flat extrapolation)
julia> interp(3.0) # Returns 3.0 (flat extrapolation)ctinterpolate_constant
CTModels.Utils.ctinterpolate_constant — Function
ctinterpolate_constant(
x,
f
) -> CTModels.Utils.var"#steppost_interp#ctinterpolate_constant##0"
Return a piecewise-constant interpolation function for the data f defined at points x.
This function creates a right-continuous piecewise constant interpolant: the value at knot x[i] is held constant on the interval [x[i], x[i+1}).
This implements the standard steppost behavior for optimal control:
u(t_i) = u_i(value at the knot)u(t) = u_ifor allt ∈ [t_i, t_{i+1})- Right-continuous:
lim_{t→t_i^+} u(t) = u(t_i)
Arguments
x: A vector of points at which the valuesfare defined.f: A vector of values to interpolate.
Returns
A callable interpolation object that can be evaluated at new points.
Example
julia> x = [0.0, 1.0, 2.0]
julia> f = [1.0, 2.0, 3.0]
julia> interp = ctinterpolate_constant(x, f)
julia> interp(0.0) # Returns 1.0 (value at x[1])
julia> interp(0.5) # Returns 1.0 (held from x[1] on [0.0, 1.0))
julia> interp(1.0) # Returns 2.0 (value at x[2], right-continuous)
julia> interp(1.5) # Returns 2.0 (held from x[2] on [1.0, 2.0))matrix2vec
CTModels.Utils.matrix2vec — Function
matrix2vec(A::Matrix{<:Real}) -> Vector{<:Vector{<:Real}}
matrix2vec(
A::Matrix{<:Real},
dim::Int64
) -> Vector{<:Vector{<:Real}}
Transform a matrix into a vector of vectors along the specified dimension.
Each row or column of the matrix A is extracted and stored as an individual vector, depending on dim.
Arguments
A: A matrix of elements of type<:ctNumber.dim: The dimension along which to split the matrix (1for rows,2for columns). Defaults to1.
Returns
A Vector of Vectors extracted from the rows or columns of A.
Note
This is useful when data needs to be represented as a sequence of state or control vectors in optimal control problems.
Example
julia> A = [1 2 3; 4 5 6]
julia> matrix2vec(A, 1) # splits into rows: [[1, 2, 3], [4, 5, 6]]
julia> matrix2vec(A, 2) # splits into columns: [[1, 4], [2, 5], [3, 6]]