Public API

This page lists exported symbols of CTModels.Utils.


From CTModels.Utils

CTModels.Utils

CTModels.UtilsModule
Utils

Utility 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 data
  • matrix2vec: 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.ctinterpolateFunction
ctinterpolate(x, f) -> Any

Return a linear interpolation function for the data f defined at points x.

This function creates a one-dimensional linear interpolant using the Interpolations.jl package, with linear extrapolation beyond the bounds of x.

Arguments

  • x: A vector of points at which the values f are 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.5:2
julia> f = [0.0, 1.0, 0.0, -1.0, 0.0]
julia> interp = ctinterpolate(x, f)
julia> interp(1.2)

matrix2vec

CTModels.Utils.matrix2vecFunction
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 (1 for rows, 2 for columns). Defaults to 1.

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]]