根据官网例程写的解算器,win10+vs2005+gsl1.8 求解四方方程的根 定义了根的上下限,可以得到唯一解 放在工程中实时在线求解的时候不定期会报内存泄漏:Object dump complete.,有遇到相同情况的吗? 检查了下发现 gsl 版本较低,更新成 2.4 版本后同样的问题
double rosenbrock_f3(double x, void * params)
{
double a = ((struct rparams *) params)->a;
double b = ((struct rparams *) params)->b;
double c = ((struct rparams *) params)->c;
double d = ((struct rparams *) params)->d;
double e = ((struct rparams *) params)->e;
double f = (1.0 / 4.0)*c*pow(x, 4) + (1.0 / 3.0)*b*pow(x, 3) + (1.0 / 2.0)*a*pow(x, 2) + d*x - e;
return f;
}
double ObtainRoot(double a, double b, double c, double d, double e, double t1) {
int status;
int iter = 0, max_iter = 100;
const gsl_root_fsolver_type *Type;
gsl_root_fsolver *ss;
double r = 0;
double x_lo = 0.0, x_hi = t1;//下限和上限
rparams alpha = { a, b, c, d, e };
gsl_function obtaint;
obtaint.function = &CVehicleExe::rosenbrock_f3;
obtaint.params = α
Type = gsl_root_fsolver_brent;
ss = gsl_root_fsolver_alloc(Type);
gsl_root_fsolver_set(ss, &obtaint, x_lo, x_hi);
do
{
iter++;
status = gsl_root_fsolver_iterate(ss);
r = gsl_root_fsolver_root(ss);
x_lo = gsl_root_fsolver_x_lower(ss);
x_hi = gsl_root_fsolver_x_upper(ss);
status = gsl_root_test_interval(x_lo, x_hi,0, 0.001);
if (status == GSL_SUCCESS)
printf("Converged:\n");
} while (status == GSL_CONTINUE && iter < max_iter);
double result = r;
gsl_root_fsolver_free(ss);
return result;
}
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.