# I keep getting a syntax error saying my function needs and end, but I don't know why?

Below is the code. This is the error I get: ERROR: LoadError: syntax: incomplete: “function” at [name]COVID_Project.jl:17 requires end

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_r = 1/500, R0=1.4, beta_bar = 0.75, beta_n = 0.4,
beta_stoch = (t, p) -> p.beta_n )

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, 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
# compartment interactions
ci = (m_eiu * beta_e * e) + (m_ih * beta_i * i) + (m_eiu * beta_iu * theta * i_u) + (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 * i_u) - (gamma_v * i_u);    # 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 * i_u) - (gamma_v * ru); #ru_dot
(gamma_v * s) + (gamma_v * e) + (gamma_v * i_u) + (gamma_v * rd) + (gamma_v * ru); # v_dot
gamma_h * hd; # d_dot
nu*(beta_bar(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, R0, beta_bar, beta_n, beta_stoch, 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, γ = 1.0 / 18, η = 1.0 / 20,
R₀_n = 1.6, R̄₀ = (t, p) -> p.R₀_n, δ_bar = 0.01,
σ = 0.03, ξ = 0.004, θ = 0.2, N = 3.3E8)
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, r_0, d_0, R̄₀_0, δ_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)")

there is one end missing here

5 Likes

Thank you!

1 Like