1 #define lin1_N 11 /* can be anything >= p */
2 #define lin1_P 5
3
4 static double lin1_x0[lin1_P] = { 1.0, 1.0, 1.0, 1.0, 1.0 };
5 static double lin1_epsrel = 1.0e-10;
6
7 static void
lin1_checksol(const double x[],const double sumsq,const double epsrel,const char * sname,const char * pname)8 lin1_checksol(const double x[], const double sumsq,
9 const double epsrel, const char *sname,
10 const char *pname)
11 {
12 size_t i;
13 const double sumsq_exact = (double) (lin1_N - lin1_P);
14
15 gsl_test_rel(sumsq, sumsq_exact, epsrel, "%s/%s sumsq",
16 sname, pname);
17
18 for (i = 0; i < lin1_P; ++i)
19 {
20 gsl_test_rel(x[i], -1.0, epsrel, "%s/%s i=%zu",
21 sname, pname, i);
22 }
23 }
24
25 static int
lin1_f(const gsl_vector * x,void * params,gsl_vector * f)26 lin1_f (const gsl_vector * x, void *params, gsl_vector * f)
27 {
28 size_t i, j;
29
30 for (i = 0; i < lin1_N; ++i)
31 {
32 double fi = 0.0;
33
34 for (j = 0; j < lin1_P; ++j)
35 {
36 double xj = gsl_vector_get(x, j);
37 double Aij = (i == j) ? 1.0 : 0.0;
38 Aij -= 2.0 / lin1_N;
39 fi += Aij * xj;
40 }
41
42 fi -= 1.0;
43 gsl_vector_set(f, i, fi);
44 }
45
46 (void)params; /* avoid unused parameter warning */
47
48 return GSL_SUCCESS;
49 }
50
51 static int
lin1_df(const gsl_vector * x,void * params,gsl_matrix * J)52 lin1_df (const gsl_vector * x, void *params, gsl_matrix * J)
53 {
54 size_t i, j;
55
56 for (i = 0; i < lin1_N; ++i)
57 {
58 for (j = 0; j < lin1_P; ++j)
59 {
60 double Jij = (i == j) ? 1.0 : 0.0;
61 Jij -= 2.0 / lin1_N;
62 gsl_matrix_set(J, i, j, Jij);
63 }
64 }
65
66 (void)x; /* avoid unused parameter warning */
67 (void)params; /* avoid unused parameter warning */
68
69 return GSL_SUCCESS;
70 }
71
72 static int
lin1_fvv(const gsl_vector * x,const gsl_vector * v,void * params,gsl_vector * fvv)73 lin1_fvv (const gsl_vector * x, const gsl_vector * v,
74 void *params, gsl_vector * fvv)
75 {
76 (void)x; /* avoid unused parameter warnings */
77 (void)v;
78 (void)params;
79
80 gsl_vector_set_zero(fvv);
81
82 return GSL_SUCCESS;
83 }
84
85 static gsl_multifit_nlinear_fdf lin1_func =
86 {
87 lin1_f,
88 lin1_df,
89 lin1_fvv,
90 lin1_N,
91 lin1_P,
92 NULL,
93 0,
94 0,
95 0
96 };
97
98 static test_fdf_problem lin1_problem =
99 {
100 "linear_full",
101 lin1_x0,
102 NULL,
103 NULL,
104 &lin1_epsrel,
105 &lin1_checksol,
106 &lin1_func
107 };
108