#include <math.h>
#include "typedefs.h"
#include "smalloc.h"
+#include "vec.h"
#include "gmx_statistics.h"
-static double sqr(double x)
-{
- return x*x;
-}
-
-static int gmx_nint(double x)
+static int gmx_dnint(double x)
{
return (int) (x+0.5);
}
d2 = 0;
for(i=0; (i<N); i++)
{
- d2 += sqr(stats->x[i]-stats->y[i]);
+ d2 += dsqr(stats->x[i]-stats->y[i]);
if ((stats->dy[i]) && (weight == elsqWEIGHT_Y))
{
- w = 1/sqr(stats->dy[i]);
+ w = 1/dsqr(stats->dy[i]);
}
else
{
wtot += w;
- xx += w*sqr(stats->x[i]);
- xx_nw += sqr(stats->x[i]);
+ xx += w*dsqr(stats->x[i]);
+ xx_nw += dsqr(stats->x[i]);
- yy += w*sqr(stats->y[i]);
- yy_nw += sqr(stats->y[i]);
+ yy += w*dsqr(stats->y[i]);
+ yy_nw += dsqr(stats->y[i]);
yx += w*stats->y[i]*stats->x[i];
yx_nw += stats->y[i]*stats->x[i];
/* Compute average, sigma and error */
stats->aver = sy_nw/N;
- stats->sigma_aver = sqrt(yy_nw/N - sqr(sy_nw/N));
+ stats->sigma_aver = sqrt(yy_nw/N - dsqr(sy_nw/N));
stats->error = stats->sigma_aver/sqrt(N);
/* Compute RMSD between x and y */
yy_nw /= N;
sx_nw /= N;
sy_nw /= N;
- ssxx = N*(xx_nw - sqr(sx_nw));
- ssyy = N*(yy_nw - sqr(sy_nw));
+ ssxx = N*(xx_nw - dsqr(sx_nw));
+ ssyy = N*(yy_nw - dsqr(sy_nw));
ssxy = N*(yx_nw - (sx_nw*sy_nw));
- stats->Rdata = sqrt(sqr(ssxy)/(ssxx*ssyy));
+ stats->Rdata = sqrt(dsqr(ssxy)/(ssxx*ssyy));
/* Compute straight line through datapoints, either with intercept
zero (result in aa) or with intercept variable (results in a
{
dy = 1;
}
- chi2aa += sqr((stats->y[i]-(stats->aa*stats->x[i]))/dy);
- chi2 += sqr((stats->y[i]-(stats->a*stats->x[i]+stats->b))/dy);
+ chi2aa += dsqr((stats->y[i]-(stats->aa*stats->x[i]))/dy);
+ chi2 += dsqr((stats->y[i]-(stats->a*stats->x[i]+stats->b))/dy);
}
if (N > 2)
{
}
else
{
- nbins = gmx_nint((delta)/binwidth + 0.5);
+ nbins = gmx_dnint((delta)/binwidth + 0.5);
}
snew(*x,nbins);
snew(nindex,nbins);
chi2 = 0;
if (xd != NULL) {
for(i=0; i<n; i++)
- chi2 += sqr(yr[i] - ((*a)*xd[i] + (*b)));
+ chi2 += dsqr(yr[i] - ((*a)*xd[i] + (*b)));
} else {
for(i=0; i<n; i++)
- chi2 += sqr(yr[i] - ((*a)*xr[i] + (*b)));
+ chi2 += dsqr(yr[i] - ((*a)*xr[i] + (*b)));
}
if (n > 2)
gmx_fatal(FARGS,"Zero or negative weigths in linear regression analysis");
for (i=0; i<n; i++) {
- s_2 = sqr(1.0/dy[i]);
- sxx += s_2*sqr(x[i]);
+ s_2 = dsqr(1.0/dy[i]);
+ sxx += s_2*dsqr(x[i]);
sxy += s_2*y[i]*x[i];
- syy += s_2*sqr(y[i]);
+ syy += s_2*dsqr(y[i]);
sx += s_2*x[i];
sy += s_2*y[i];
w += s_2;
*chi2=0;
for(i=0; i<n; i++)
- *chi2+=sqr((y[i]-((*a)*x[i]+(*b)))/dy[i]);
+ *chi2+=dsqr((y[i]-((*a)*x[i]+(*b)))/dy[i]);
*chi2 = *chi2/w;
*da = sqrt(*chi2/((n-2)*dx2));