% The case of SOUTH SULAWESI
% This is the M-Script to run corona_modified_SRI.slx
% IN ORDER TO FIND THE BEST ALPHA, BETA and GAMMA
% BASED ON THE AVAILABLE DATA at DAY 35 after 20/03/2020
% Simulation time is 35 days
T = 35;
REF_I = 420;
REF_R = 82;
REF_D = 35;
% run for 
ITERASI = 1000;
N = 0.01*19000000; % Assume: 1% of the total population is affected by the virus
Io = 2; % Initial number of people infected on 20/03/2020
Ro = 0; % Initial number of prople recovered on 20/03/2020
Do = 1; % Initial number of death on 20/03/2020
alpha = 0.006409420000000; % Death Rate = 1.22% Infected
beta = 0.154031899999999; % Every 1000 persons infected 183 persons each day
gamma = 0.038943500000000; % 3.00% infected people recovered each day
ALPHA(1)=alpha;
BETA(1)=beta;
GAMMA(1)=gamma;
for I = 1:ITERASI
    iterasi(I)=I;
    alpha = ALPHA(I);
    alpha_i(I) = alpha;
    beta = BETA(I);
    beta_i(I) = beta;
    gamma = GAMMA(I);
    gamma_i(I)=gamma;
    sim('corona_modified_SRI_revised.slx');
    M = length(infected);
    ERR_I(I)=round(infected(M)) - REF_I;
    ERR_R(I)=round(recovered(M)) - REF_R;
    ERR_D(I)=round(death(M)) - REF_D;
    % next
    ALPHA(I+1)=ALPHA(I) - (10^(-5))*ERR_D(I);
    BETA(I+1)=BETA(I) - (10^(-5))*ERR_I(I);
    GAMMA(I+1)=GAMMA(I) - (10^(-5))*ERR_R(I);
end
subplot(311), plot(iterasi,ERR_D), grid on, xlabel('iterasi'),ylabel('ERR_D')
subplot(312), plot(iterasi,ERR_I), grid on, xlabel('iterasi'),ylabel('ERR_I')
subplot(313), plot(iterasi,ERR_R), grid on, xlabel('iterasi'),ylabel('ERR_R')
format long
ALPHA_FINAL = alpha_i(ITERASI)
BETA_FINAL = beta_i(ITERASI)
GAMMA_FINAL = gamma_i(ITERASI)
J = length(ERR_I);
Final_ERR_I=ERR_I(J)
Final_ERR_R=ERR_R(J)
Final_ERR_D=ERR_D(J)