在C中的许多TQLI实现中是否存在错误? 在用户GROO的评论中,对于南加州大学的高级计算和模拟合作所做的C,有一个非常基本的错误,即所有数组都被当作是基于一个数组的。虽然我已经觉得很奇怪,一个非常著名的机构会在其中一个代码中犯这样一个基本的错误,这让我更加困惑,但基本上,TQLI算法和你可以在网上找到的相关tred2算法的每一个其他实现都会犯同样的错误

在C中的许多TQLI实现中是否存在错误? 在用户GROO的评论中,对于南加州大学的高级计算和模拟合作所做的C,有一个非常基本的错误,即所有数组都被当作是基于一个数组的。虽然我已经觉得很奇怪,一个非常著名的机构会在其中一个代码中犯这样一个基本的错误,这让我更加困惑,但基本上,TQLI算法和你可以在网上找到的相关tred2算法的每一个其他实现都会犯同样的错误,c,arrays,segmentation-fault,C,Arrays,Segmentation Fault,示例: 真的有可能所有不同的人都犯了同样的错误,还是我遗漏了什么?是否有基于1的数组的C版本?好问题!来自上述来源的源代码表示从索引1开始对数组进行计算。 也 由基于1的索引数组使用。见: /******************************************************************************/ void tqli(double d[], double e[], int n, double **z) /****************

示例:


真的有可能所有不同的人都犯了同样的错误,还是我遗漏了什么?是否有基于1的数组的C版本?

好问题!来自上述来源的源代码表示从索引
1
开始对数组进行计算。 也

由基于
1
的索引数组使用。见:

/******************************************************************************/
void tqli(double d[], double e[], int n, double **z)
/*******************************************************************************
QL algorithm with implicit shifts, to determine the eigenvalues and eigenvectors
of a real, symmetric, tridiagonal matrix, or of a real, symmetric matrix
previously reduced by tred2 sec. 11.2. On input, d[1..n] contains the diagonal
elements of the tridiagonal matrix. On output, it returns the eigenvalues. The
vector e[1..n] inputs the subdiagonal elements of the tridiagonal matrix, with
e[1] arbitrary. On output e is destroyed. When finding only the eigenvalues,
several lines may be omitted, as noted in the comments. If the eigenvectors of
a tridiagonal matrix are desired, the matrix z[1..n][1..n] is input as the
identity matrix. If the eigenvectors of a matrix that has been reduced by tred2
are required, then z is input as the matrix output by tred2. In either case,
the kth column of z returns the normalized eigenvector corresponding to d[k].
*******************************************************************************/
{
    double pythag(double a, double b);
    int m,l,iter,i,k;
    double s,r,p,g,f,dd,c,b;

    for (i=2;i<=n;i++) e[i-1]=e[i]; /* Convenient to renumber the elements of e. */
...
}

使用基于索引的数组

In respect to the TU Graz and Stanford algorithms
they just require supplying input data in the specific format. 
这是来自以下方面的示例:

在此版本中,
tqli
使用基于1索引的向量和矩阵。 调用
tqli
需要特殊的数据准备,这些数据由
向量
矩阵
函数。普通的
浮点c[10][10]
不是由
tqli
函数直接使用的。必须准备数据:

d=vector(1,NP);
e=vector(1,NP);
f=vector(1,NP);

a=matrix(1,NP,1,NP);

for (i=1;i<=NP;i++)
    for (j=1;j<=NP;j++) a[i][j]=c[i-1][j-1]; 
结论如下:

真的有可能所有不同的人都做了同样的事情吗 错了还是我遗漏了什么

算法是正确的。谜题中缺少的关键是正确的数据准备

是否存在基于1的数组的C版本


不。

问得好!来自上述来源的源代码表示从索引
1
开始对数组进行计算。 也

由基于
1
的索引数组使用。见:

/******************************************************************************/
void tqli(double d[], double e[], int n, double **z)
/*******************************************************************************
QL algorithm with implicit shifts, to determine the eigenvalues and eigenvectors
of a real, symmetric, tridiagonal matrix, or of a real, symmetric matrix
previously reduced by tred2 sec. 11.2. On input, d[1..n] contains the diagonal
elements of the tridiagonal matrix. On output, it returns the eigenvalues. The
vector e[1..n] inputs the subdiagonal elements of the tridiagonal matrix, with
e[1] arbitrary. On output e is destroyed. When finding only the eigenvalues,
several lines may be omitted, as noted in the comments. If the eigenvectors of
a tridiagonal matrix are desired, the matrix z[1..n][1..n] is input as the
identity matrix. If the eigenvectors of a matrix that has been reduced by tred2
are required, then z is input as the matrix output by tred2. In either case,
the kth column of z returns the normalized eigenvector corresponding to d[k].
*******************************************************************************/
{
    double pythag(double a, double b);
    int m,l,iter,i,k;
    double s,r,p,g,f,dd,c,b;

    for (i=2;i<=n;i++) e[i-1]=e[i]; /* Convenient to renumber the elements of e. */
...
}

使用基于索引的数组

In respect to the TU Graz and Stanford algorithms
they just require supplying input data in the specific format. 
这是来自以下方面的示例:

在此版本中,
tqli
使用基于1索引的向量和矩阵。 调用
tqli
需要特殊的数据准备,这些数据由
向量
矩阵
函数。普通的
浮点c[10][10]
不是由
tqli
函数直接使用的。必须准备数据:

d=vector(1,NP);
e=vector(1,NP);
f=vector(1,NP);

a=matrix(1,NP,1,NP);

for (i=1;i<=NP;i++)
    for (j=1;j<=NP;j++) a[i][j]=c[i-1][j-1]; 
结论如下:

真的有可能所有不同的人都做了同样的事情吗 错了还是我遗漏了什么

算法是正确的。谜题中缺少的关键是正确的数据准备

是否存在基于1的数组的C版本


否。

关于第二个问题:是否数组的第一个元素0-index被用作数组大小?这有时是惯例。我不知道C是否有基于1的数组。关于第二个问题:数组的第一个元素0-index是否被用作数组大小?这有时是惯例。但我不知道C是否有基于1的数组。