#include #include #include #include "puldat.h" void do_the_fit() { /* fit to a1, t1, mu1, an mu2 only => ndim = 4 */ int i,j,k,l,m; float a1, a2, t1, t2, mu1, mu2; float t0, tend, dt; float t, value; float pulse(); float chisqr(); void amotst(float **p, float y[], int ndim, float ftol, float (*funk)(float []), int *nfunk ); void amoeba(float **p, float y[], int ndim, float ftol, float (*funk)(float []), int *nfunk ); int *nter; float **matrix(); float *vector(); float **p; float *y; void free_matrix(); void free_vector(); int ncnt; nter = &ncnt; if (p1.mode == 1) { p = matrix(1,5,1,4); y = vector(1,5); /* setup the initial simplex */ a1 = p1.sim[1]; a2 = p1.sim[2]; t1 = p1.sim[3]; t2 = p1.sim[4]; mu1 = p1.sim[5]; mu2 = p1.sim[6]; p[1][1] = a1; p[1][2] = t1; p[1][3] = mu1; p[1][4] = mu2; p[2][1] = a1 + 0.1*a1; p[2][2] = t1; p[2][3] = mu1; p[2][4] = mu2; p[3][1] = a1; p[3][2] = t1 + 0.1*t1; p[3][3] = mu1; p[3][4] = mu2; p[4][1] = a1; p[4][2] = t1; p[4][3] = mu1 + 0.1*mu1; p[4][4] = mu2; p[5][1] = a1; p[5][2] = t1; p[5][3] = mu1; p[5][4] = mu2 + 0.1*mu2; /* initial values of y at each of the simplex vetices */ for (i=1; i<=5; i++) { y[i] = chisqr(p[i]); } /* do the fit */ /* printf("1 pulse Before %f %f %f %f %f \n",y[1],y[2],y[3],y[4],y[5]); */ amoeba(p,y,4, 0.0001 ,chisqr, nter); /* printf("1 pulse After %f %f %f %f %f \n",y[1],y[2],y[3],y[4],y[5]); */ p1.iter_one = *nter; p1.chi2_one = y[1]; free_matrix(p,1,5,1,4); free_vector(y,1,5); } else { p = matrix(1,7,1,6); y = vector(1,7); /* setup the initial simplex */ a1 = p1.sim[1]; a2 = p1.sim[2]; t1 = p1.sim[3]; t2 = p1.sim[4]; mu1 = p1.sim[5]; mu2 = p1.sim[6]; for (i = 1; i<=7; i++) { for (j=1; j<=6; j++) { p[i][j] = p1.sim[j]; } } p[1][1] = p[1][1] + p[1][1]*0.1; p[2][1] = p[2][1] + p[2][1]*0.1; p[3][2] = p[3][2] + p[3][2]*0.1; p[4][3] = p[4][3] + p[4][3]*0.1; p[5][4] = p[5][4] + p[5][4]*0.1; p[6][5] = p[6][5] + p[6][5]*0.1; p[7][6] = p[7][6] + p[7][6]*0.1; for (i=1; i<=7; i++) { y[i] = chisqr(p[i]); } /* printf("2-pulse Before %f %f %f %f %f %f %f \n",y[1],y[2],y[3],y[4],y[5],y[6],y[7]); */ amoeba(p,y,6, 0.1 ,chisqr, nter); /* printf("2-pulse After %f %f %f %f %f %f %f \n",y[1],y[2],y[3],y[4],y[5],y[6],y[7]); */ p1.iter_two = *nter; p1.chi2_two = y[1]; free_matrix(p,1,7,1,6); free_vector(y,1,7); } }