/* GaussFit - A System for Least Squares and Robust Estimation Source Code Copyright (C) 1987 by William H. Jefferys, Michael J. Fitzpatrick and Barbara E. McArthur All Rights Reserved. */ /* Matrix operations to calculate weights and phi vector */ #define import_spp #define import_libc #define import_stdio #define import_math #include #include "defines.h" #include "datum.h" #include "house.h" #include "files.h" #include "robust.h" extern FILE *fp; extern double tolerance; /* number of residuals */ typedef double MATRIX[MATSIZE][MATSIZE]; /* MATRIX typedef */ typedef double VECTOR[MATSIZE]; /* VECTOR typedef */ int iterno=1; matxpose(A,B,p,q) /* transpose p x q matrix A into B */ MATRIX A,B; int p; int q; { int i,j; for(i=0;iMATSIZE) /* max size is MATSIZE */ fatalerror("Matrix Square Root, Order too high\n",""); if(A[0][0] <= 0.0) /* can't do it if diagonal element is <= 0 */ fatalerror("Matrix Square Root Error 0\n",""); A[0][0] = sqrt(A[0][0]); /* 1 x 1 is just square root */ for(i=1;iMATSIZE) fatalerror("Matrix Inverses Order Too Great\n",""); for(i=p-1;i>=0;i--) { for(j=i;j>=0;j--) { sum = deltafn(i,j); /* right hand side is unti matrix */ for(k=j+1;k= MATSIZE) /* if not found and no more room */ fatalerror("No More Room In Matrix Name Table\n","");/*fatal error */ names[*n] = str; /* add name to table */ return (*n)++; /* and return its value */ } covarname(x,y,name) /* concatenate name(x) and name(y) with underscores */ char *x, *y, *name; { strcpy(name,x); /* result is 8 characters long */ strcat(name,"_"); strcat(name,y); } double getsigma(x,y) char *x, *y; { char name[64]; double cov; covarname(x,y,name); /* make the name for the covariance */ if((cov = getdataval(name)) != 0.0) /* look for it in datafile */ { return cov; /* if nonzero, return it */ } if(x!=y) /* if not found, if x!= y then */ { covarname(y,x,name); /* its a covariance, look for it with names in reverse order */ if((cov = getdataval(name)) != 0.0); return cov; } if (iterno == 1) { banner(); iterno = iterno + 1; } return 1.0; /* otherwise its a variance, return 1.0 */ } banner() { fprintf(fp,"\n***********************************"); fprintf(fp,"***********************************\n"); fprintf(fp,"\nNo value given for variance in data table.\n"); fprintf(fp,"Variance assumed equal to 1.0.\n"); fprintf(fp,"Covariance assumed equal to 0.0.\n"); fprintf(fp,"\n***********************************"); fprintf(fp,"***********************************\n\n"); printf("\n***********************************"); printf("***********************************\n"); printf("\nNo value given for variance in data table.\n"); printf("Variance assumed equal to 1.0.\n"); printf("Covariance assumed equal to 0.0.\n"); printf("\n***********************************"); printf("***********************************\n\n"); } computewt(m,k,rhs,L) /* compute weight and phi vector */ int m; /* number of conditional equations */ DATUMPTR k[MATSIZE]; /* pointer to equations of condition */ VECTOR rhs; /* phi vector */ MATRIX L; /* weight matrix */ { int i,j; MATRIX sigma,fx,sigfxt,U,W,fxt; VECTOR uhat,vhat,temp1,temp2,psizero,duhat,dvhat; MATRIX Q,Qt,R,Rt,D,A,At,B,Bt,C,Ct; char *names[MATSIZE]; int n; DATUMPTR kk; extern double SumRho, SumPsi, SumPsiP, SumPsiSq, SumPsiPSq; extern double DeltaV, ScaleFac; n = 0; for(i=0;ivalue; /* get the righthand side */ while(kk = kk->next) /* look at derivative term */ if(kk->type == ObsType) /* if its an observation type */ { j = search(&n,names,getnam(kk->name)); /* get the position of the variable in the matrix */ fx[i][j] = kk->value; /* enter derivative into fx matrix */ } } for(i=0;i 1.0)*/ /* don't step too far */ /* duhat[i] = duhat[i]/du; commented out vis Dick French's problem*/ } else for(i=0;i