【问题标题】:How do you use GSL's Cholesky Decomposition function with C如何在 C 中使用 GSL 的 Cholesky 分解函数
【发布时间】:2022-07-29 14:42:15
【问题描述】:

我一直在使用 GSL 来支持使用 C 进行的一些矩阵操作。不过,我在使用其 Cholesky 分解函数时遇到了挑战,至少可以说 GSL 参考手册中的文档很少。如何获得函数的下三角矩阵输出?

下面是我目前的代码...

# include <gsl/gsl_matrix.h>
# include <gsl/gsl_linalg.h>
#define rows 6
#define cols 6

double cov[rows*cols] = {107.3461, 12.0710, -48.3746, 174.7796, 21.0202, -80.6075,
                12.0710, 8.0304, -5.9610, 20.2434, 2.2427, -9.312,
                -48.3746, -5.9610, 25.2222, -78.6277, -9.4400, 36.1789,
                174.7796, 20.2434, -78.6277, 291.3491, 35.0176, -134.3626,
                21.0202, 2.2427, -9.4400, 35.0176, 4.2144, -16.1499,
                -80.6075, -9.3129, 36.1789, -134.3626, -16.1499, 61.9666};

gsl_matrix_view m = gsl_matrix_view_array(cov, rows, cols);

int gsl_linalg_cholesky_decomp1(gsl_matrix *m)

... don't know what to do after this step

我知道手动计算的公式,但我更愿意利用这个库。

在这方面的任何帮助将不胜感激。

【问题讨论】:

标签: c gsl


【解决方案1】:

根据 David 的建议和更多的挖掘,让事情顺利进行......

#include <stdio.h>
#include <gsl/gsl_linalg.h>

int main ()
{

    double cov[9] = {2, -1, 0, -1, 2, -1, 0, -1, 2};

    gsl_matrix_view m = gsl_matrix_view_array(cov, 3, 3);
    gsl_matrix *x = gsl_matrix_alloc(3,3);

    gsl_linalg_cholesky_decomp1(&m.matrix);

    printf ("x = \n");
    gsl_matrix_fprintf (stdout, x, "%g");
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-29
    • 2013-02-12
    • 2011-10-30
    • 2020-11-05
    • 2015-06-20
    • 1970-01-01
    • 1970-01-01
    • 2014-04-24
    相关资源
    最近更新 更多