function xs = r8vec_scale_ab ( n, x, a, b )

%*****************************************************************************80
%
%% R8VEC_SCALE_AB scales an R8VEC to [A,B].
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    07 October 2018
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer N, the number of entries in the vector.
%
%    Input, real X(N), the vector to be scaled.
%
%    Input, real A, B, the new limits.
%
%    Output, real XS(N), the scaled vector.
%
  xs = x(:);
  xmin = min ( xs );
  xmax = max ( xs );
  if ( 0.0 < xmax - xmin )
    xs = a + ( b - a ) * ( xs - xmin ) / ( xmax - xmin );
  else
    xs = ( a + b ) / 2.0;
  end

  return
end

