Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
[compat]
DiffEqBase = "6.122"
MATLAB = "0.8"
ModelingToolkit = "8"
ModelingToolkit = "8, 9, 10, 11"
Reexport = "0.2, 1.0"
julia = "1.6"

Expand Down
14 changes: 13 additions & 1 deletion src/MATLABDiffEq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ using Reexport
@reexport using DiffEqBase
using MATLAB, ModelingToolkit

# Handle ModelingToolkit API changes: states -> unknowns
if isdefined(ModelingToolkit, :unknowns)
const mtk_states = ModelingToolkit.unknowns
else
const mtk_states = ModelingToolkit.states
end

abstract type MATLABAlgorithm <: DiffEqBase.AbstractODEAlgorithm end
struct ode23 <: MATLABAlgorithm end
struct ode45 <: MATLABAlgorithm end
Expand Down Expand Up @@ -57,7 +64,7 @@ function DiffEqBase.__solve(

matstr = ModelingToolkit.build_function(
map(x -> x.rhs, equations(sys)),
states(sys),
mtk_states(sys),
parameters(sys),
independent_variables(sys)[1],
target = ModelingToolkit.MATLABTarget()
Expand All @@ -70,6 +77,11 @@ function DiffEqBase.__solve(
put_variable(get_default_msession(), :reltol, reltol)
put_variable(get_default_msession(), :abstol, abstol)

# Define the ifelse helper function in MATLAB
# MATLAB doesn't have a built-in ifelse, so we need to define one
# This allows symbolic ifelse expressions to be evaluated properly
eval_string("ifelse = @(cond, a, b) cond .* a + ~cond .* b;")

# Send the function over
eval_string(matstr)

Expand Down
Loading