% % SIR_rhs % function dy = SIR_rhs(t,y,params); global N beta = params(1); gamma = params(2); mu = params(3); S = y(1); I = y(2); S_mu = y(3); I_mu = y(4); S_beta = y(5); I_beta = y(6); S_gamma = y(7); I_gamma = y(8); Svec = [S_mu; I_mu; S_beta; I_beta; S_gamma; I_gamma]; J = [(-mu-beta*I) -beta*S; beta*I (beta*S-(gamma+mu))]; Der = blkdiag(J,J,J); Grad = [(N-S); -I; -I*S; I*S; 0; -I]; Sen = Der*Svec + Grad; % % Construct the right-hand side % dy = [mu*(N-S) - beta*I*S; beta*I*S - (gamma+mu)*I; Sen];