I am trying to create programmatically a parameter (with @parameter
) with ModelingToolkit.jl. While I am succeeding, the outcome is not exactly what I wish for. Here are the two examples:
@variables t # independent variable (time)
dDt = Differential(t) # define an operator for the differentiation w.r.t. time
@variables T(t) = 300.0 # dependent
function lhs1(timescale)
pars = @parameters τ_T = timescale
τvar = first(pars)
return τvar*dDt(T)
end
function lhs2(variable, timescale)
varsymbol = Symbol(:τ_, Symbol(variable))
pars = (@parameters $(varsymbol) = timescale)
τvar = first(pars)
return τvar*dDt(variable)
end
lhs1(5.0)
lhs2(T, 5.0)
which give:
julia> lhs1(5.0)
τ_T*Differential(t)(T(t))
julia> lhs2(T, 5.0)
var"τ_T(t)"*Differential(t)(T(t))
as you can see, in the second case the created parameter is first not displayed correctly, and second, it is not a parameter at all, it is presented as a function of time. What do I have to do to make lhs2
give exactly the same expression as lhs1
?