Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/150.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用勒让德多项式的GSL问题_C++_Gsl - Fatal编程技术网

C++ 使用勒让德多项式的GSL问题

C++ 使用勒让德多项式的GSL问题,c++,gsl,C++,Gsl,我试图更新一段使用GSL版本的旧代码,该版本的GSL使用了不推荐使用的函数,但我很难找到如何使用新版本的规范化勒让德多项式函数。下面是一个总结问题的片段: #include <iostream> #include <gsl/gsl_sf_legendre.h> #include <cmath> #define GSL_NEW using namespace std; int main() { int order = 17; int ntheta

我试图更新一段使用GSL版本的旧代码,该版本的GSL使用了不推荐使用的函数,但我很难找到如何使用新版本的规范化勒让德多项式函数。下面是一个总结问题的片段:

#include <iostream>
#include <gsl/gsl_sf_legendre.h>
#include <cmath>

#define GSL_NEW

using namespace std;

int main() {

  int order = 17;
  int ntheta = 36;
  double theta_step = M_PI / ntheta;
  double c, theta;
  double legendre[ntheta][order+1];

  for( int m = 0; m <= order; m += 2) {
    for(int l = m; l <= ntheta; l += 2 ) {
      for( int t = 0; t < ntheta; t++ ) {
        theta = ( ntheta + 0.5 ) * theta_step;
        c = cos(theta);

        if( l == m ) {
#ifdef GSL_NEW
          gsl_sf_legendre_array( GSL_SF_LEGENDRE_SPHARM, order, c, &legendre[t][l] );
          cout << legendre[t][l] << endl;
#else
          gsl_sf_legendre_sphPlm_array(order, m, c, &legendre[t][l] );
          cout << legendre[t][l] << endl;
#endif
        }
      }
    }
  }
}
#包括
#包括
#包括
#定义GSL_NEW
使用名称空间std;
int main(){
整数阶=17;
int ntheta=36;
双θ阶跃=Mπ/nθ;
双c,θ;
双勒让德[ntheta][order+1];

对于(int m=0;m我尝试使用调试符号进行编译(下面命令中的
-g
标志假定您的程序名为“main.cpp”)

并使用调试器运行程序,例如,
gdb
(GNU调试器):

也许知道函数如何工作的人可以回答为什么

usr@cmptr $ g++ -g main.cpp -lgsl -lgslcblas -lm -o main
usr@cmptr $ gdb main
(gdb) run main
Starting program: /home/usr/Desktop/main 
0, 0, 0.282095
1, 0, 0.282095
2, 0, 0.282095
3, 0, 0.282095
4, 0, 0.282095
5, 0, 0.282095
6, 0, 0.282095
7, 0, 0.282095
8, 0, 0.282095
9, 0, 0.282095
10, 0, 0.282095
11, 0, 0.282095
12, 0, 0.282095
13, 0, 0.282095
14, 0, 0.282095
15, 0, 0.282095
16, 0, 0.282095
17, 0, 0.282095
18, 0, 0.282095
19, 0, 0.282095
20, 0, 0.282095
21, 0, 0.282095
22, 0, 0.282095
23, 0, 0.282095
24, 0, 0.282095

Program received signal SIGSEGV, Segmentation fault.
0x0000555555554ded in main () at main.cpp:26
26            cout << t << ", " << l << ", " << legendre[t][l] << endl;
(gdb) quit
double legendre[ntheta + 10][order + 4];