⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 idamax.c

📁 GESPI 2.0动态系统模拟工具  
💻 C
字号:
#include <math.h>

int idamax( n, dx, incx )

double *dx;
int n, incx;

/* Purpose : Find largest component of double vector dx


   --- Input ---

   n    : number of elements in input vector
   dx   : double vector with n+1 elements, dx[0] is not used
   incx : storage spacing between elements of dx


   --- Output ---

   idamax : smallest index, 0 if n <= 0


   Find smallest index of maximum magnitude of dx.
   idamax = first i, i=1 to n, to minimize fabs( dx[1-incx+i*incx] ).

*/

{
   double dmax, xmag;
   int i, ii, xindex;

   xindex = 0;
   if ( n <= 0 )
      return xindex;
   xindex = 1;
   if ( n <= 1 || incx <= 0 )
      return xindex;

/* Code for increments not equal to 1.   */

   if ( incx != 1 ) {
      dmax = fabs( dx[1] );
      ii = 2;
      for ( i = 1 + incx ; i <= n * incx ; i = i + incx ) {
         xmag = fabs( dx[i] );
         if ( xmag > dmax ) {
            xindex = ii;
            dmax = xmag;
         }
         ii++;
      }
      return xindex;
   }

/* Code for increments equal to 1.  */

   dmax = fabs( dx[1] );
   for ( i = 2 ; i <= n ; i++ ) {
      xmag = fabs( dx[i] );
      if ( xmag > dmax ) {
         xindex = i;
         dmax = xmag;
      }
   }
   return xindex;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -