Skip to content

Commit 580aa6d

Browse files
Merge pull request #680 from SciML/myb/fixes
Various fixes and scalar linear solve
2 parents 2d657f7 + c7d62c3 commit 580aa6d

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ModelingToolkit"
22
uuid = "961ee093-0014-501f-94e3-6117800e7a78"
33
authors = ["Chris Rackauckas <[email protected]>"]
4-
version = "4.0.9"
4+
version = "4.1.0"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"

src/linearity.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ for f in monadic_nonlinear
2727
end
2828

2929
# 2-arg
30-
for f in [+, rem2pi, -, >, isless, <, isequal, max, min, convert]
30+
for f in [+, rem2pi, -, >, isless, <, isequal, max, min, convert, <=, >=]
3131
linearity_known_2[f] = true
3232
linearity_map_2[f] = (true, true, true)
3333
end

src/solve.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ end
4545
# return the coefficient matrix `A` and a
4646
# vector of constants (possibly symbolic) `b` such that
4747
# A \ b will solve the equations for the vars
48-
function A_b(eqs, vars)
48+
function A_b(eqs::AbstractArray, vars::AbstractArray)
4949
exprs = rhss(eqs) .- lhss(eqs)
5050
for ex in exprs
5151
@assert islinear(ex, vars)
@@ -54,6 +54,13 @@ function A_b(eqs, vars)
5454
b = A * vars - exprs
5555
A, b
5656
end
57+
function A_b(eq, var)
58+
ex = eq.rhs - eq.lhs
59+
@assert islinear(ex, [var])
60+
a = expand_derivatives(Differential(var)(ex))
61+
b = a * var - ex
62+
a, b
63+
end
5764

5865
"""
5966
solve_for(eqs::Vector, vars::Vector)
@@ -69,11 +76,12 @@ function solve_for(eqs, vars)
6976
_solve(A, b)
7077
end
7178

72-
function _solve(A, b)
79+
function _solve(A::AbstractMatrix, b::AbstractArray)
7380
A = SymbolicUtils.simplify.(to_symbolic.(A), polynorm=true)
7481
b = SymbolicUtils.simplify.(to_symbolic.(b), polynorm=true)
7582
SymbolicUtils.simplify.(ldiv(sym_lu(A), b))
7683
end
84+
_solve(a, b) = value(SymbolicUtils.simplify(b/a, polynorm=true))
7785

7886
# ldiv below
7987

src/systems/abstractsystem.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ end
230230
lhss(xs) = map(x->x.lhs, xs)
231231
rhss(xs) = map(x->x.rhs, xs)
232232

233+
flatten(sys::AbstractSystem) = sys
234+
233235
function equations(sys::ModelingToolkit.AbstractSystem)
234236
if isempty(sys.systems)
235237
return sys.eqs

0 commit comments

Comments
 (0)