Hi,
I am trying to put my linear ODE system in state space form.
My model is quite simple:
function TiThTe(input_funcs::Dict)
@parameters begin
C_i
C_e
C_h
R_ie
R_ih
R_ea
A_w
A_e
T_i_0
T_e_0
T_h_0
end
@variables begin
T_i(t) = T_i_0
T_e(t) = T_e_0
T_h(t) = T_h_0
T_a(t)
P_h(t)
P_s(t)
end
# Define time-varying inputs from the input_funcs dictionary
@named T_a_out = TimeVaryingFunction(input_funcs[:T_a])
@named P_h_out = TimeVaryingFunction(input_funcs[:P_h])
@named P_s_out = TimeVaryingFunction(input_funcs[:P_s])
systems = [T_a_out, P_h_out, P_s_out]
# define the system of differential equations
eqs = [
# dTi equation
C_i * D(T_i) ~ (1 / R_ih) * (T_h - T_i) + (1 / R_ie) * (T_e - T_i) + A_w * P_s,
# dTe equation
C_e * D(T_e) ~ (1 / R_ie) * (T_i - T_e) + (1 / R_ea) * (T_a - T_e) + A_e * P_s,
# dTh equation
C_h * D(T_h) ~ (1 / R_ih) * (T_i - T_h) + P_h
]
# Define the inputs (mapping them to their respective time-varying functions)
inputs = [
T_a ~ T_a_out.output.u,
P_h ~ P_h_out.output.u,
P_s ~ P_s_out.output.u
]
append!(eqs, inputs)
@named sys = ODESystem(eqs, t; systems=systems)
return sys
end
My input functions are given by DataInterpolations.jl.
I try to form the matrices in this way, defining my inputs and outputs:
# inputs
@variables t T_a(t) P_h(t) P_s(t)
inputs = [T_a, P_h, P_s]
# outputs
@variables T_i(t) T_e(t) T_h(t)
outputs= [T_i, T_e, T_h]
# linearize
ss_matrices, ssys = ModelingToolkit.linearize_symbolic(sys, inputs, outputs)
Unfortunately this method complains about missing variables which I dont want to see in my linearization:
ExtraEquationsSystemException: The system is unbalanced. There are 6 highest order derivative variables and 9 equations.
More equations than variables, here are the potential extra equation(s):
0 ~ -T_a_out₊output₊u(t) + DataInterpolations.AkimaInterpolation{Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Float64}([8.167, 8.187, 8.077, 7.988, 7.98, 7.814, 7.784, 7.531, 7.638, 8.057
But I tried adding them anyway to see what result I get:
@variables t T_a(t) P_h(t) P_s(t) T_a_out₊output₊u(t) P_h_out₊output₊u(t) P_s_out₊output₊u(t)
inputs = [T_a, P_h, P_s, T_a_out₊output₊u, P_h_out₊output₊u, P_s_out₊output₊u]
This throws a boundserror in AbstractSystem.jl:
BoundsError: attempt to access 9×3 Matrix{Num} at index [1:3, 4:9]
Stacktrace:
[1] throw_boundserror(A::Matrix{Num}, I::Tuple{UnitRange{Int64}, UnitRange{Int64}})
@ Base .\abstractarray.jl:737
[2] checkbounds
@ .\abstractarray.jl:702 [inlined]
[3] _getindex
@ .\multidimensional.jl:888 [inlined]
[4] getindex(::Matrix{Num}, ::UnitRange{Int64}, ::UnitRange{Int64})
@ Base .\abstractarray.jl:1291
[5] linearize_symbolic(sys::ODESystem, inputs::Vector{Num}, outputs::Vector{Num}; simplify::Bool, allow_input_derivatives::Bool, eval_expression::Bool, eval_module::Module, kwargs::@Kwargs{})
@ ModelingToolkit C:\Users\lange.julia\packages\ModelingToolkit\Vsl3C\src\systems\abstractsystem.jl:2496
[6] linearize_symbolic(sys::ODESystem, inputs::Vector{Num}, outputs::Vector{Num})
@ ModelingToolkit C:\Users\lange.julia\packages\ModelingToolkit\Vsl3C\src\systems\abstractsystem.jl:2472
Could somebody advise me what to do?