Closed azev77 closed 3 years ago
In the constructor we can just do eqs.lhs - eqs.rhs
to move them all over. It's an easy fix for whoever has the time.
structural_simplify
already solves issue 1. For the second issue, you just need to write var = collect(@variables x y)
Thanks @YingboMa.
ODEs can be written w/o structural_simplify
: eqs = [D(y) ~ x*(ρ-z)-y]
why not nonlinear equations?
Because D(y) ~ x*(ρ-z)-y
is already the canonical form for ODEs, just like how 0 ~ a + b
is the canonical form for nonlinear equations.
0 ~ y - f(x)
,
-I think y ~ f(x)
is much more convenient to write!
-I really hope it becomes possiblestructural_simplify(ns)
I get an error
using ModelingToolkit, NonlinearSolve
var = collect(@variables x, y)
par = collect(@parameters θ)
eqs = [ 2.0x ~ 15.2, 5.2 ~ x + y,] #
ns = NonlinearSystem(eqs, var, par)
guess = ones(length(var))
ps = [ θ=>0.45; ]
julia> prob = NonlinearProblem(structural_simplify(ns),guess,ps) #
ERROR: ArgumentError: States (0) and initial conditions (2) are of different lengths.
Stacktrace:
[1] process_NonlinearProblem(constructor::Type, sys::NonlinearSystem, u0map::Vector{Float64}, parammap::Vector{Pair{Num, Float64}}; version::Nothing, jac::Bool, checkbounds::Bool, sparse::Bool, simplify::Bool, linenumbers::Bool, parallel::Symbolics.SerialForm, eval_expression::Bool, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ ModelingToolkit ~\.julia\packages\ModelingToolkit\7KM6m\src\systems\nonlinear\nonlinearsystem.jl:215
[2] process_NonlinearProblem
@ ~\.julia\packages\ModelingToolkit\7KM6m\src\systems\nonlinear\nonlinearsystem.jl:208 [inlined]
[3] (NonlinearProblem{true, isinplace, P, F, K} where {isinplace, P, F, K})(sys::NonlinearSystem, u0map::Vector{Float64}, parammap::Vector{Pair{Num, Float64}}; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ ModelingToolkit ~\.julia\packages\ModelingToolkit\7KM6m\src\systems\nonlinear\nonlinearsystem.jl:243
[4] (NonlinearProblem{true, isinplace, P, F, K} where {isinplace, P, F, K})(sys::NonlinearSystem, u0map::Vector{Float64}, parammap::Vector{Pair{Num, Float64}})
@ ModelingToolkit ~\.julia\packages\ModelingToolkit\7KM6m\src\systems\nonlinear\nonlinearsystem.jl:243
[5] NonlinearProblem(::NonlinearSystem, ::Vector{Float64}, ::Vararg{Any, N} where N; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ ModelingToolkit ~\.julia\packages\ModelingToolkit\7KM6m\src\systems\nonlinear\nonlinearsystem.jl:225
[6] NonlinearProblem(::NonlinearSystem, ::Vector{Float64}, ::Vararg{Any, N} where N)
@ ModelingToolkit ~\.julia\packages\ModelingToolkit\7KM6m\src\systems\nonlinear\nonlinearsystem.jl:225
[7] top-level scope
@ REPL[193]:1
structural_simplify
. We don't do constructor-level simplification.structural_simplify
https://github.com/SciML/DiffEqBase.jl/issues/650
Issue 1: Currently we need to write:
It would be great not to require 0 on the LHS:
Issue 2: Currently we need to repeat
x, y
when declaring vars/NonlinearSystem()/guess :It would be really great if we had the option not to repeat things: