/* gcc tkoyama-initial.c -lm -lgsl -lblas on orange */ #include #include #include #include #include #include #include #include #include #include #define MAXSIZE 10 /* maximum size of the matrix x */ #define RKERROR 1e-6 /* error of runge-kutta */ #define NEWINITIAL #define RANGE 1000 #define NDATA 100 struct list{ double c; struct list *next; }; struct tkoyama_params { gsl_matrix *pfs0, *pfs1; }; #if SAMPLE > 0 double *fbnd( double x[MAXSIZE][MAXSIZE], double y[]); #else double *fbnd( double **x, double *y); #endif double *fbnd_diag( double x1[], double y1[]); int rk_func (double t, const double y[], double f[], void *params); struct tkoyama_params* set_pfs( double x[], double y[]); void free_pfs(struct tkoyama_params *params); double *pow_series( double x[], double y[], double r); struct list *mk_coeff( double r); void free_coeff(struct list *coeff); struct list *cons(double c, struct list *coeff); double pow_series_dyi( double x[], double y[], double r, struct list *coeff, int i); double pow_series_dyii( double x[], double y[], double r, struct list *coeff, int i); int set_tdev(double); void runge_kutta(double *g, double *xdiag0, double *ydiag0,double r); void dev_max_eigen(double *g, double max_eigen); void g2fdiag(double *g, double r, double *xdiag0); double move_near0(double *xdiag, double *ydiag, double *xdiag0, double *ydiag0); static int dim; /* dimension of the sphere */ static double eps_pert = 0.00001; static int maxdeg = 10; static int *weight; void perturbation(int length, double v[], double eps, const gsl_rng_type *T, gsl_rng * r) { int i; double err[length]; printf("perturbation:\nerror="); for(i=0; i0){ dim=M-1; printf("dim: %d\n",dim); X = (double **)malloc(sizeof(double *) * M); Xy = (double *)malloc(sizeof(double) * M*M); Y = (double *)malloc(sizeof(double) * M); for (i=0; ii) X[i][j] *= Two; X[j][i] = X[i][j]; k++; if (k >= argc) break; } if (k>= argc) break; } for (i=0; i= argc) break; } } } for (i=0; i RANGE){ return (int)(rr/RANGE) ; } else { return 1; } } void runge_kutta(double *g, double *xdiag0, double *ydiag0,double r) { double t,t1, dt; double h; double rkerror2; int i,ii; int tdev = set_tdev(r); dt = (r*r-1.0)/tdev; for(ii=0; ii %f \n", ii,t, t1);*/ int status; while (t < t1){ status = gsl_odeiv_evolve_apply (e, c, s, &sys, &t, t1, &h, g); if (status != GSL_SUCCESS) break; #ifdef DEBUG_INITIAL printf("s = %f [", t); for(i = 0; i< 2*dim+1; i++) printf("%g, ", g[i]); printf("%g]\n ", g[i]); #endif } gsl_odeiv_evolve_free (e); gsl_odeiv_control_free (c); gsl_odeiv_step_free (s); free_pfs(params); } } void dev_max_eigen(double *g, double max_eigen) { int i; double tmp = exp(-max_eigen); for(i=0; i<2*dim+2; i++) g[i] = g[i]*tmp; } void g2fdiag(double *g, double r, double *xdiag0) { double tmp; int i; tmp = exp(r*r*xdiag0[0]); for(i=0; i<2*dim+2; i++){g[i] *= tmp;} tmp = pow(r, dim+1); for(i=0; ipfs0; gsl_matrix *pfs1 = prms->pfs1; int i, j; for (i = 0; i < 2*dim+2; i++) { f[i] = 0.0; for (j = 0; j < 2*dim+2; j++) f[i] += (gsl_matrix_get(pfs0, i, j)+ gsl_matrix_get(pfs1, i, j)/(2*s) )* y[j]; } return GSL_SUCCESS; } struct tkoyama_params* set_pfs( double x[], double y[]) { struct tkoyama_params *ans = (struct tkoyama_params *)malloc(sizeof(struct tkoyama_params)); gsl_matrix *pfs0, *pfs1; int i,j; pfs0 = gsl_matrix_alloc(2*dim+2, 2*dim+2); pfs1 = gsl_matrix_alloc(2*dim+2, 2*dim+2); gsl_matrix_set_zero(pfs0); gsl_matrix_set_zero(pfs1); for(i=1; ipfs0 = pfs0; ans->pfs1 = pfs1; return ans; } void free_pfs(struct tkoyama_params *params) { gsl_matrix_free(params->pfs0); gsl_matrix_free(params->pfs1); free(params); } /********************************************** Calculating the power series *********************************************/ double* pow_series( double x[], double y[], double r) { double *ans = (double*) malloc((2*dim+2)*sizeof(double)); double s = 2*pow(M_PI,((dim+1)/2.0)) / gsl_sf_gamma((dim+1)/2.0); struct list *coeff = mk_coeff(r); int i; for(i=0; i -1){ if(sum[dp] < max+1){ if(dp == maxdp-1){ coeff = cons( ans[dp], coeff); }else{ dp++; sum[dp] = sum[dp-1]; s[dp] = s[dp-1]; ans[dp] = ans[dp-1]; continue; } }else{ dp--; if(dp == -1){ break; }else{ idx[dp+1] = 0; } } if(dp < dim+1){ ans[dp] = ans[dp]*r*r*(2*idx[dp]+2*idx[dp+dim+1]+1)/(dim+1+2*s[dp]); } else { ans[dp] = ans[dp]*r*r*(2*idx[dp-dim-1]+2*idx[dp]+1)/(dim+1+2*s[dp]); } s[dp+1] = 0; idx[dp]++; sum[dp] = sum[dp] + weight[dp]; s[dp]++; } return coeff; } void free_coeff(struct list *coeff) { struct list *tmp; while(coeff != NULL){ tmp = coeff->next; free(coeff); coeff = tmp; } } struct list* cons(double c, struct list *coeff) { struct list *ans = malloc(sizeof(struct list)); ans->c = c; ans->next = coeff; return ans; } double pow_series_dyi( double x[], double y[], double r, struct list *coeff, int i) { int maxdp = 2*dim+2; int max = maxdeg; double ans[maxdp+1]; int s[maxdp+1]; int idx[maxdp]; int sum[maxdp]; int dp=0; int ic; for(ic=0; ic -1){ if(idx[dp] > -1){ if(dp == maxdp-1){ ans[dp+1] = coeff->c; coeff = coeff->next; }else{ dp++; idx[dp] = (max - sum[dp-1]) / weight[dp]; sum[dp] = sum[dp-1] + idx[dp]*weight[dp]; continue; } }else { dp--; if(dp == -1){ break; } } if(dp == dim+1+i){ if(idx[dp] > 1){ ans[dp] = (ans[dp] + ans[dp+1]) * y[dp -(dim +1)]*y[dp -(dim+1)] /(double)( (2*idx[dp]-1)*(2*idx[dp]-2)); } else if(idx[dp] == 1){ ans[dp] = (ans[dp] + ans[dp+1]) * y[dp -(dim +1)]; } }else { if(idx[dp] > 0){ if(dp < dim+1){ ans[dp] = (ans[dp] + ans[dp+1]) * x[dp]/idx[dp]; } else { ans[dp] = (ans[dp] + ans[dp+1]) * y[dp -(dim +1)]*y[dp -(dim+1)] /(double)( 2*idx[dp]*(2*idx[dp]-1)); } }else if(idx[dp] == 0){ ans[dp] = ans[dp] + ans[dp+1]; } } ans[dp+1] = 0; idx[dp]--; sum[dp] = sum[dp] - weight[dp]; } return ans[0]; } double pow_series_dyii( double x[], double y[], double r, struct list *coeff, int i) { int maxdp = 2*dim+2; int max = maxdeg; double ans[maxdp+1]; int s[maxdp+1]; int idx[maxdp]; int sum[maxdp]; int dp=0; int ic; for(ic=0; ic -1){ if(idx[dp] > -1){ if(dp == maxdp-1){ ans[dp+1] = coeff->c; coeff = coeff->next; }else{ dp++; idx[dp] = (max - sum[dp-1])/ weight[dp]; sum[dp] = sum[dp-1] + idx[dp]*weight[dp]; continue; } }else { dp--; if(dp == -1){ break; } } if(dp == dim+1+i){ if(idx[dp] > 1){ ans[dp] = (ans[dp] + ans[dp+1]) * y[dp -(dim +1)]*y[dp -(dim+1)] /( (2*idx[dp]-2)*(2*idx[dp]-3)); } else if(idx[dp] == 1){ ans[dp] = ans[dp] + ans[dp+1]; } }else { if(idx[dp] > 0){ if(dp < dim+1){ ans[dp] = (ans[dp] + ans[dp+1]) * x[dp]/idx[dp]; } else { ans[dp] = (ans[dp] + ans[dp+1]) * y[dp -(dim +1)]*y[dp -(dim+1)] /( 2*idx[dp]*(2*idx[dp]-1)); } }else if(idx[dp] == 0){ ans[dp] = ans[dp] + ans[dp+1]; } } ans[dp+1] = 0; idx[dp]--; sum[dp] = sum[dp] - weight[dp]; } return ans[0]; }