function r8vec_variance_sample_update_test ( )

%*****************************************************************************80
%
%% r8vec_variance_sample_update_test() tests r8vec_variance_sample_update().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    06 May 2021
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'r8vec_variance_sample_update_test():\n' );
  fprintf ( 1, '  r8vec_variance_sample_update() updates the sample variance\n' );
  fprintf ( 1, '  of a vector when one more element is added.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '   n     r     var1   var2   var3\n' );
  fprintf ( 1, '\n' );

  n_max = 10;
  a = zeros ( n_max, 1 );

  mean_n = 0.0;
  variance_n = 0.0;

  for n = 1 : n_max

    r = randn ( );

    a(n) = r;
    v1 = r8vec_variance_sample ( n, a );
    v2 = var ( a(1:n) );
    
    nm1 = n - 1;
    mean_nm1 = mean_n;
    variance_nm1 = variance_n;

    [ n, mean_n, variance_n ] = r8vec_variance_sample_update ( nm1, mean_nm1, ...
      variance_nm1, r );

    fprintf ( 1, '  %2d  %14.6g  %14.6g  %14.6g  %14.6g\n', n, r, v1, v2, variance_n );

  end

  return
end
