I think I understand what the error is, but I can’t find where I made the mistake. Can anyone help?
LoadError: DimensionMismatch(“arrays could not be broadcast to a common size; got a dimension with lengths 11 and 12”)
in expression starting at [name].jl:80
using InstantiateFromURL
using LinearAlgebra, Statistics, Random, SparseArrays
using OrdinaryDiffEq, StochasticDiffEq
using Parameters
using Plots
gr(fmt=:png);
p_gen = @with_kw ( T = 550.0, theta = 0.3, death_rate = 0.01, m_eiu = 0.1,
m_ih = 0.5, nu = 1.0/20, sigma = 0.03,
gamma_e = 1/8, gamma_i = 1/18, gamma_h = 1/20, gamma_v = 1/60,
gamma_r = 1/500, R0=1.4, beta_bar = 0.75, beta_n = 0.4,
beta_stoch = (t, p) -> p.beta_n )
pop_size = 3.3e8
beta_bar = 0.75
function F(x, p, t)
s, e, i, iu, hr, hd, rd, ru, d, v, R0 = x
@unpack gamma_e, gamma_i, gamma_h, gamma_r, gamma_v, R0, beta_bar, beta_n, beta_stoch, theta, nu, death_rate, m_eiu, m_ih = p
# removed varying R0 from Python version for now
beta_e = beta_n
beta_i = 0.75 * beta_n
beta_iu = 1.5 * beta_n
beta_h = 0.25 * beta_n
function vax_rate(t)
if t < 270
return gamma_v = 0
else
return gamma_v = 1/60
end
end
# compartment interactions
ci = (m_eiu * beta_e * e) + (m_ih * beta_i * i) + (m_eiu * beta_iu * theta * iu) + (m_ih * beta_h * hr) + (m_ih * beta_h * hd)
return [(-(s)* ci) - (gamma_v * s); # s_dot
(s * ci) - (gamma_e * e) - (gamma_v * e); # e_dot
(gamma_e * e - gamma_i * i); # i_dot
((1 - theta) * gamma_i * i) - (gamma_i * iu) - (gamma_v * iu); # iu_dot
theta * (1 - (death_rate / theta)) * gamma_i * i - (gamma_h * hr); #hr_dot
(death_rate * gamma_i * i) - gamma_h * hd; # hd_dot
(gamma_h * hr) - (gamma_v * rd); # rd_dot
(gamma_i * iu) - (gamma_v * ru); #ru_dot
(gamma_v * s) + (gamma_v * e) + (gamma_v * iu) + (gamma_v * rd) + (gamma_v * ru); # v_dot
gamma_h * hd; # d_dot
nu*(beta_stoch(t, p) - beta_n);# dR₀/dt
]
end
function G(x, p, t)
s, e, i, iu, hr, hd, rd, ru, d, v, R0 = x
@unpack gamma_e, gamma_i, gamma_h, gamma_r, gamma_v, R0, beta_bar, beta_n, beta_stoch, sigma, theta, nu, death_rate, m_eiu, m_ih = p
return [0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; sigma*sqrt(beta_n);]
end
p_gen = @with_kw ( T = 550.0, theta = 0.3, death_rate = 0.01, m_eiu = 0.1,
m_ih = 0.5, nu = 1.0/20, sigma = 0.03,
gamma_e = 1/8, gamma_i = 1/18, gamma_h = 1/20,
gamma_r = 1/500, gamma_v = 1/60, R0=1.4, beta_bar = 0.75, beta_n = 0.4, N = 3.3e8,
beta_stoch = (t, p) -> p.beta_n )
p = p_gen() # use all defaults
i_0 = 0
e_0 = 7_500 / pop_size
iu_0 = 0
hr_0 = 0
hd_0 =0
rd_0 = 0
ru_0 = 0
v_0 = 0
d_0 = 0
s_0 = 1 - i_0 - e_0 - iu_0 - hr_0 - hd_0 - rd_0 - ru_0 - v_0 - d_0
b_0 = beta_bar
x_0 = [s_0, i_0, e_0, iu_0, hr_0, hd_0, rd_0, ru_0, v_0, d_0, b_0]
prob = SDEProblem(F, G, x_0, (0, p.T), p)
sol_1 = solve(prob, SOSRI());
@show length(sol_1.t);
sol_2 = solve(prob, SOSRI())
plot(sol_1, vars=[2], title = "Number of Infections", label = "Trajectory 1",
lm = 2, xlabel = "t", ylabel = "i(t)")
plot!(sol_2, vars=[2], label = "Trajectory 2", lm = 2, ylabel = "i(t)")