Using DataInterpolations.jl with Symbolics.jl and ModelingToolkit.jl

All interpolation methods can be integrated with Symbolics.jl and ModelingToolkit.jl seamlessly.

Using with Symbolics.jl

Expressions

using DataInterpolations, Symbolics
using Test

u = [0.0, 1.5, 0.0]
t = [0.0, 0.5, 1.0]
A = LinearInterpolation(u, t)

@variables τ

# Simple Expression
ex = cos(τ) * A(τ)
@test substitute(ex, Dict(τ => 0.5)) == cos(0.5) * A(0.5) # true
Test Passed

Symbolic Derivatives

D = Differential(τ)

ex1 = A(τ)

# Derivative of interpolation
ex2 = expand_derivatives(D(ex1))

@test substitute(ex2, Dict(τ => 0.5)) == DataInterpolations.derivative(A, 0.5) # true

# Higher Order Derivatives
ex3 = expand_derivatives(D(D(A(τ))))

@test substitute(ex3, Dict(τ => 0.5)) == DataInterpolations.derivative(A, 0.5, 2) # true
Test Passed

Using with ModelingToolkit.jl

We recommend using the ModelingToolkitStandardLibrary Interpolation Blocks in order to use DataInterpolations.jl in MTK models.