function [ t, S, I, R ] = sir_ode_euler ( n, T, S0, I0, R0, beta, gamma )

%*****************************************************************************80
%
%% sir_ode_euler approximates the SIR solution using the Euler method.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    22 February 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the number of steps to take.  1000 might be typical.
%
%    real T, the final time.
%
%    real BETA, GAMMA, the infection and recovery rates.
%    0.02 and 0.005 might be typical.
%
%    real S0, I0, R0, the susceptible, infected, and recovered
%    populations at the initial time.
%
%  Output:
%
%    real S(N+1), I(N+1), R(N+1), the susceptible, infected, and recovered
%    populations at each time step.
%
  dt = T / n;
%
%  Allocate space.
%
  t = zeros ( 1, n + 1 );
  S = zeros ( 1, n + 1 );
  I = zeros ( 1, n + 1 );
  R = zeros ( 1, n + 1 );

  t(1) = 0.0;
  S(1) = S0;
  I(1) = I0;
  R(1) = R0;

  for i = 1 : n
    [ dSdt, dIdt, dRdt ] = sir_deriv ( t(i), S(i), I(i), R(i), beta, gamma );
    t(i+1) = t(i) + dt;
    S(i+1) = S(i) + dt * dSdt;
    I(i+1) = I(i) + dt * dIdt;
    R(i+1) = R(i) + dt * dRdt;
  end
  
  return
end
