如何让 Rosenbrock23 在 ParameterizedFunctions.jl DSL 中与 ODE 一起工作?
How to get Rosenbrock23 to work with ODE in ParameterizedFunctions.jl DSL?
进一步 ,我在 ParameterizedFunctions.jl
DSL 中实现了相同的模型。以下 MWE 作品:
using DifferentialEquations
using Plots
# Modeling a consecutive / parallel reaction in a CSTR
# A --> 2B --> C, C --> 2B, B --> D
# PETERSEN-Matrix
# No. A B C D Rate
# 1 -1 2 k1*A
# 2 -2 1 k2*B*B
# 3 2 -1 k3*C
# 4 -1 1 k4*B
fpr! = @ode_def ConsecutiveParallelReaction begin
dA = -k_1*A + q_in/V_liq*(A_in - A)
dB = 2*k_1*A - 2*k_2*B*B + 2*k_3*C - k_4*B + q_in/V_liq*(B_in - B)
dC = k_2*B*B - k_3*C + q_in/V_liq*(C_in - C)
dD = k_4*B + q_in/V_liq*(D_in - D)
end k_1 k_2 k_3 k_4 q_in V_liq A_in B_in C_in D_in
u0 = [1.5, 0.1, 0, 0]
params = [1.0, 1.5, 0.75, 0.15, 3, 15, 0.5, 0, 0, 0]
tspan = (0.0, 15.0)
prob = ODEProblem(fpr!, u0, tspan, params)
sol = solve(prob)
plot(sol)
然而,使用sol = solve(prob, Rosenbrock23())
(甚至使用autodiff=false
),会出现以下错误:
ERROR: LoadError: MethodError: Cannot `convert` an object of type Array{Float64,1} to an object of type Float64
我想这是一个与上述类似的问题,但由于我没有在这里明确定义任何 Float64
向量并且 autodiff=false
没有消除错误,我不知道如何解决这个问题。有什么建议吗?
从评论来看,这似乎确实有效。
进一步 ParameterizedFunctions.jl
DSL 中实现了相同的模型。以下 MWE 作品:
using DifferentialEquations
using Plots
# Modeling a consecutive / parallel reaction in a CSTR
# A --> 2B --> C, C --> 2B, B --> D
# PETERSEN-Matrix
# No. A B C D Rate
# 1 -1 2 k1*A
# 2 -2 1 k2*B*B
# 3 2 -1 k3*C
# 4 -1 1 k4*B
fpr! = @ode_def ConsecutiveParallelReaction begin
dA = -k_1*A + q_in/V_liq*(A_in - A)
dB = 2*k_1*A - 2*k_2*B*B + 2*k_3*C - k_4*B + q_in/V_liq*(B_in - B)
dC = k_2*B*B - k_3*C + q_in/V_liq*(C_in - C)
dD = k_4*B + q_in/V_liq*(D_in - D)
end k_1 k_2 k_3 k_4 q_in V_liq A_in B_in C_in D_in
u0 = [1.5, 0.1, 0, 0]
params = [1.0, 1.5, 0.75, 0.15, 3, 15, 0.5, 0, 0, 0]
tspan = (0.0, 15.0)
prob = ODEProblem(fpr!, u0, tspan, params)
sol = solve(prob)
plot(sol)
然而,使用sol = solve(prob, Rosenbrock23())
(甚至使用autodiff=false
),会出现以下错误:
ERROR: LoadError: MethodError: Cannot `convert` an object of type Array{Float64,1} to an object of type Float64
我想这是一个与上述类似的问题,但由于我没有在这里明确定义任何 Float64
向量并且 autodiff=false
没有消除错误,我不知道如何解决这个问题。有什么建议吗?
从评论来看,这似乎确实有效。