我正在使用 GNU GSL 进行一些矩阵计算。我正在尝试将矩阵 B 与矩阵 A 的逆矩阵相乘。
现在我注意到 GSL 的 BLAS 部分有一个函数可以做到这一点,但前提是 A 是三角形。这有什么具体原因吗?另外,进行此计算的最快方法是什么?我应该使用 LU 分解来反转 A,还是有更好的方法?
FWIW,A 的形式为 P' G P,其中 P 是正规矩阵,P' 是其逆矩阵,G 是对角矩阵。
非常感谢:)
我正在尝试找到正确的参数输入到我的代码中以产生所需的结果。我没有猜测和检查,而是使用根查找来查找给出所需结果的参数。有两个变量可以自由变化,但我在运行根查找器时遇到困难。我更改了代码以单独求解每个变量,并发现我在优化一个变量时遇到了麻烦。
问题似乎是 gsl_multiroot_iterate 在第一次迭代后猜测 nan 为 x1 。至少,当我为 x1 放入 printf 语句时,x1 的值在该点之后的 function() 调用中返回。
我正在运行的模拟仅允许 x1 的值在 0 和 1 之间。这可能会导致问题,尽管我检查模拟以确保 x1 在 0 和 1 之间,并且除了 x1 时之外不会引发问题是南。无论如何,是否可以为迭代尝试 x1 的值设置一个范围?有人知道使用 nan 作为 x1 的迭代会尝试什么吗?
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_multiroots.h>
struct rparams{
double target1;
};
int function(const gsl_vector * x, void *params, gsl_vector * f);
int main(int argc, char* argv[]) {
double target1;
sscanf(argv[1],"%lf",&target1);
const gsl_multiroot_fsolver_type *T;
gsl_multiroot_fsolver *s;
int status;
unsigned int iter …Run Code Online (Sandbox Code Playgroud) 我刚刚更新到最新的 OSX El Capitan,但在编译 C 程序时遇到问题。在操作系统升级之前它编译得很好。之后我就收到了一条关于我的 LaTeX 文本编辑器 Latexian 的警告消息:
但由于我不在程序内使用预览或编译,并在终端中使用“latex file.tex”进行编译,因此工作正常。
现在我的问题是我的 .c 程序,其中包含 GSL 库之一,这是我的标头:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
Run Code Online (Sandbox Code Playgroud)
编译时我得到以下信息:
performance.c:4:10: fatal error: 'gsl/gsl_rng.h' file not found
#include <gsl/gsl_rng.h>
^
1 error generated.
Run Code Online (Sandbox Code Playgroud)
我猜由于这两种情况,OSX 中发生了一些变化,但后者对我来说是一个大问题,因为我正在完成我的论文!希望我的问题很清楚,这是我的第一个问题。
编辑:
我猜这就是问题所在
我知道以前有人问过这个问题,但我没有找到有用的解决方案。完整的错误是:
Executing: "/home/mint/Documents/test_sensor/cycl_test/top_block.py"
Using Volk machine: avx_64_mmx_orc
Traceback (most recent call last):
File "/home/mint/Documents/test_sensor/cycl_test/top_block.py", line 87, in <module>
tb = top_block()
File "/home/mint/Documents/test_sensor/cycl_test/top_block.py", line 61, in __init__
self.cycl_MME_cpp_0 = cycl.MME_cpp(1000, 16, 0.1)
AttributeError: 'module' object has no attribute 'MME_cpp'
Run Code Online (Sandbox Code Playgroud)
我从之前的问题中找到了一些可能的原因:
函数参数不匹配(包括 .cc 和 .h 中的引用函数)
喝水问题
.xml 文件中的回调
nm -C -u libgnuradio-.so
我已经检查了前 3 个原因,但我不确定如何使用最后一个方法找出未定义的符号。结果有一部分:
U gsl_linalg_SV_decomp
U gsl_matrix_alloc
U gsl_matrix_set
U gsl_matrix_set_zero
U gsl_vector_alloc
U gsl_vector_get
Run Code Online (Sandbox Code Playgroud)
这是否意味着所有 gsl 函数都未定义?如果是这样,我该如何处理?
除了这四个原因,我的问题还有其他提示吗?
我感谢您的帮助。
附录:
1.MME_cpp_impl.cc
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include …Run Code Online (Sandbox Code Playgroud) 我只是尝试在 C++ 中集成一个函数。我一直在尝试使用 gsl,因为我在网上看到了这个推荐。我遵循了 gsl 示例,但收效甚微。
这是我的 C++ 代码:
double inverseE(double z){
double inverseE = 1.0/(std::sqrt(Om0*std::pow(1.0+z,3.0)+1.0-Om0));
return inverseE;
}
double comoving_distance(double z){
gsl_integration_workspace * w
= gsl_integration_workspace_alloc (1000);
double result, error;
gsl_function iE;
iE.function = &inverseE;
gsl_integration_qags (&iE, 0, z, 0, 1e-7, 1000,
w, &result, &error);
gsl_integration_workspace_free (w);
cout << result << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为了澄清起见,Python 中的相同代码(有效)如下所示:
def iE(z):
return 1/(np.sqrt(Om0*np.power(1+z,3)+1-Om0))
def comoving_distance(z):
return (c/H0)*quad(iE,0,z)[0]
Run Code Online (Sandbox Code Playgroud)
quad 执行集成的地方(它是一个 scipy 模块)。
我收到两条错误消息:
ISO C++ 禁止将未限定的或带括号的非静态成员函数的地址作为指向成员函数的指针。说 '&cosmo::inverseE' [-fpermissive]
不能在赋值中将'double (cosmo:: …
我有一个函数,它要求返回类型是一个容器。问题是我需要尽可能有效地集成容器的内容,并希望使用自适应 Gauss-Kronrod 集成或同样有效(或更好)的方法。
我希望使用 GNU Scientific Library 正交例程 qags,但它返回的结果是 double 类型。就目前情况而言,我认为我可能不得不重写 GSL 正交例程的部分以将返回类型转换为 std 向量,但这将是一个相当冗长且可能容易出错的弯路。我希望有人可以推荐更好的解决方案!
下面是我试图整合的那种函数的例子,目前使用基本的梯形规则,但表明我更喜欢在哪里实现 GSL 例程 gaq。虽然它比我的实际问题简单得多,但它表明放入向量中的每个元素都是根据先前的结果计算的,因此需要容器。
#include <iostream>
#include <vector>
#include <gsl/gsl_integration.h>
using namespace std;
vector<double> f(double E, int N) {
vector<double> result;
result.reserve(N);
double x = E;
for (int it=0; it < N; ++it){
result.push_back(x);
x *= x;
}
return result;
}
vector<double> f_qag(double E, void * params) {
int N = *(int *) params;
vector<double> result;
result.reserve(N);
double x = E;
for (int it=0; it …Run Code Online (Sandbox Code Playgroud) 当启用未定义的消毒剂时,我在 GNU 科学库 (GSL) 中发现了一个运行时错误:
deque.c:58:11: runtime error: member access within misaligned address 0x0000024010f4 for type 'struct deque', which requires 8 byte alignment
0x0000024010f4: note: pointer points here
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^
deque.c:59:11: runtime error: member access within misaligned address 0x0000024010f4 for type 'struct deque', which requires 8 byte alignment
0x0000024010f4: …Run Code Online (Sandbox Code Playgroud) 我正在尝试从C中重新定义R中的一些代码,所以我试图使用该gsl_fit_linear()函数拟合线性回归.
在R中,我使用lm()函数,它使用以下代码返回拟合的p值:
lmAvgs<- lm( c(1.23, 11.432, 14.653, 21.6534) ~ c(1970, 1980, 1990, 2000) )
summary(lmAvgs)
Run Code Online (Sandbox Code Playgroud)
我不知道如何从C输出到p值,我的代码到目前为止看起来像这样:
int main(void)
{
int i, n = 4;
double x[4] = { 1970, 1980, 1990, 2000 };
double y[4] = {1.23, 11.432, 14.653, 21.6534};
double c0, c1, cov00, cov01, cov11, sumsq;
gsl_fit_linear (x, 1, y, 1, n, &c0, &c1, &cov00, &cov01, &cov11, &sumsq);
}
Run Code Online (Sandbox Code Playgroud)
这似乎正确计算斜率和截距,但我不知道如何获得p值.我是统计数据和C的新手!
我已按照提供的安装 GSL-1.16 库的说明进行操作,并且我认为我已成功安装了该库。但是,当我尝试编译并运行网站(http://www.gnu.org/software/gsl/manual/html_node/An-Example-Program.html#An-Example-Program)中的示例程序时,我得到以下消息:
$ gcc besel_exam.c
Undefined symbols for architecture x86_64:
"_gsl_sf_bessel_J0", referenced from:
_main in besel_exam-72d841.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
操作系统为 macOS X Yosemite,gcc --version 的输出如下:
$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix
Run Code Online (Sandbox Code Playgroud) 我正在比较 Eigen (v3.2.8) 和 GSL (v2.1) 库在各种线性代数运算中的性能。虽然在大多数操作中 Eigen 以较大优势(少数因素)获胜,但在奇异值分解的计算中它落后了。我使用了两种 SVD 实现——JacobiSVD 和 BDCSVD(后者仍然在这个版本的“不受支持”模块中),并在几个平台上测试了以下代码:
#include <gsl/gsl_rng.h>
#include <gsl/gsl_linalg.h>
#include <unsupported/Eigen/SVD>
#include <ctime>
#include <iostream>
void testSVD(const int size)
{
clock_t tbegin;
gsl_rng* rng = gsl_rng_alloc(gsl_rng_default);
gsl_rng_set(rng, 42);
Eigen::MatrixXd mat(size, size);
for(int i=0; i<size; i++)
for(int j=0; j<size; j++)
mat(i, j) = gsl_rng_uniform(rng);
gsl_matrix_view matv = gsl_matrix_view_array(mat.data(), size, size);
gsl_matrix* mat1 = &matv.matrix;
gsl_matrix* mat2 = gsl_matrix_alloc(size, size);
gsl_vector* vec1 = gsl_vector_alloc(size);
gsl_vector* vec2 = gsl_vector_alloc(size);
tbegin = std::clock();
Eigen::JacobiSVD<Eigen::MatrixXd> jac(mat, Eigen::ComputeThinU …Run Code Online (Sandbox Code Playgroud)