gpt4 book ai didi

C编程,GSL vector 库,错误: incompatible type for argument 1 of 'gsl_rng_uniform'

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

我正在 Windows 操作系统上的代码块中进行编程。我必须在下面的代码中使用一些 GSL 库,但在第 13 行出现错误,'gsl_rng_uniform 的参数 1 的类型不兼容

double randomBR = gsl_rng_uniform(r)*360+6;

我不知道如何解决它。在错误消息下,gsl_rng.h 文件中的第 150 行注释显示:“expected 'const struct gsl_rng *' but argument is of type 'double'”。

#include <stdio.h>
#include <gsl_vector.h>
#include <gsl_rng.h>

int main()
{
gsl_vector*vec=gsl_vector_alloc(100);

double z, max, min, r;
int k=100, i, pos;

for (i=0; i<k; i++){
double randomBR = gsl_rng_uniform(r)*360+6;
z=((int)(gsl_rng_uniform)(r)*360+6);
gsl_vector_set(vec, i, z);
}

max=gsl_vector_max(vec);
pos_vector_max_index(vec);
min=gsl_vector_min)(vec);
pos_vector_min_index(vec);

if (max == 360)
{
printf("Max number generated in box %d", pos);
}

if (max < 366)
{
printf("Max number is %f, position %d", max, pos);
}

return 0;
}

最佳答案

函数原型(prototype)为

double gsl_rng_uniform (const gsl_rng * r)

显然它需要一个 const gsl_rng*,而不是一个 double。阅读有关 GSL 文档的更多信息,您必须首先使用 gsl_rng_alloc 初始化它来获取 rng:

gsl_rng * r = gsl_rng_alloc (gsl_rng_taus);

然后将 gsl_rng r 传递给统一函数以获得所需的随机数。

尝试阅读此处的文档:

http://www.gnu.org/software/gsl/manual/html_node/Random-number-generator-initialization.html#Random-number-generator-initialization

http://www.gnu.org/software/gsl/manual/html_node/Sampling-from-a-random-number-generator.html

关于C编程,GSL vector 库,错误: incompatible type for argument 1 of 'gsl_rng_uniform' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36611927/

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