% NATIONAL
% This is the M-Script to run corona_modified_SRI.slx
% IN ORDER TO FIND THE BEST ALPHA, BETA, GAMMA and DELTA
% BASED ON THE AVAILABLE DATA at DAY 35 after 14/03/2020
% Simulation time is 35 days
Takhir = 65;
REF_I = 1318;
REF_R = 462;
REF_D = 68;
REF_T = 7716;
% 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 14/03/2020
Ro = 0; % Initial number of prople recovered on 14/03/2020
Do = 1; % Initial number of death on 14/03/2020
To = Io + Ro;  % Initial number of tested on 14/03/2020
% INITIAL GUESS
alpha = 0.004662080000000; % Death Rate = 0.46% Infected
beta = 0.098835899999996; % Every 1000 persons infected 99 persons each day
gamma = 0.018339000000000; % 1.8% infected people recovered each day
delta = 0.105377011000000;
ALPHA(1)=alpha;
BETA(1)=beta;
GAMMA(1)=gamma;
DELTA(1)=delta;
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;
    delta = DELTA(I);
    delta_i(I)= delta;
    sim('corona_modified_SRI_delta_mod.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;
    ERR_T(I)=round(tested(M)) - REF_T;
    % next
    ALPHA(I+1)=ALPHA(I) - (10^(-6))*ERR_D(I);
    BETA(I+1)=BETA(I) - (10^(-5))*ERR_I(I);
    GAMMA(I+1)=GAMMA(I) - (10^(-5))*ERR_R(I);
    DELTA(I+1)=DELTA(I) - (10^(-6))*ERR_T(I);
end
subplot(411), plot(iterasi,ERR_D), grid on, xlabel('iterasi'),ylabel('ERR_D')
subplot(412), plot(iterasi,ERR_I), grid on, xlabel('iterasi'),ylabel('ERR_I')
subplot(413), plot(iterasi,ERR_R), grid on, xlabel('iterasi'),ylabel('ERR_R')
subplot(414), plot(iterasi,ERR_T), grid on, xlabel('iterasi'),ylabel('ERR_T')
format long
ALPHA_FINAL = alpha_i(ITERASI)
BETA_FINAL = beta_i(ITERASI)
GAMMA_FINAL = gamma_i(ITERASI)
DELTA_FINAL = delta_i(ITERASI)
J = length(ERR_I);
Final_ERR_I=ERR_I(J)
Final_ERR_R=ERR_R(J)
Final_ERR_D=ERR_D(J)
Final_ERR_T=ERR_T(J)

