c++ - 如何使用gsl在cholesky中打印较低的矩阵?
问题描述
我正在使用 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;
}
解决方案
下矩阵 L 在原始矩阵 A 中被覆盖。矩阵 A 的下三角形部分,存储 L。
推荐阅读
- python - 动态创建类成员 sqlalchemy
- ruby-on-rails - 在 RoR 上的黄瓜测试中转到正确页面时出错
- javascript - 来自 React 材质 UI MenuItem 单击事件的 setState
- java - java/android - TimeZone 的一致方式 3 字母缩写
- mongoose - 如何打印出嵌套在猫鼬模式中的对象?
- java - 无法打开 ServletContext 资源 [/WEB-INF/dispatcher-servlet.xml]
- php - 如何检查管理员是否在自定义 php 文件中登录?
- python - 为什么 Python 的 strptime() 允许“秒”为 60 和 61?
- javascript - 欧洲和南美用户的浏览器在渲染的 JS 中将坐标分隔符从句点更改为逗号
- swift - Setting selectedTitleTextAttributes for a UIControl subclass