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

📄 mathstat.c

📁 国外网站上的一些精典的C程序
💻 C
📖 第 1 页 / 共 3 页
字号:
#else /* C++ */Boolean_T Stat::Delete(double datum){      if (count)      {            int idx;            total   -= datum;            meantmp  = Mean();            total2  -= datum * datum;            recip   -= 1.0 / datum;            product /= datum;                        /*            **  If a data array is being used, maintain it            */            if (filt)            {                  /*                  **  Remove low data by physically shifting the array. This is laborious,                  **  but no more so than implementing a decent sort on a circular buffer.                  */                                    if (datum == filt[0])                        memmove(&filt[0], &filt[1], (--count) * sizeof(float));                  /*                  **  Remove high data. Actually, if the datum being removed was at the top                  **  of the array, it may be effectively wiped out by decremented the count,                  **  so the only reamining task to locate data within the array and delete it.                  **  Again, this is done by physically shifting data in the array.                  */                                    else if (datum != filt[count-1])                  {                        if (-1 == (idx = BinSearchF(datum, &filt[0], count)))                              return Error_;                        memmove(&filt[idx], &filt[idx+1], (--count - idx) * sizeof(datum));                  }                  else  --count;                                    return Success_;            }      }      return Error_;}#endif/***  Return the minimum datum****  Parameters: 1 - Pointer to Stat_T structure type****  Returns: Minimum datum****  Note: If no data, return STAT_NaN*/#if !(__cplusplus)double stat_min(Stat_T *ptr){      if (ptr->count)      {            if (ptr->filt)                  return ptr->filt[0];            else  return ptr->min;      }      else  return STAT_NaN;}#else /* C++ */inline double Stat::Min(){      if (count)      {            if (filt)                  return filt[0];            else  return min;      }      else  return STAT_NaN;}#endif/***  Return the maximum datum****  Parameters: 1 - Pointer to Stat_T structure type****  Returns: Maximum datum****  Note: If no data, return STAT_NaN*/#if !(__cplusplus)double stat_max(Stat_T *ptr){      if (ptr->count)      {            if (ptr->filt)                  return ptr->filt[ptr->count - 1];            else  return ptr->max;      }      else  return STAT_NaN;}#else /* C++ */inline double Stat::Max(){      if (count)      {            if (filt)                  return filt[count - 1];            else  return max;      }      else  return STAT_NaN;}#endif/***  Return the error (%) for the minimum datum****  Parameters: 1 - Pointer to Stat_T structure type****  Returns: Percentage error of the minimmum datum****  Note: If no data, return STAT_NaN*/#if !(__cplusplus)double stat_minerror(Stat_T *ptr){      double Mean = stat_mean(ptr);      if (ptr->count)            return 100.0 * (stat_min(ptr) - Mean) / Mean;      else  return STAT_NaN;}#else /* C++ */double Stat::Minerror(){      double mean_ = Mean();      if (ptr->count)            return 100.0 * (Min() - mean) / mean;      else  return STAT_NaN;}#endif/***  Return the error (%) for the maximum datum****  Parameters: 1 - Pointer to Stat_T structure type****  Returns: Percentage error of the minimmum datum****  Note: If no data, return STAT_NaN*/#if !(__cplusplus)double stat_maxerror(Stat_T *ptr){      double Mean = stat_mean(ptr);      if (ptr->count)            return 100.0 * (stat_max(ptr) - Mean) / Mean;      else  return STAT_NaN;}#else /* C++ */double Stat::Maxerror(){      double mean_ = Mean();      if (ptr->count)            return 100.0 * (Max() - mean) / mean;      else  return STAT_NaN;}#endif/***  Compute the arithmetic mean****  Parameters: 1 - Pointer to Stat_T structure type****  Returns: Arithmetic mean of the data****  Note: If no data, return STAT_NaN*/#if !(__cplusplus)double stat_mean(Stat_T *ptr){      if (ptr->count)            return (ptr->total / ptr->count);      else  return STAT_NaN;}#else /* C++ */double Stat::Mean(){      if (count)            return (total / count);      else  return STAT_NaN;}#endif/***  Compute the geometric mean****  Parameters: 1 - Pointer to Stat_T structure type****  Returns: Geometric mean of the data****  Note: If no data, return STAT_NaN*/#if !(__cplusplus)double stat_gmean(Stat_T *ptr){      if (ptr->count)            return pow(ptr->product, 1.0 / ptr->count);      else  return STAT_NaN;}#else /* C++ */double Stat::Gmean(){      if (count)            return pow(product, 1.0 / count);      else  return STAT_NaN;}#endif/***  Compute the harmonic mean****  Parameters: 1 - Pointer to Stat_T structure type****  Returns: Harmonic mean of the data****  Note: If no data, return STAT_NaN*/#if !(__cplusplus)double stat_hmean(Stat_T *ptr){      if (ptr->count)            return ptr->count / ptr->recip;      else  return STAT_NaN;}#else /* C++ */double Stat::Hmean(){      if (count)            return count / recip;      else  return STAT_NaN;}#endif/***  Compute the standard deviation of the population****  Parameters: 1 - Pointer to Stat_T structure type****  Returns: Standard deviation of the population****  Note: If no data, return STAT_NaN*/#if !(__cplusplus)double stat_stddevP(Stat_T *ptr){      if (ptr->count)            return sqrt(stat_varP(ptr));      else  return STAT_NaN;}#else /* C++ */double Stat::StddevP(){      if (count)            return sqrt(VarP);      else  return STAT_NaN;}#endif/***  Compute the standard deviation of the sampled data****  Parameters: 1 - Pointer to Stat_T structure type****  Returns: Standard deviation of the sampled data****  Note: If insufficient data, return STAT_NaN*/#if !(__cplusplus)double stat_stddevS(Stat_T *ptr){      if (ptr->count >= 2)            return sqrt(stat_varS(ptr));      else  return STAT_NaN;}#else /* C++ */double Stat::StddevS(){      if (count >= 2)            return sqrt(VarS);      else  return STAT_NaN;}#endif/***  Compute the variance of the population****  Parameters: 1 - Pointer to Stat_T structure type****  Returns: Variance of the population****  Note: If no data, return STAT_NaN****  Note: If no data, return STAT_NaN*/#if !(__cplusplus)double stat_varP(Stat_T *ptr){      if (ptr->count)            return ((ptr->count * ptr->total2) - (ptr->total * ptr->total)) / (ptr->count * ptr->count);      else  return STAT_NaN;}#else /* C++ */inline double Stat::VarP(){      if (count)            retval = ((count * total2) - (total * total)) / (count * count);      else  return STAT_NaN;}#endif/***  Compute the variance of the sample****  Parameters: 1 - Pointer to Stat_T structure type****  Returns: Variance of the sampled data****  Note: If insufficient data, return STAT_NaN*/#if !(__cplusplus)double stat_varS(Stat_T *ptr){      if (ptr->count >= 2)            return ((ptr->count * ptr->total2) - (ptr->total * ptr->total)) / ((ptr->count - 1) * (ptr->count - 1));      else  return STAT_NaN;}#else /* C++ */inline double Stat::VarS(){      if (ptr->count >= 2)            return ((count * total2) - (total * total)) / ((count - 1) * (count - 1));      else  return STAT_NaN;}#endif/***  Compute the coefficient of variation (percentage) for the population****  Parameters: 1 - Pointer to Stat_T structure type****  Returns: Coefficient of variation of the population****  Note: If no data, return STAT_NaN*/#if !(__cplusplus)double stat_varcoeffP(Stat_T *ptr){      if (ptr->count)            return (stat_varP(ptr) / stat_mean(ptr)) * 100.0;      else  return STAT_NaN;}#else /* C++ */double Stat::VarcoeffP(){      if (count)            return (Varp(ptr) / Mean(ptr)) * 100.0;      else  return STAT_NaN;}#endif/***  Compute the coefficient of variation (percentage) for the sample****  Parameters: 1 - Pointer to Stat_T structure type**

⌨️ 快捷键说明

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