-
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Right hand side derivative #359
Comments
Hi Marius, Thanks for reporting! I think that the reason for this behaviour is that ode = @ODEmodel begin
# Define the state derivatives
a'(t) = p_a * s_0 * nb(t) - d_a * pa1(t),
b'(t) = p_b * pa2(t) - d_b * pb(t),
nb'(t) = -nb(t) * n_ba * ((p_b * pa2(t) - d_b * pb(t)) / b(t)) * (1 - nb(t)),
pa1'(t) = pa1(t) * n_a * ((p_a * s_0 * nb(t) - d_a * pa1(t)) / a(t)) * (1 - pa1(t)),
pa2'(t) = pa2(t) * n_ab * ((p_a * s_0 * nb(t) - d_a * pa1(t)) / a(t)) * (1 - pa2(t)),
pb'(t) = pb(t) * n_b * ((p_b * pa2(t) - d_b * pb(t)) / b(t)) * (1 - pb(t)),
# Define the outputs
y1(t) = a(t), # First measurable output
y2(t) = b(t) # Second measurable output
end with ode = @ODEmodel(
# Define the state derivatives
a'(t) = p_a * s_0 * nb(t) - d_a * pa1(t),
b'(t) = p_b * pa2(t) - d_b * pb(t),
nb'(t) = -nb(t) * n_ba * ((p_b * pa2(t) - d_b * pb(t)) / b(t)) * (1 - nb(t)),
pa1'(t) = pa1(t) * n_a * ((p_a * s_0 * nb(t) - d_a * pa1(t)) / a(t)) * (1 - pa1(t)),
pa2'(t) = pa2(t) * n_ab * ((p_a * s_0 * nb(t) - d_a * pa1(t)) / a(t)) * (1 - pa2(t)),
pb'(t) = pb(t) * n_b * ((p_b * pa2(t) - d_b * pb(t)) / b(t)) * (1 - pb(t)),
# Define the outputs
y1(t) = a(t), # First measurable output
y2(t) = b(t) # Second measurable output
) everything will work. |
Thank you very much for the solution! It indeed works now :) |
Hi! Appending an output for a known parameter should work. For example, ode = @ODEmodel(
# Define the state derivatives
a'(t) = p_a * s_0 * nb(t) - d_a * pa1(t),
b'(t) = p_b * pa2(t) - d_b * pb(t),
nb'(t) = -nb(t) * n_ba * ((p_b * pa2(t) - d_b * pb(t)) / b(t)) * (1 - nb(t)),
pa1'(t) = pa1(t) * n_a * ((p_a * s_0 * nb(t) - d_a * pa1(t)) / a(t)) * (1 - pa1(t)),
pa2'(t) = pa2(t) * n_ab * ((p_a * s_0 * nb(t) - d_a * pa1(t)) / a(t)) * (1 - pa2(t)),
pb'(t) = pb(t) * n_b * ((p_b * pa2(t) - d_b * pb(t)) / b(t)) * (1 - pb(t)),
# Define the outputs
y1(t) = a(t), # First measurable output
y2(t) = b(t), # Second measurable output
y3(t) = p_a
) |
Thank you very much, awesome! |
Hello, i am trying to use your amazing software for my ODE system. However if i end up using it i get the error that a derivative was detected on the right hand side. My original system is not rational, so i followed advice from you for an old Issue here on github: #219 . This resulted in the following code:
And here is the error:
ERROR: LoadError: ArgumentError: Derivative are not allowed in the right-hand side
Stacktrace:
[1] (::StructuralIdentifiability.var"#676#677"{Bool, Symbol, Set{Any}, Set{Any}, Set{Symbol}})(x::Expr)
@ StructuralIdentifiability ~/.julia/packages/StructuralIdentifiability/rZ9cm/src/input_macro.jl:7
[2] walk
@ ~/.julia/packages/MacroTools/Cf2ok/src/utils.jl:135 [inlined]
[3] postwalk
@ ~/.julia/packages/MacroTools/Cf2ok/src/utils.jl:145 [inlined]
[4] (::MacroTools.var"#25#26"{StructuralIdentifiability.var"#676#677"{Bool, Symbol, Set{Any}, Set{Any}, Set{Symbol}}})(x::Expr)
@ MacroTools ~/.julia/packages/MacroTools/Cf2ok/src/utils.jl:145
[5] iterate(::Base.Generator{Vector{Any}, MacroTools.var"#25#26"{StructuralIdentifiability.var"#676#677"{Bool, Symbol, Set{Any}, Set{Any}, Set{Symbol}}}})
@ Base ./generator.jl:47
[6] _collect(c::Vector{Any}, itr::Base.Generator{Vector{Any}, MacroTools.var"#25#26"{StructuralIdentifiability.var"#676#677"{Bool, Symbol, Set{Any}, Set{Any}, Set{Symbol}}}}, ::Base.EltypeUnknown, isz::Base.HasShape{1})
@ Base ./array.jl:854
[7] collect_similar(cont::Vector{Any}, itr::Base.Generator{Vector{Any}, MacroTools.var"#25#26"{StructuralIdentifiability.var"#676#677"{Bool, Symbol, Set{Any}, Set{Any}, Set{Symbol}}}})
@ Base ./array.jl:763
[8] map(f::Function, A::Vector{Any})
@ Base ./abstractarray.jl:3285
[9] walk
@ ~/.julia/packages/MacroTools/Cf2ok/src/utils.jl:135 [inlined]
[10] postwalk
@ ~/.julia/packages/MacroTools/Cf2ok/src/utils.jl:145 [inlined]
[11] (::MacroTools.var"#25#26"{StructuralIdentifiability.var"#676#677"{Bool, Symbol, Set{Any}, Set{Any}, Set{Symbol}}})(x::Expr)
@ MacroTools ~/.julia/packages/MacroTools/Cf2ok/src/utils.jl:145
[12] iterate
@ ./generator.jl:47 [inlined]
[13] collect_to!(dest::Vector{LineNumberNode}, itr::Base.Generator{Vector{Any}, MacroTools.var"#25#26"{StructuralIdentifiability.var"#676#677"{Bool, Symbol, Set{Any}, Set{Any}, Set{Symbol}}}}, offs::Int64, st::Int64)
@ Base ./array.jl:892
[14] collect_to_with_first!(dest::Vector{LineNumberNode}, v1::LineNumberNode, itr::Base.Generator{Vector{Any}, MacroTools.var"#25#26"{StructuralIdentifiability.var"#676#677"{Bool, Symbol, Set{Any}, Set{Any}, Set{Symbol}}}}, st::Int64)
@ Base ./array.jl:870
[15] _collect(c::Vector{Any}, itr::Base.Generator{Vector{Any}, MacroTools.var"#25#26"{StructuralIdentifiability.var"#676#677"{Bool, Symbol, Set{Any}, Set{Any}, Set{Symbol}}}}, ::Base.EltypeUnknown, isz::Base.HasShape{1})
@ Base ./array.jl:864
[16] collect_similar(cont::Vector{Any}, itr::Base.Generator{Vector{Any}, MacroTools.var"#25#26"{StructuralIdentifiability.var"#676#677"{Bool, Symbol, Set{Any}, Set{Any}, Set{Symbol}}}})
@ Base ./array.jl:763
[17] map(f::Function, A::Vector{Any})
@ Base ./abstractarray.jl:3285
[18] walk
@ ~/.julia/packages/MacroTools/Cf2ok/src/utils.jl:135 [inlined]
[19] postwalk
@ ~/.julia/packages/MacroTools/Cf2ok/src/utils.jl:145 [inlined]
[20] _extract_aux!(funcs::Set{Any}, all_symb::Set{Any}, eq::Expr; ders_ok::Bool, type::Symbol)
@ StructuralIdentifiability ~/.julia/packages/StructuralIdentifiability/rZ9cm/src/input_macro.jl:3
[21] _extract_aux!
@ ~/.julia/packages/StructuralIdentifiability/rZ9cm/src/input_macro.jl:1 [inlined]
[22] macrohelper_extract_vars(equations::Vector{Expr}, type::Symbol)
@ StructuralIdentifiability ~/.julia/packages/StructuralIdentifiability/rZ9cm/src/input_macro.jl:67
[23] generate_model_code(::Symbol, ::Expr, ::Vararg{Expr})
@ StructuralIdentifiability ~/.julia/packages/StructuralIdentifiability/rZ9cm/src/input_macro.jl:105
[24] var"@ODEmodel"(source::LineNumberNode, module::Module, ex::Vararg{Expr})
@ StructuralIdentifiability ~/.julia/packages/StructuralIdentifiability/rZ9cm/src/input_macro.jl:270
in expression starting at /Users/malmansto/Documents/Timer/Structural_id.jl:49
in expression starting at /Users/malmansto/Documents/Timer/Structural_id.jl:49
The text was updated successfully, but these errors were encountered: