1 /* multimin/test_funcs.c
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000 Fabrice Rossi
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include <gsl/gsl_multimin.h>
23 #include "test_funcs.h"
25 gsl_multimin_function_fdf rosenbrock =
31 gsl_multimin_function rosenbrock_fmin =
35 void rosenbrock_initpt (gsl_vector * x)
37 gsl_vector_set (x, 0, -1.2);
38 gsl_vector_set (x, 1, 1.0);
41 double rosenbrock_f (const gsl_vector * x, void *params)
43 double u = gsl_vector_get(x,0);
44 double v = gsl_vector_get(x,1);
48 return a * a + 10 * b * b;
51 void rosenbrock_df (const gsl_vector * x, void *params, gsl_vector * df)
53 double u = gsl_vector_get(x,0);
54 double v = gsl_vector_get(x,1);
57 gsl_vector_set(df,0,2 * (u - 1) + 40 * u * b);
58 gsl_vector_set(df,1,-20 * b);
61 void rosenbrock_fdf (const gsl_vector * x, void *params, double * f,
64 double u = gsl_vector_get(x,0);
65 double v = gsl_vector_get(x,1);
69 *f = a * a + 10 * b * b;
70 gsl_vector_set(df,0,2 * (u - 1) + 40 * u * b);
71 gsl_vector_set(df,1,-20 * b);
74 gsl_multimin_function_fdf roth =
80 gsl_multimin_function roth_fmin =
84 void roth_initpt (gsl_vector * x)
86 gsl_vector_set (x, 0, 4.5);
87 gsl_vector_set (x, 1, 3.5);
90 double roth_f (const gsl_vector * x, void *params)
92 double u = gsl_vector_get(x,0);
93 double v = gsl_vector_get(x,1);
94 double a = -13.0 + u + ((5.0 - v)*v - 2.0)*v;
95 double b = -29.0 + u + ((v + 1.0)*v - 14.0)*v;
100 void roth_df (const gsl_vector * x, void *params, gsl_vector * df)
102 double u = gsl_vector_get(x,0);
103 double v = gsl_vector_get(x,1);
104 double a = -13.0 + u + ((5.0 - v)*v - 2.0)*v;
105 double b = -29.0 + u + ((v + 1.0)*v - 14.0)*v;
106 double c = -2 + v * (10 - 3 * v);
107 double d = -14 + v * (2 + 3 * v);
109 gsl_vector_set(df,0,2 * a + 2 * b);
110 gsl_vector_set(df,1,2 * a * c + 2 * b * d);
113 void roth_fdf (const gsl_vector * x, void *params, double * f,
116 *f = roth_f (x,params);
117 roth_df(x,params,df);
120 gsl_multimin_function_fdf wood =
126 gsl_multimin_function wood_fmin =
131 wood_initpt (gsl_vector * x)
133 gsl_vector_set (x, 0, -3.0);
134 gsl_vector_set (x, 1, -1.0);
135 gsl_vector_set (x, 2, -3.0);
136 gsl_vector_set (x, 3, -1.0);
139 double wood_f (const gsl_vector * x, void *params)
141 double u1 = gsl_vector_get(x,0);
142 double u2 = gsl_vector_get(x,1);
143 double u3 = gsl_vector_get(x,2);
144 double u4 = gsl_vector_get(x,3);
146 double t1 = u1 * u1 - u2;
147 double t2 = u3 * u3 - u4;
149 return 100 * t1 * t1 + (1 - u1) * (1 - u1)
150 + 90 * t2 * t2 + (1 - u3) * (1 - u3)
151 + 10.1 * ( (1 - u2) * (1 - u2) + (1 - u4) * (1 - u4) )
152 + 19.8 * (1 - u2) * (1 - u4);
155 void wood_df (const gsl_vector * x, void *params, gsl_vector * df)
157 double u1 = gsl_vector_get(x,0);
158 double u2 = gsl_vector_get(x,1);
159 double u3 = gsl_vector_get(x,2);
160 double u4 = gsl_vector_get(x,3);
162 double t1 = u1 * u1 - u2;
163 double t2 = u3 * u3 - u4;
165 gsl_vector_set(df,0, 400 * u1 * t1 - 2 * (1 - u1) );
166 gsl_vector_set(df,1, -200 * t1 - 20.2 * (1 - u2) - 19.8 * (1 - u4) );
167 gsl_vector_set(df,2, 360 * u3 * t2 - 2 * (1 - u3) );
168 gsl_vector_set(df,3, -180 * t2 - 20.2 * (1 - u4) - 19.8 * (1 - u2) );
172 void wood_fdf (const gsl_vector * x, void *params, double * f, gsl_vector * df)
174 wood_df(x,params,df);
179 gsl_multimin_function_fdf Nrosenbrock =
185 void Nrosenbrock_df (const gsl_vector * x, void *params, gsl_vector * df)
187 gsl_multimin_function F ;
191 gsl_multimin_diff (&F, x, df);
194 void Nrosenbrock_fdf (const gsl_vector * x, void *params, double * f,
197 *f = rosenbrock_f (x, params);
198 Nrosenbrock_df (x, params, df);
201 gsl_multimin_function_fdf Nroth =
207 void Nroth_df (const gsl_vector * x, void *params, gsl_vector * df)
209 gsl_multimin_function F ;
213 gsl_multimin_diff (&F, x, df);
216 void Nroth_fdf (const gsl_vector * x, void *params, double * f,
219 *f = roth_f (x, params);
220 Nroth_df (x, params, df);
224 gsl_multimin_function_fdf Nwood =
230 void Nwood_df (const gsl_vector * x, void *params, gsl_vector * df)
232 gsl_multimin_function F ;
236 gsl_multimin_diff (&F, x, df);
239 void Nwood_fdf (const gsl_vector * x, void *params, double * f,
242 *f = wood_f (x, params);
243 Nwood_df (x, params, df);