Skip to content

Commit

Permalink
Update 2024-03-31-julia-ode-func-sys.md
Browse files Browse the repository at this point in the history
  • Loading branch information
sosiristseng authored Dec 17, 2024
1 parent a99d3c6 commit 0a47655
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions docs/blog/posts/julia/2024-03-31-julia-ode-func-sys.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ categories:
```julia
using ModelingToolkit
using DifferentialEquations
using Plots

# Independent (time) and dependent (state) variables (x and RHS)
@variables t x(t) RHS(t)
@independent_variables t
@variables x(t) RHS(t)

# Setting parameters in the modeling
@parameters τ
Expand All @@ -27,14 +27,13 @@ D = Differential(t)
# Equations in MTK use the tilde character (`~`) as equality.
# Every MTK system requires a name. The `@named` macro simply ensures that the symbolic name matches the name in the REPL.

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

sys = structural_simplify(fol_separate)
tend = 2.0
prob = ODEProblem(sys, [x=>0.0], tend, [τ=>1.0])

f = ODEFunction(sys)

f([0.0], [1.0], 0.0) # f(u, p, t) returns the value of D(x)
prob.f([0.0], prob.p, 0.0) # f(u, p, t) returns the value of D(x)
```

0 comments on commit 0a47655

Please sign in to comment.