-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
30 changed files
with
796 additions
and
378 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
[deps] | ||
DataInterpolations = "82cc6244-b520-54b8-b5a6-8a565e85f1d0" | ||
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" | ||
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" | ||
ModelingToolkitStandardLibrary = "16a59e39-deab-5bd0-87e4-056b12336739" | ||
Optim = "429524aa-4258-5aef-a3af-852621145aeb" | ||
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" | ||
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" | ||
RegularizationTools = "29dad682-9a27-4bc3-9c72-016788665182" | ||
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" | ||
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" | ||
|
||
[compat] | ||
DataInterpolations = "5" | ||
DataInterpolations = "6" | ||
Documenter = "1" | ||
ModelingToolkit = "9" | ||
ModelingToolkitStandardLibrary = "2" | ||
Optim = "1" | ||
OrdinaryDiffEq = "6" | ||
Plots = "1" | ||
RegularizationTools = "0.6" | ||
StableRNGs = "1" | ||
StableRNGs = "1" | ||
Symbolics = "5.29" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Using DataInterpolations.jl with Symbolics.jl and ModelingToolkit.jl | ||
|
||
All interpolation methods can be integrated with [Symbolics.jl](https://symbolics.juliasymbolics.org/stable/) and [ModelingToolkit.jl](https://docs.sciml.ai/ModelingToolkit/stable/) seamlessly. | ||
|
||
## Using with Symbolics.jl | ||
|
||
### Expressions | ||
|
||
```@example symbolics | ||
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 | ||
``` | ||
|
||
### Symbolic Derivatives | ||
|
||
```@example symbolics | ||
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 | ||
``` | ||
|
||
## Using with ModelingToolkit.jl | ||
|
||
Most common use case with [ModelingToolkit.jl](https://docs.sciml.ai/ModelingToolkit/stable/) is to plug in interpolation objects as input functions. This can be done using `TimeVaryingFunction` component of [ModelingToolkitStandardLibrary.jl](https://docs.sciml.ai/ModelingToolkitStandardLibrary/stable/). | ||
|
||
```@example mtk | ||
using DataInterpolations | ||
using ModelingToolkitStandardLibrary.Blocks | ||
using ModelingToolkit | ||
using ModelingToolkit: t_nounits as t, D_nounits as D | ||
using OrdinaryDiffEq | ||
us = [0.0, 1.5, 0.0] | ||
times = [0.0, 0.5, 1.0] | ||
A = LinearInterpolation(us, times) | ||
@named src = TimeVaryingFunction(A) | ||
vars = @variables x(t) out(t) | ||
eqs = [out ~ src.output.u, D(x) ~ 1 + out] | ||
@named sys = ODESystem(eqs, t, vars, []; systems = [src]) | ||
sys = structural_simplify(sys) | ||
prob = ODEProblem(sys, [x => 0.0], (times[1], times[end])) | ||
sol = solve(prob) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.