GSL:如何在GSL中获得LDLT分解
我想从LDLT分解中获取矩阵q
的矩阵l和d
。 scipy.linalg.linalg.dl()
的相同结果,这是代码:
#include <gsl/gsl_math.h> #include <gsl/gsl_sf.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_blas.h>
#include <gsl/gsl_linalg.h>
#include <gsl/gsl_cdf.h>
#include <gsl/gsl_errno.h>
int main() {
const int dim = 3;
double pars[3] = { 0, 0, 0 };
double Q[9] = {
2,-1,0,
-1,3,-1,
0,-1,4
};
int i=0,j=0;
// Gaussian Multivariate distribution
gsl_matrix *L = gsl_matrix_calloc(dim, dim);
gsl_vector *S = gsl_vector_calloc(dim);
gsl_permutation * perm = gsl_permutation_calloc(dim);
for(i=0;i<dim*dim;i++) L->data[i]=Q[i];
>> gsl_linalg_ldlt_decomp(L);
for(i=0;i<3;i++){
for(j=0;j<3;j++){
printf("%.4f ", L->data[i*3+j]);
}
printf("\n");
}
printf("\n S=");
for(i=0;i<3;i++)
printf("%.4f ", S->data[i]);
printf("\n");
}
我的编译args是gcc> gcc ldl.c -lm -llm -llapack -lblas -lglas -lgsl
,
但它返回;
ldl.c: In function ‘main’:
ldl.c:39:5: warning: implicit declaration of function ‘gsl_linalg_ldlt_decomp’; did you mean ‘gsl_linalg_PTLQ_decomp’? [-Wimplicit-function-declaration]
39 | gsl_linalg_ldlt_decomp(L);
| ^~~~~~~~~~~~~~~~~~~~~~
| gsl_linalg_PTLQ_decomp
/usr/bin/ld: /tmp/ccSWXMMb.o: in function `main':
ldl.c:(.text+0x170): undefined reference to `gsl_linalg_ldlt_decomp'
collect2: error: ld returned 1 exit status
为什么 ?我做什么?
I want to get the matrix l and d
of matrix Q
from LDLT decomposition. The same result of scipy.linalg.ldl()
,here is the code:
#include <gsl/gsl_math.h> #include <gsl/gsl_sf.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_blas.h>
#include <gsl/gsl_linalg.h>
#include <gsl/gsl_cdf.h>
#include <gsl/gsl_errno.h>
int main() {
const int dim = 3;
double pars[3] = { 0, 0, 0 };
double Q[9] = {
2,-1,0,
-1,3,-1,
0,-1,4
};
int i=0,j=0;
// Gaussian Multivariate distribution
gsl_matrix *L = gsl_matrix_calloc(dim, dim);
gsl_vector *S = gsl_vector_calloc(dim);
gsl_permutation * perm = gsl_permutation_calloc(dim);
for(i=0;i<dim*dim;i++) L->data[i]=Q[i];
>> gsl_linalg_ldlt_decomp(L);
for(i=0;i<3;i++){
for(j=0;j<3;j++){
printf("%.4f ", L->data[i*3+j]);
}
printf("\n");
}
printf("\n S=");
for(i=0;i<3;i++)
printf("%.4f ", S->data[i]);
printf("\n");
}
my compile args is gcc ldl.c -lm -llapack -lblas -lgsl
But it returns;
ldl.c: In function ‘main’:
ldl.c:39:5: warning: implicit declaration of function ‘gsl_linalg_ldlt_decomp’; did you mean ‘gsl_linalg_PTLQ_decomp’? [-Wimplicit-function-declaration]
39 | gsl_linalg_ldlt_decomp(L);
| ^~~~~~~~~~~~~~~~~~~~~~
| gsl_linalg_PTLQ_decomp
/usr/bin/ld: /tmp/ccSWXMMb.o: in function `main':
ldl.c:(.text+0x170): undefined reference to `gsl_linalg_ldlt_decomp'
collect2: error: ld returned 1 exit status
WHy ? What shoud I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过命令行编译GSL程序的最佳方法也许是使用GSL本身提供的标志。可以通过公用事业读取它们
。
在您的情况下,如下所示(如果您的外壳可以正确处理反向引用):
如果没有,请直接将
gsl-config的输出直接用作命令行参数。
无论如何,您的代码会在我的系统上编译并运行,没有任何问题。
Perhaps the best way of compiling GSL programs via the command-line is by using the flags provided by GSL itself. They can be read via the
utility.
In your case use it as follows (providing your shell can properly process the backquoteses):
If not, use the output of
gsl-config --libs
directly as the command line arguments.Anyway, your code compiles and runs on my system without any problem.