function [ n, mean_n, std_n ] = r8vec_std_update ( nm1, mean_nm1, std_nm1, xn )

%*****************************************************************************80
%
%% R8VEC_STD_UPDATE updates the standard deviation of an R8VEC with one new value.
%
%  Discussion:
%
%    An R8VEC is a vector of R8's.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    01 December 2017
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer NM1, the number of entries in the old vector.
%
%    real MEAN_NM1, the mean of the old vector.
%
%    real STD_NM1, the standard deviation of the old vector.
%
%    real XN, the new N-th entry of the vector.
%
%  Output:
%
%    integer N, the number of entries in the new vector.
%
%    real MEAN_N, the mean of the new vector.
%
%    real STD_N, the standard deviation of the new vector.
%

  if ( nm1 <= 0 )
    n = 1;
    mean_n = xn;
    std_n = 0.0;
  else
    n = nm1 + 1;
    mean_n = mean_nm1 + ( xn - mean_nm1 ) / n;
    std_n = sqrt ( ( std_nm1 ^ 2 * nm1 ...
      + ( xn - mean_nm1 ) * ( xn - mean_n ) ) / n )
  end

  return
end
