@@ -4,6 +4,13 @@ using Reexport
44@reexport using DiffEqBase
55using MATLAB, ModelingToolkit
66
7+ # Handle ModelingToolkit API changes: states -> unknowns
8+ if isdefined (ModelingToolkit, :unknowns )
9+ const mtk_states = ModelingToolkit. unknowns
10+ else
11+ const mtk_states = ModelingToolkit. states
12+ end
13+
714abstract type MATLABAlgorithm <: DiffEqBase.AbstractODEAlgorithm end
815struct ode23 <: MATLABAlgorithm end
916struct ode45 <: MATLABAlgorithm end
@@ -57,7 +64,7 @@ function DiffEqBase.__solve(
5764
5865 matstr = ModelingToolkit. build_function (
5966 map (x -> x. rhs, equations (sys)),
60- states (sys),
67+ mtk_states (sys),
6168 parameters (sys),
6269 independent_variables (sys)[1 ],
6370 target = ModelingToolkit. MATLABTarget ()
@@ -70,6 +77,11 @@ function DiffEqBase.__solve(
7077 put_variable (get_default_msession (), :reltol , reltol)
7178 put_variable (get_default_msession (), :abstol , abstol)
7279
80+ # Define the ifelse helper function in MATLAB
81+ # MATLAB doesn't have a built-in ifelse, so we need to define one
82+ # This allows symbolic ifelse expressions to be evaluated properly
83+ eval_string (" ifelse = @(cond, a, b) cond .* a + ~cond .* b;" )
84+
7385 # Send the function over
7486 eval_string (matstr)
7587
0 commit comments