⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_funcs.c

📁 该文件为c++的数学函数库!是一个非常有用的编程工具.它含有各种数学函数,为科学计算、工程应用等程序编写提供方便!
💻 C
📖 第 1 页 / 共 2 页
字号:
/* multiroots/test_funcs.c *  * Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough *  * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. *  * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#include <config.h>#include <math.h>#include <gsl/gsl_vector.h>#include <gsl/gsl_matrix.h>#include <gsl/gsl_multiroots.h>#include "test_funcs.h"/* For information on testing see the following paper,   J.J More, B.S. Garbow, K.E. Hillstrom, "Testing Unconstrained   Optimization Software", ACM Transactions on Mathematical Software,   Vol 7, No 1, (1981) p 17-41   *//* Rosenbrock Function */gsl_multiroot_function_fdf rosenbrock ={&rosenbrock_f, &rosenbrock_df, &rosenbrock_fdf, 2, 0};voidrosenbrock_initpt (gsl_vector * x){  gsl_vector_set (x, 0, -1.2);  gsl_vector_set (x, 1, 1.0);}introsenbrock_f (const gsl_vector * x, void *params, gsl_vector * f){  double x0 = gsl_vector_get (x, 0);  double x1 = gsl_vector_get (x, 1);  double y0 = 1 - x0;  double y1 = 10 * (x1 - x0 * x0);  gsl_vector_set (f, 0, y0);  gsl_vector_set (f, 1, y1);  params = 0;                   /* avoid warning about unused parameters */  return GSL_SUCCESS;}introsenbrock_df (const gsl_vector * x, void *params, gsl_matrix * df){  double x0 = gsl_vector_get (x, 0);  double df00 = -1;  double df01 = 0;  double df10 = -20 * x0;  double df11 = 10;  gsl_matrix_set (df, 0, 0, df00);  gsl_matrix_set (df, 0, 1, df01);  gsl_matrix_set (df, 1, 0, df10);  gsl_matrix_set (df, 1, 1, df11);  params = 0;                   /* avoid warning about unused parameters */  return GSL_SUCCESS;}introsenbrock_fdf (const gsl_vector * x, void *params,                gsl_vector * f, gsl_matrix * df){  rosenbrock_f (x, params, f);  rosenbrock_df (x, params, df);  return GSL_SUCCESS;}/* Freudenstein and Roth function */gsl_multiroot_function_fdf roth ={&roth_f, &roth_df, &roth_fdf, 2, 0};voidroth_initpt (gsl_vector * x){  gsl_vector_set (x, 0, 4.5);  /* changed from the value in the paper */  gsl_vector_set (x, 1, 3.5);  /* otherwise the problem is too hard */}introth_f (const gsl_vector * x, void *params, gsl_vector * f){  double x0 = gsl_vector_get (x, 0);  double x1 = gsl_vector_get (x, 1);  double y0 = -13.0 + x0 + ((5.0 - x1)*x1 - 2.0)*x1;  double y1 = -29.0 + x0 + ((x1 + 1.0)*x1 - 14.0)*x1;  gsl_vector_set (f, 0, y0);  gsl_vector_set (f, 1, y1);  params = 0;                   /* avoid warning about unused parameters */  return GSL_SUCCESS;}introth_df (const gsl_vector * x, void *params, gsl_matrix * df){  double x1 = gsl_vector_get (x, 1);  double df00 = 1;  double df01 = -3 * x1 * x1 + 10 * x1 - 2;  double df10 = 1;  double df11 = 3 * x1 * x1 + 2 * x1 - 14;  gsl_matrix_set (df, 0, 0, df00);  gsl_matrix_set (df, 0, 1, df01);  gsl_matrix_set (df, 1, 0, df10);  gsl_matrix_set (df, 1, 1, df11);  params = 0;                   /* avoid warning about unused parameters */  return GSL_SUCCESS;}introth_fdf (const gsl_vector * x, void *params,                gsl_vector * f, gsl_matrix * df){  roth_f (x, params, f);  roth_df (x, params, df);  return GSL_SUCCESS;}/* Powell badly scaled function */gsl_multiroot_function_fdf powellscal ={&powellscal_f, &powellscal_df, &powellscal_fdf, 2, 0};voidpowellscal_initpt (gsl_vector * x){  gsl_vector_set (x, 0, 0.0);  gsl_vector_set (x, 1, 1.0);}intpowellscal_f (const gsl_vector * x, void *params, gsl_vector * f){  double x0 = gsl_vector_get (x, 0);  double x1 = gsl_vector_get (x, 1);  double y0 = 10000.0 * x0 * x1 - 1.0;  double y1 = exp (-x0) + exp (-x1) - 1.0001;  gsl_vector_set (f, 0, y0);  gsl_vector_set (f, 1, y1);  params = 0;                   /* avoid warning about unused parameters */  return GSL_SUCCESS;}intpowellscal_df (const gsl_vector * x, void *params, gsl_matrix * df){  double x0 = gsl_vector_get (x, 0);  double x1 = gsl_vector_get (x, 1);  double df00 = 10000.0 * x1, df01 = 10000.0 * x0;  double df10 = -exp (-x0), df11 = -exp (-x1);  gsl_matrix_set (df, 0, 0, df00);  gsl_matrix_set (df, 0, 1, df01);  gsl_matrix_set (df, 1, 0, df10);  gsl_matrix_set (df, 1, 1, df11);  params = 0;                   /* avoid warning about unused parameters */  return GSL_SUCCESS;}intpowellscal_fdf (const gsl_vector * x, void *params,                  gsl_vector * f, gsl_matrix * df){  powellscal_f (x, params, f);  powellscal_df (x, params, df);  return GSL_SUCCESS;}/* Brown badly scaled function */gsl_multiroot_function_fdf brownscal ={&brownscal_f, &brownscal_df, &brownscal_fdf, 2, 0};voidbrownscal_initpt (gsl_vector * x){  gsl_vector_set (x, 0, 1.0);  gsl_vector_set (x, 1, 1.0);}intbrownscal_f (const gsl_vector * x, void *params, gsl_vector * f){  double x0 = gsl_vector_get (x, 0);  double x1 = gsl_vector_get (x, 1);  double y0 = x0 - 1e6;  double y1 = x0 * x1 - 2;  gsl_vector_set (f, 0, y0);  gsl_vector_set (f, 1, y1);  params = 0;                   /* avoid warning about unused parameters */  return GSL_SUCCESS;}intbrownscal_df (const gsl_vector * x, void *params, gsl_matrix * df){  double x0 = gsl_vector_get (x, 0);  double x1 = gsl_vector_get (x, 1);  double df00 = 1.0, df01 = 0.0;  double df10 = x1, df11 = x0;  gsl_matrix_set (df, 0, 0, df00);  gsl_matrix_set (df, 0, 1, df01);  gsl_matrix_set (df, 1, 0, df10);  gsl_matrix_set (df, 1, 1, df11);  params = 0;                   /* avoid warning about unused parameters */  return GSL_SUCCESS;}intbrownscal_fdf (const gsl_vector * x, void *params,                  gsl_vector * f, gsl_matrix * df){  brownscal_f (x, params, f);  brownscal_df (x, params, df);  return GSL_SUCCESS;}/* Powell Singular Function */gsl_multiroot_function_fdf powellsing ={&powellsing_f, &powellsing_df, &powellsing_fdf, 4, 0};voidpowellsing_initpt (gsl_vector * x){  gsl_vector_set (x, 0, 3.0);  gsl_vector_set (x, 1, -1.0);  gsl_vector_set (x, 2, 0.0);  gsl_vector_set (x, 3, 1.0);}intpowellsing_f (const gsl_vector * x, void *params, gsl_vector * f){  double x0 = gsl_vector_get (x, 0);  double x1 = gsl_vector_get (x, 1);  double x2 = gsl_vector_get (x, 2);  double x3 = gsl_vector_get (x, 3);  double y0 = x0 + 10 * x1;  double y1 = sqrt (5.0) * (x2 - x3);  double y2 = pow (x1 - 2 * x2, 2.0);  double y3 = sqrt (10.0) * pow (x0 - x3, 2.0);  gsl_vector_set (f, 0, y0);  gsl_vector_set (f, 1, y1);  gsl_vector_set (f, 2, y2);  gsl_vector_set (f, 3, y3);  params = 0;                   /* avoid warning about unused parameters */  return GSL_SUCCESS;}intpowellsing_df (const gsl_vector * x, void *params, gsl_matrix * df){  double x0 = gsl_vector_get (x, 0);  double x1 = gsl_vector_get (x, 1);  double x2 = gsl_vector_get (x, 2);  double x3 = gsl_vector_get (x, 3);  double df00 = 1, df01 = 10, df02 = 0, df03 = 0;  double df10 = 0, df11 = 0, df12 = sqrt (5.0), df13 = -df12;  double df20 = 0, df21 = 2 * (x1 - 2 * x2), df22 = -2 * df21, df23 = 0;  double df30 = 2 * sqrt (10.0) * (x0 - x3), df31 = 0, df32 = 0, df33 = -df30;  gsl_matrix_set (df, 0, 0, df00);  gsl_matrix_set (df, 0, 1, df01);  gsl_matrix_set (df, 0, 2, df02);  gsl_matrix_set (df, 0, 3, df03);  gsl_matrix_set (df, 1, 0, df10);  gsl_matrix_set (df, 1, 1, df11);  gsl_matrix_set (df, 1, 2, df12);  gsl_matrix_set (df, 1, 3, df13);  gsl_matrix_set (df, 2, 0, df20);  gsl_matrix_set (df, 2, 1, df21);  gsl_matrix_set (df, 2, 2, df22);  gsl_matrix_set (df, 2, 3, df23);  gsl_matrix_set (df, 3, 0, df30);  gsl_matrix_set (df, 3, 1, df31);  gsl_matrix_set (df, 3, 2, df32);  gsl_matrix_set (df, 3, 3, df33);  params = 0;                   /* avoid warning about unused parameters */  return GSL_SUCCESS;}intpowellsing_fdf (const gsl_vector * x, void *params,                    gsl_vector * f, gsl_matrix * df){  powellsing_f (x, params, f);  powellsing_df (x, params, df);  return GSL_SUCCESS;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -