Skip to content

Commit 0a71d7f

Browse files
Merge pull request SciML#54 from ChrisRackauckas-Claude/fix-issue-36-ifelse
Fix ifelse support and update ModelingToolkit compat
2 parents b7036d5 + 056d91e commit 0a71d7f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1111
[compat]
1212
DiffEqBase = "6.122"
1313
MATLAB = "0.8"
14-
ModelingToolkit = "8"
14+
ModelingToolkit = "8, 9, 10, 11"
1515
Reexport = "0.2, 1.0"
1616
julia = "1.6"
1717

src/MATLABDiffEq.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ using Reexport
44
@reexport using DiffEqBase
55
using 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+
714
abstract type MATLABAlgorithm <: DiffEqBase.AbstractODEAlgorithm end
815
struct ode23 <: MATLABAlgorithm end
916
struct 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

Comments
 (0)