I have this code
‘’'function virus_spread(transmission_rate, initial_infected, total_population, simulation_duration)
# Initialize arrays to track data
time = 1:simulation_duration
susceptibles = Int[total_population - initial_infected]
infected = Int[initial_infected]
recovered = Int[0]
for day in 2:simulation_duration
# Calculate the number of new infections
new_infections = Int[susceptibles[day - 1] * transmission_rate * infected[day - 1] / total_population]
# Calculate the number of recoveries (hypothetically, after some time)
recoveries_day = Int[infected[day - 1] - new_infections]
# Update arrays
push!(susceptibles, susceptibles[day - 1] - new_infections)
push!(infected, infected[day - 1] + new_infections - recoveries_day)
push!(recovered, recovered[day - 1] + recoveries_day)
end
return time, susceptibles, infected, recovered
end
Simulation parameters
transmission_rate = 0.2 # Transmission rate (0.2 means one person infects 20% of the population)
initial_infected = 1
total_population = 1000
simulation_duration = 100
Run the simulation
time, susceptibles, infected, recovered = virus_spread(transmission_rate, initial_infected, total_population, simulation_duration)
Plot the results
plot(time, susceptibles, label=“Susceptibles”)
plot!(time, infected, label=“Infected”)
plot!(time, recovered, label=“Recovered”, xlabel=“Days”, ylabel=“Number of People”, legend=true)
‘’’
and I have this error:
‘’‘ERROR: LoadError: InexactError: Int64(0.1998)
Stacktrace:
[1] Int64
@ ./float.jl:900 [inlined]
[2] convert
@ ./number.jl:7 [inlined]
[3] setindex!
@ ./array.jl:969 [inlined]
[4] getindex
@ ./array.jl:403 [inlined]
[5] virus_spread(transmission_rate::Float64, initial_infected::Int64, total_population::Int64, simulation_duration::Int64)
@ Main ~/Documents/sujet veille technologique/Julia/propagation.jl:10
[6] top-level scope
@ ~/Documents/sujet veille technologique/Julia/propagation.jl:31
‘’’
can you help me ?