未声明标识符
#include "tf.h"
//solveroot,不适用雅可比矩阵的求解器的状态保存在gsl_multiroot_fsolver机构中,更新过程只使用函数值,算法通过近似方法估计J
int solveroot( double * y ) {
const gsl_multiroot_fsolver_type *T;//创建求解器类型指针
gsl_multiroot_fsolver *s;//创建求解器指针
int status;
int i, iter = 0;
gsl_multiroot_function f = {&func_add_f, NodeN, NULL};//根据映射创造待解函数
gsl_vector * x = gsl_vector_alloc( NodeN );
for ( i = 0; i < NodeN; i ++ )
gsl_vector_set( x, i, rand() / ( double )RAND_MAX );
T = gsl_multiroot_fsolver_hybrids;//设置求解器类型:混合算法
s = gsl_multiroot_fsolver_alloc (T, NodeN);//设置求解器维数为3维
gsl_multiroot_fsolver_set (s, &f, x);//向求解函数传递求解器,自定义函数,自变量
do
{
iter++;
status = gsl_multiroot_fsolver_iterate (s);
if (status) /*check if solver is stuck,检查求解器是否卡住了,status=1则求解器异常,需要跳出死循环*/
break;
status = gsl_multiroot_test_residual (s->f, 1e-7);//检验收敛性,距离小于1e-7
}
while (status == GSL_CONTINUE && iter < 1000);
for ( i = 0; i < NodeN; i ++ )
{
y[ i ] = gsl_vector_get( s->x, i );
// printf( "%lf ", y[ i ] );
}
// printf( " %d \n", status );
gsl_multiroot_fsolver_free (s);
gsl_vector_free (x);
return status;
}
//solverroot1使用雅可比矩阵求解器的状态保存在gsl_mutiroot_fdfsolver结构中,由用户提供函数及其导数的更新过程
int solveroot1( double * y ) {
const gsl_multiroot_fdfsolver_type *T;
gsl_multiroot_fdfsolver *s;
int status;
int i,iter = 0;
gsl_multiroot_function_fdf f = {&func_add_f, &func_add_df, &func_add_fdf, NodeN, NULL};
T = gsl_multiroot_fdfsolver_hybrids;
s = gsl_multiroot_fdfsolver_alloc(T, NodeN);
gsl_multiroot_fdfsolver_alloc(T, NodeN);
gsl_vector * x = gsl_vector_alloc( NodeN );
for ( i = 0; i < NodeN; i ++ )
gsl_vector_set( x, i, rand() / ( double )RAND_MAX );
gsl_multiroot_fdfsolver_set (s, &f, x);
do
{
iter++;
status = gsl_multiroot_fdfsolver_iterate (s);//它执行的是单次迭代
if (status) /* check if solver is stuck */
break;
status = gsl_multiroot_test_residual (s->f, 1e-7);//|f1|+|f2|+|f3|<1e-7,则返回GSL_SUCCESS
}
while (status == GSL_CONTINUE && iter < 10000);
//迭代将会在以下三种情况停止:1.根找到了;2.达到了用户定义的最大迭代次数;3.出现错误了
for ( i = 0; i < NodeN; i ++ )
{
y[ i ] = gsl_vector_get( s->x, i );
// printf( "%lf ", y[ i ] );
}
// printf( " %d \n", status );
gsl_multiroot_fdfsolver_free (s);
gsl_vector_free (x);
return status;
}
在solveroot1中T =gsl_multiroot_fdfsolver_hybrids;这一行出现错误,不知道该怎么改
严重性 代码 说明 项目 文件 行 禁止显示状态
警告 C4047 “=”:“const gsl_multiroot_fdfsolver_type *”与“int”的间接级别不同 adaptation C:\Users\Lenovo\source\repos\adaptation\adaptation\solveroot.c 52
严重性 代码 说明 项目 文件 行 禁止显示状态
错误 C2065 “gsl_multiroot_fdfsolver_hybrids”: 未声明的标识符 adaptation C:\Users\Lenovo\source\repos\adaptation\adaptation\solveroot.c 52