```julia
using ModelingToolkit
using DifferentialEquations
using Plots
```

# Simplified Example


```julia
@variables t x(t) RHS(t) 
@parameters τ
```




\begin{equation}
\left[
\begin{array}{c}
\tau \\
\end{array}
\right]
\end{equation}





```julia
D = Differential(t) # define differentiation operator w.r.t. time
```




    (::Differential) (generic function with 2 methods)




```julia
@named fol_separate = ODESystem([
        RHS ~ (1-x)/τ, 
        D(x) ~ RHS
        ])
```




\begin{align}
\frac{dx(t)}{dt} =& \mathrm{RHS}\left( t \right) \\
\mathrm{RHS}\left( t \right) =& \frac{1 - x\left( t \right)}{\tau}
\end{align}





```julia
prob = ODEProblem(
    structural_simplify(fol_separate),
    [x => 0.0],
    (0.0, 10.0),
    [τ => 3.0]
)

sol = solve(prob) 

plot(sol, vars=[x, RHS])
```




    

    



# Registering Functions 

What if we want to embed data as a forcing function? MTK allows us to register functions that are excluded from symbolic transformations. That way you could interpolate a time series for example. 


```julia
value_vector = randn(10) 
f_fun(t) = t >= 10 ? value_vector[end] : value_vector[Int(floor(t))+1]

@register_symbolic f_fun(t)
```


```julia
@variables f(t) 

@named fol_external_f = ODESystem([
        f ~ f_fun(t), 
        D(x) ~ (f-x)/τ
        ])
```




\begin{align}
\frac{dx(t)}{dt} =& \frac{ - x\left( t \right) + f\left( t \right)}{\tau} \\
f\left( t \right) =& \mathrm{f\_fun}\left( t \right)
\end{align}





```julia
prob = ODEProblem(structural_simplify(fol_external_f), [x=>0.0], (0.0,10.0), [τ=>0.75])
sol = solve(prob) 

plot(sol, vars=[x, f])
```




    

    




```julia

```

4644aed38b432da890bcf5bd33994ab8c68a82a1
ipynb
Jupyter Notebook
notebooks/Symbolic Modeling Tutorials.ipynb
john-waczak/DataAssimilation.jl
2bb7cfe23405bc5d4cfb79da78e70da1e0b04ded
MIT
notebooks/Symbolic Modeling Tutorials.ipynb
john-waczak/DataAssimilation.jl
2bb7cfe23405bc5d4cfb79da78e70da1e0b04ded
MIT
notebooks/Symbolic Modeling Tutorials.ipynb
john-waczak/DataAssimilation.jl
2bb7cfe23405bc5d4cfb79da78e70da1e0b04ded
MIT
Qwen/Qwen-72B
1. YES
2. YES