/* * From: jt@avidya.ifa.hawaii.edu * Subject: antivec.c * Date: March 2, 2005 17:05:31 EST * To: wmwood-vasey@cfa.harvard.edu */ /* antivec.c */ /* Fits an antisymmetric matrix as a vector term difference: * A[i][j] = V[i] - V[j] * Inputs are a difference matrix, an error matrix, * the number of terms, and it produces the individual values * The first term is set to zero. */ /* Rev 2.0 John Tonry 030322 - major hacks on args/coding. Same function */ /* Rev 1.0 Megan Novicki c. Jul 2000 */ #include #include #include #include #include #define MIN(a,b) (((a) < (b)) ? (a) : (b)) #define MAX(a,b) (((a) > (b)) ? (a) : (b)) #define ABS(a) (((a) > 0) ? (a) : -(a)) #define NINT(x) (x<0?(int)((x)-0.5):(int)((x)+0.5)) #define SQRT(x) ( ((x) >= 0) ? sqrt(x) : -sqrt(-(x))) static double *cov=NULL, *y; static int nalloc; /* #define EXTRAWGT /* This is to deemphasize very low error points */ /* but probably is better done by the caller */ /* #define SEECOV /* Debug listing of covariance matrix? */ antivec(int n, /* Number of terms */ double *a, /* Antisymmetric nxn matrix */ double *e, /* Uncertainties of terms in matrix */ double *v, /* Resulting vector */ double *dvext, /* External uncertainty in vector */ double *dvint) /* Internal uncertainty in vector */ { int i, j, k, stat; double err, wgt, det, chi, dof, wgtave; dof = (n*(n-1))/2 - (n-1); /* Estimate an average weight */ for(j=0, wgtave=0.0; j nalloc) { if(cov != NULL) { free(cov); free(y); } cov = (double *)calloc(n*n, sizeof(double)); y = (double *)calloc(n, sizeof(double)); nalloc = n; } #ifdef SEECOV printf("Incoming error matrix:\n"); for(j=0; j = %.3f\n", wgtave); for(j=0; j dvext * dvint -> dvint * sqrt(chi/N) * * Case 2: we partition the e matrix into an internal piece and an external * piece, with the internal piece adjusted to make chi/N = 1 and the * external piece having a floor of zero. * * dvext -> dvext * MAX(0, 1-sqrt(chi/N)) * dvint -> dvint * sqrt(chi/N) * * I'm dubious about Case 2, so I'm just going to report things as Case 1. * Users who may have error matrices which include a large piece of * internal matrix error (instead of external vector error) may want to * rescale the dvext and dvint before adding in quadrature to get a final * uncertainty. */ for(j=0; j