Skip to content

Commit 3570cc6

Browse files
committed
Add simplify kwarg in solve_for
1 parent 7e7bd16 commit 3570cc6

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/solve.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,23 @@ Assumes `length(eqs) == length(vars)`
8282
8383
Currently only works if all equations are linear.
8484
"""
85-
function solve_for(eqs, vars)
85+
function solve_for(eqs, vars; simplify=true)
8686
A, b = A_b(eqs, vars)
8787
#TODO: we need to make sure that `solve_for(eqs, vars)` contains no `vars`
88-
_solve(A, b)
88+
_solve(A, b, simplify)
8989
end
9090

91-
function _solve(A::AbstractMatrix, b::AbstractArray)
91+
function _solve(A::AbstractMatrix, b::AbstractArray, do_simplify)
9292
A = SymbolicUtils.simplify.(Num.(A), polynorm=true)
9393
b = SymbolicUtils.simplify.(Num.(b), polynorm=true)
94-
value.(SymbolicUtils.simplify.(sym_lu(A) \ b))
94+
sol = value.(sym_lu(A) \ b)
95+
do_simplify ? SymbolicUtils.simplify.(sol, polynorm=true) : sol
96+
end
97+
98+
function _solve(a, b, do_simplify)
99+
sol = value(b/a)
100+
do_simplify ? SymbolicUtils.simplify(sol, polynorm=true) : sol
95101
end
96-
_solve(a, b) = value(SymbolicUtils.simplify(b/a, polynorm=true))
97102

98103
# ldiv below
99104

0 commit comments

Comments
 (0)