Example #1
0
void test009 ( )

/******************************************************************************/
/*
  Purpose:

    TEST009 tests R4_HUGE.

  Licensing:

    This code is distributed under the GNU LGPL license. 

  Modified:

    25 June 2010

  Author:

    John Burkardt
*/
{
  printf ( "\n" );
  printf ( "TEST009\n" );
  printf ( "  R4_HUGE returns a large R4 value;\n" );
  printf ( "\n" );
  printf ( "  R4_HUGE = %g\n", r4_huge ( ) );

  return;
}
Example #2
0
float r4mat_min ( int m, int n, float a[] )

/******************************************************************************/
/*
  Purpose:

    R4MAT_MIN returns the minimum entry of an R4MAT.

  Discussion:

    An R4MAT is a doubly dimensioned array of R8 values, stored as a vector
    in column-major order.

  Licensing:

    This code is distributed under the GNU LGPL license.

  Modified:

    15 May 2010

  Author:

    John Burkardt

  Parameters:

    Input, int M, the number of rows in A.

    Input, int N, the number of columns in A.

    Input, float A[M*N], the M by N matrix.

    Output, float R4MAT_MIN, the minimum entry of A.
*/
{
  int i;
  int j;
  float value;

  value = r4_huge ( );

  for ( j = 0; j < n; j++ )
  {
    for ( i = 0; i < m; i++ )
    {
      value = r4_min ( value, a[i+j*m] );
    }
  }

  return value;
}
Example #3
0
float r4vec_max ( int n, float r4vec[] )

/******************************************************************************/
/*
  Purpose:

    R4VEC_MAX returns the value of the maximum element in a R4VEC.

  Licensing:

    This code is distributed under the GNU LGPL license.

  Modified:

    05 May 2006

  Author:

    John Burkardt

  Parameters:

    Input, int N, the number of entries in the array.

    Input, float R4VEC[N], a pointer to the first entry of the array.

    Output, float R4VEC_MAX, the value of the maximum element.  This
    is set to 0.0 if N <= 0.
*/
{
  int i;
  float value;

  value = - r4_huge ( );

  if ( n <= 0 )
  {
    return value;
  }

  for ( i = 0; i < n; i++ )
  {
    if ( value < r4vec[i] )
    {
      value = r4vec[i];
    }
  }
  return value;
}
Example #4
0
float r4vec_min ( int n, float r4vec[] )

/******************************************************************************/
/*
  Purpose:

    R4VEC_MIN returns the value of the minimum element in a R4VEC.

  Licensing:

    This code is distributed under the GNU LGPL license.

  Modified:

    05 May 2006

  Author:

    John Burkardt

  Parameters:

    Input, int N, the number of entries in the array.

    Input, float R4VEC[N], the array to be checked.

    Output, float R4VEC_MIN, the value of the minimum element.
*/
{
  int i;
  float value;

  value = r4_huge ( );

  if ( n <= 0 )
  {
    return value;
  }

  for ( i = 0; i < n; i++ )
  {
    if ( r4vec[i] < value )
    {
      value = r4vec[i];
    }
  }
  return value;
}
Example #5
0
float r4_normal_01_cdf_inverse ( float p )
// Purpose: inverts the standard normal CDF. The result is accurate to about 1 part in 10**7.
// Author:  Original FORTRAN77 version by Michael Wichura. C version by John Burkardt.

// Reference: Michael Wichura, The Percentage Points of the Normal Distribution, Algorithm AS 241, Applied Statistics, Volume 37, Number 3, pages 477-484, 1988.

//  Parameters: Input, float P, the value of the cumulative probability densitity function. 0 < P < 1.  If P is outside this range, an "infinite" result is returned.
// Outputs the normal deviate value with the property that the probability of a standard normal deviate being less than or equal to this value is P.
{
  static float a[4] = { 3.3871327179f, 50.434271938f, 159.29113202f, 59.109374720f };
  static float b[4] = { 1.0, 17.895169469f, 78.757757664f, 67.187563600f };
  static float c[4] = { 1.4234372777f, 2.7568153900f, 1.3067284816f, 0.17023821103f };
  static float const1 = 0.180625f;
  static float const2 = 1.6f;
  static float d[3] = { 1.0f, 0.73700164250f, 0.12021132975f };
  static float e[4] = { 6.6579051150f, 3.0812263860f, 0.42868294337f, 0.017337203997f };
  static float f[3] = { 1.0f, 0.24197894225f, 0.012258202635f };
  float q;
  float r;
  static float split1 = 0.425f;
  static float split2 = 5.0f;
  float value;

  if ( p <= 0.0 )
  {
    value = - r4_huge ( );
    return value;
  }

  if ( 1.0 <= p )
  {
    value = r4_huge ( );
    return value;
  }

  q = p - 0.5f;

  if ( fabs ( q ) <= split1 )
  {
    r = const1 - q * q;
    value = q * r4poly_value ( 4, a, r ) / r4poly_value ( 4, b, r );
  }
  else
  {
    if ( q < 0.0 )
    {
      r = p;
    }
    else
    {
      r = 1.0f - p;
    }

    if ( r <= 0.0 )
    {
      value = - 1.0;
      exit ( 1 );
    }

    r = sqrt ( -log ( r ) );

    if ( r <= split2 )
    {
      r = r - const2;
      value = r4poly_value ( 4, c, r ) / r4poly_value ( 3, d, r );
    }
    else
    {
      r = r - split2;
      value = r4poly_value ( 4, e, r ) / r4poly_value ( 3, f, r );
    }

    if ( q < 0.0 )
    {
      value = - value;
    }

  }

  return value;
}