function [ n12, mean12, std12 ] = r8vec_std_updates ( n1, mean1, std1, n2, ...
  mean2, std2 )

%*****************************************************************************80
%
%% r8vec_std_updates() computes the standard deviation of two combined vectors.
%
%  Discussion:
%
%    Vectors 1 and 2 have size, mean, and standard deviations computed.
%    This function computes the corresponding size, mean and standard deviation
%    for the vector formed by combining the two vectors.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    09 May 2022
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N1, the number of entries in vector 1.
%
%    real MEAN1, the mean of vector 1.
%
%    real STD1, the standard deviation of vector 1.
%
%    integer N2, the number of entries in vector 2.
%
%    real MEAN2, the mean of vector 2.
%
%    real STD2, the standard deviation of vector 2.
%
%  Output:
%
%    integer N12, the number of entries in the combined vector.
%
%    real MEAN12, the mean of the combined vector.
%
%    real STD12, the standard deviation of the combined vector.
%
  n12 = n1 + n2;

  mean12 = ( n1 * mean1 + n2 * mean2 ) / ( n1 + n2 );

  ta = ( ( n1 - 1 ) * std1^2 + ( n2 - 1 ) * std2^2 ) / ( n1 + n2 - 1 );
  tb = n1 * n2 * ( mean1 - mean2 )^2 / ( n1 + n2 ) / ( n1 + n2 - 1 );
  v12 = ta + tb;
  std12 = sqrt ( v12 );

  return
end
