gpt4 book ai didi

c - gsl akima 样条的插值误差

转载 作者:行者123 更新时间:2023-11-30 15:26:23 38 4
gpt4 key购买 nike

我使用以下代码收到“gsl: interp.c:150: ERROR: interpolation error”。一些谷歌搜索说,当您尝试使用 interp 函数进行推断时,会发生此错误,但我不明白这是如何发生的。帮助将不胜感激。谢谢。

函数randomground()仅返回一个随机数( double )。

#define NSTEPS 100   

int main()
{
int j, q, space = 1, refine = 100;
double xi = 0.0, tx[2*NSTEPS] = {0}, theight[2*NSTEPS] = {0};

double terrain[(int) (2*NSTEPS*100)] = {0};
double terrainsl[(int) (2*NSTEPS*100)] = {0};

for (j = 0; j < 2*NSTEPS; j++)
{
tx[j] = (double) j*space;
theight[j] = randomground();
}

gsl_interp_accel *acc = gsl_interp_accel_alloc();
gsl_spline *spline = gsl_spline_alloc(gsl_interp_akima, 2*NSTEPS);
gsl_spline_init(spline, tx, theight, 2*NSTEPS);

for (q = 0; q< 2*NSTEPS*100; q++)
{
terrain[q] = gsl_spline_eval(spline,xi,acc);
terrainsl[q] = gsl_spline_eval_deriv(spline,xi,acc);
xi = xi+(double) space/refine;
}
return 0;
}

最佳答案

通过向 tx 和 theight 添加额外的元素解决了该问题。我猜这就是你要求我做的,@ViniciusMiranda。代码现在显示为

                double tx[2*NSTEPS+1] = {0}, theight[2*NSTEPS+1] = {0};
double terrain[(int) (2*NSTEPS*100)] = {0};
double terrainsl[(int) (2*NSTEPS*100)] = {0};

for (j = 0; j < 2*NSTEPS+1; j++)
{
tx[j] = (double) j*space;
theight[j] = randomground();
}

gsl_interp_accel *acc = gsl_interp_accel_alloc();
gsl_spline *spline = gsl_spline_alloc(gsl_interp_akima, 2*NSTEPS+1);
gsl_spline_init(spline, tx, theight, 2*NSTEPS+1);

for (q = 0; q< 2*NSTEPS*100; q++)
{
terrain[q] = gsl_spline_eval(spline,xi,acc);
terrainsl[q] = gsl_spline_eval_deriv(spline,xi,acc);
xi = xi+(double) space/refine;
}

我仍然不明白为什么需要此修复。

关于c - gsl akima 样条的插值误差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27384929/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com