7 #include <gsl/gsl_errno.h>
8 #include <gsl/gsl_sf.h>
9 #include <gsl/gsl_siman.h>
10 #include <gsl/gsl_randist.h>
14 #define J_END_COL(i) \
15 for (j=0; j<PN; j++) gsl_matrix_set(J,i,j,J_COL[j]);
17 static inline _Bool IS_SMALL(double v) {
21 static inline double sinc(double x) {
22 return gsl_sf_sinc(x / M_PI);
26 static double *INPUT; /* dyanmic array, on main's stack */
27 static double PREP[NPREP];
29 #define X(xi) gsl_vector_get(xg, (xi))
31 static void printcore(gsl_vector *xg) {
38 printf(" %25.18g,", POINT(i,j));
42 static void prepare(double X[] /* startpoint */) {
43 /* fills in PREP and startpoint */
49 static double cb_f(const gsl_vector *xg, void *params) {
59 printf(" %7.4f", POINT(P)[j]);
69 static void cb_step(const gsl_rng *rng, void *xp, double step_size) {
73 gsl_ran_dir_nd(rng, NX, step);
75 x[i] += step_size * step[i];
76 //printf("\n cb_step %p %10.7f [", xp, step_size);
77 //for (i=0; i<N; i++) printf(" %10.7f,", step[i]);
81 static double cb_metric(void *xp, void *yp) {
82 const double *x=xp, *y=yp;
85 for (i=0, s=0; i<NX; i++) {
86 double d = x[i] - y[i];
92 static void __attribute__((unused)) cb_print(void *xp) {
98 static double scan1double(void) {
103 if (ferror(stdin)) { perror("stdin"); exit(-1); }
104 if (feof(stdin)) exit(0);
105 if (r!=1) { fputs("bad input\n",stderr); exit(-1); }
109 int main(int argc, const char *const *argv) {
114 epsilon = atof(argv[2]);
116 gsl_rng *rng = gsl_rng_alloc(gsl_rng_ranlxd2);
118 double input[NINPUT]; INPUT = input;
119 double startpoint[NX];
122 /* NINPUT + 1 doubles: startpoint, epsilon for residual */
123 for (i=0; i<NINPUT; i++)
124 INPUT[i] = scan1double();
128 gsl_siman_params_t siman_params = {
132 .t_min = epsilon * 1E-3,
133 .iters_fixed_T = 100,
142 cb_Efunc, cb_step, cb_metric,
144 0,0,0, sizeof(startpoint), siman_params);
146 printcore(startpoint);