如何用gsl在cholesky中打印下层矩阵?

时间:2018-05-17 18:12:18

标签: c++ gsl

我正在使用gsl和c ++来解决使用Cholesky方法的线性系统,一切正常但我想获得并打印下面的矩阵L.我在官方文档中没有找到关于这个问题的任何内容。这是我的代码:

#include <iostream>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_linalg.h>


using namespace std;

int main(void) {

    double a_data[] = { 4, -1, 1,
                        -1, 4.25, 2.75,
                        1, 2.75, 3.5};

    double b_data[] = {1, 2, 3};

    gsl_matrix_view A = gsl_matrix_view_array (a_data, 3, 3);
    gsl_vector_view b = gsl_vector_view_array (b_data, 3);
    gsl_permutation * p = gsl_permutation_alloc (3);
    gsl_vector *x = gsl_vector_alloc (3);
    gsl_matrix *L = gsl_matrix_alloc (3, 3);



    gsl_linalg_pcholesky_decomp(& A.matrix, p);
    gsl_linalg_pcholesky_solve(& A.matrix, p, &b.vector, x);
    cout<<"x = "<<endl;
    gsl_vector_fprintf (stdout, x, "%g");
    cout<<"p = "<<endl;
    gsl_permutation_fprintf (stdout, p, "%d");
    cout<<endl;
    cout<<"L = "<<endl;
    gsl_matrix_fprintf (stdout, L, "%g");

    gsl_permutation_free (p);

    return 0;
}

1 个答案:

答案 0 :(得分:1)

较低的矩阵L被原始矩阵A覆盖。矩阵A的较低三角形部分存储L。