home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / src / matrix / minmax_source.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-04  |  4.5 KB  |  213 lines

  1. /* matrix/minmax_source.c
  2.  * 
  3.  * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman, Brian Gough
  4.  * 
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or (at
  8.  * your option) any later version.
  9.  * 
  10.  * This program is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * General Public License for more details.
  14.  * 
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. BASE
  21. FUNCTION (gsl_matrix, max) (const TYPE (gsl_matrix) * m)
  22. {
  23.   /* finds the largest element of a matrix */
  24.  
  25.   const size_t M = m->size1;
  26.   const size_t N = m->size2;
  27.   const size_t tda = m->tda;
  28.  
  29.   BASE max = m->data[0 * tda + 0];
  30.   size_t i, j;
  31.  
  32.   for (i = 0; i < M; i++)
  33.     {
  34.       for (j = 0; j < N; j++)
  35.     {
  36.       BASE x = m->data[i * tda + j];
  37.       if (x > max)
  38.         max = x;
  39.     }
  40.     }
  41.  
  42.   return max;
  43. }
  44.  
  45. BASE
  46. FUNCTION (gsl_matrix, min) (const TYPE (gsl_matrix) * m)
  47. {
  48.   /* finds the smallest element of a matrix */
  49.  
  50.   const size_t M = m->size1;
  51.   const size_t N = m->size2;
  52.   const size_t tda = m->tda;
  53.  
  54.   BASE min = m->data[0 * tda + 0];
  55.   size_t i, j;
  56.  
  57.   for (i = 0; i < M; i++)
  58.     {
  59.       for (j = 0; j < N; j++)
  60.     {
  61.       BASE x = m->data[i * tda + j];
  62.       if (x < min)
  63.         min = x;
  64.     }
  65.     }
  66.  
  67.   return min;
  68. }
  69.  
  70.  
  71. void
  72. FUNCTION (gsl_matrix, minmax) (const TYPE (gsl_matrix) * m,
  73.                                BASE * min_out,
  74.                                BASE * max_out)
  75. {
  76.   /* finds the smallest and largest elements of a matrix */
  77.  
  78.   const size_t M = m->size1;
  79.   const size_t N = m->size2;
  80.   const size_t tda = m->tda;
  81.  
  82.   BASE max = m->data[0 * tda + 0];
  83.   BASE min = m->data[0 * tda + 0];
  84.  
  85.   size_t i, j;
  86.  
  87.   for (i = 0; i < M; i++)
  88.     {
  89.       for (j = 0; j < N; j++)
  90.     {
  91.       BASE x = m->data[i * tda + j];
  92.       if (x < min)
  93.         {
  94.           min = x;
  95.         }
  96.       if (x > max)
  97.         {
  98.           max = x;
  99.         }
  100.     }
  101.     }
  102.  
  103.   *min_out = min;
  104.   *max_out = max;
  105. }
  106.  
  107. void
  108. FUNCTION (gsl_matrix, max_index) (const TYPE (gsl_matrix) * m, size_t * imax_out, size_t *jmax_out)
  109. {
  110.   /* finds the largest element of a matrix */
  111.  
  112.   const size_t M = m->size1;
  113.   const size_t N = m->size2;
  114.   const size_t tda = m->tda;
  115.  
  116.   BASE max = m->data[0 * tda + 0];
  117.   size_t imax = 0, jmax = 0;
  118.   size_t i, j;
  119.  
  120.   for (i = 0; i < M; i++)
  121.     {
  122.       for (j = 0; j < N; j++)
  123.     {
  124.       BASE x = m->data[i * tda + j];
  125.       if (x > max)
  126.             {
  127.               max = x;
  128.               imax = i;
  129.               jmax = j;
  130.             }
  131.     }
  132.     }
  133.  
  134.   *imax_out = imax;
  135.   *jmax_out = jmax;
  136. }
  137.  
  138. void
  139. FUNCTION (gsl_matrix, min_index) (const TYPE (gsl_matrix) * m, size_t * imin_out, size_t *jmin_out)
  140. {
  141.   /* finds the largest element of a matrix */
  142.  
  143.   const size_t M = m->size1;
  144.   const size_t N = m->size2;
  145.   const size_t tda = m->tda;
  146.  
  147.   BASE min = m->data[0 * tda + 0];
  148.   size_t imin = 0, jmin = 0;
  149.   size_t i, j;
  150.  
  151.   for (i = 0; i < M; i++)
  152.     {
  153.       for (j = 0; j < N; j++)
  154.     {
  155.       BASE x = m->data[i * tda + j];
  156.       if (x < min)
  157.             {
  158.               min = x;
  159.               imin = i;
  160.               jmin = j;
  161.             }
  162.     }
  163.     }
  164.  
  165.   *imin_out = imin;
  166.   *jmin_out = jmin;
  167. }
  168.  
  169. void
  170. FUNCTION (gsl_matrix, minmax_index) (const TYPE (gsl_matrix) * m,
  171.                                      size_t * imin_out,
  172.                                      size_t * jmin_out,
  173.                                      size_t * imax_out,
  174.                                      size_t * jmax_out)
  175. {
  176.   /* finds the smallest and largest elements of a matrix */
  177.  
  178.   const size_t M = m->size1;
  179.   const size_t N = m->size2;
  180.   const size_t tda = m->tda;
  181.  
  182.   size_t imin = 0, jmin = 0, imax = 0, jmax = 0;
  183.   BASE max = m->data[0 * tda + 0];
  184.   BASE min = m->data[0 * tda + 0];
  185.  
  186.   size_t i, j;
  187.  
  188.   for (i = 0; i < M; i++)
  189.     {
  190.       for (j = 0; j < N; j++)
  191.     {
  192.       BASE x = m->data[i * tda + j];
  193.       if (x < min)
  194.         {
  195.           min = x;
  196.           imin = i;
  197.           jmin = j;
  198.         }
  199.       if (x > max)
  200.         {
  201.           max = x;
  202.           imax = i;
  203.           jmax = j;
  204.         }
  205.     }
  206.     }
  207.  
  208.   *imin_out = imin;
  209.   *jmin_out = jmin;
  210.   *imax_out = imax;
  211.   *jmax_out = jmax;
  212. }
  213.