- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在使用 GSL 集成包 (gsl_integration.h) 尝试在某个限制 [a,b] 之间对一些关于 x 的多变量函数 f(x,y,z) 进行积分。在这个例子中,我有一个玩具模型:f(x,y,z) = xyz
我想用一个函数输出这个积分的结果
double integral(double a, double b, double y, double z){}
在这一点之前,我可以让 y 和 z 保持任意。到目前为止,我的尝试主要涉及将 y、z 设置为某个预定义函数中的常数,然后使用
gsl_integration_qags
集成该功能的功能。但是,我想保留 y 和 z 的任意值,直到我在上面的函数中定义它们。到目前为止我得到的最接近的如下
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <gsl/gsl_integration.h>
#include<stdio.h>
#include<math.h>
#define PI 3.1415926535897
double integrand(double x, void * params){
double y = *(double *) params;
double z = *(double *) params; // PROBLEM: this just sets z = y
double tmp = x*z*y;
return tmp;
}
double integral(double a, double b, double y, double z){
gsl_integration_workspace * w
= gsl_integration_workspace_alloc (1000);
gsl_function F;
F.function = &integrand; // Set integrand
F.params = &y, &z; // Set the parameters you wish to treat as constant in the integration
double result, error;
gsl_integration_qags (&F, a, b, 0, 1e-7, 1000,
w, &result, &error);
gsl_integration_workspace_free (w); // Free the memory
return result;
}
int main(){
std::cout << "Result "<< integral(0.0,1.0,3.0,5.0)<<std::endl;
}
这给出了输出
Result 4.5
代码设置 a = 0.0, b = 1.0, y = z = 3.0 -- 我想要 a = 0.0, b = 1.0, y = 3.0, z = 5.0,结果为 7.5。
如果可能的话,我想坚持使用 GSL 集成而不是提升。我也咨询过https://www.gnu.org/software/gsl/doc/html/integration.html但我一点也不聪明。任何建议将不胜感激,谢谢。
最佳答案
我正在猜测,但在我看来你想要
double params[] = { y, z };
F.params = params;
和
double y = ((double *)params)[0];
double z = ((double *)params)[1];
关于c++ - gsl多变量数值积分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51365545/
我正在编写一些代码,其中使用了一些 GNU GSL 函数。 出于纯粹的兴趣,我想知道这些功能是如何实现的,因此我想看看源代码。 问题是我似乎无法找到它所在的目录。 我知道我可以在“/usr/local
我需要计算 ∫ [x₁ to x₂] 1/√(1-k² sinh²(x)) dx 在我的程序中。这可以使用在复数参数中评估的第一类不完全椭圆积分来表示: -i (F(ix₂ | -k²) - F(ix
brew install gsl - 没问题 快速制作一个使用 gsl 的 Mac 应用程序,以检查它是否正常工作。 ( Handy example here. ) - 没问题 它们在/include
给定以下函数,采用:只读 float 跨度(动态或任何静态大小): template void foobar(gsl::span x); 假设我有一个 vector .将其作为参数传递是行不通的,但
C++ Core Guidelines促进实践using span . 问题在于 const 和可变范围。这是我尝试做的: auto foo(gsl::span); // 1st au
我正在尝试获取一个名为 emergent 的软件在职的。它依赖于我已经安装的 qt 和 coin。 但是当我尝试运行 emergent 时,出现以下错误: dyld: Library not load
假设我有一个成员变量std::vector在一个类中,我想使用 gsl::array_view 的组合从成员函数返回它作为不可变 View 和 gsl::cstring_view .不幸的是,以下内容
我正在尝试计算两个 vector a 和 b 之间的马氏距离。最终,我将使用它作为统计算法中的距离度量。我正在使用 gsl 来实现它们。马氏距离的公式是 sqrt((a-b)'c^-1(a-b)),其
我正在将指南支持库检查器集成到我的项目中。 Microsoft.CppCoreCheck Microsoft.Gsl 当我运行它时,我从包含的库(如标准库、glm、boost 等)中收到一堆错误。 一
我记得读过 mat4x3 比 mat3x4 使用了更多的寄存器,因为它有四列,即使它们具有相同数量的元素。我似乎无法在任何地方找到它了。新规范是否对两种类型的矩阵使用相同数量的统一寄存器? 转置是否也
我想使用 GSL 的统一随机数生成器。在他们的网站上,他们包含以下示例代码: #include #include int main (void) { const gsl_rng_t
我最近安装了 GSL,用于我的计算作业。我从预构建的库安装了它,并将其链接到 CodeBlocks,然后运行 GSL(贝塞尔函数)的测试示例以确保它有效。一切都很顺利。 然后我尝试了这里给出的线性
我现在正在与 GSL 合作。我在寻找特征值时遇到一些问题。在对称矩阵的情况下,GSL 似乎没有正确给出特征值。我给出了某些对称矩阵的输入,这些矩阵的特征值应该为 0,但是,GSL 函数返回非零特征值来
构建后: $ gcc generator.c -lm -lgsl -lgslcblas -lm 代码: #include #include gsl_rng * r; /* global gene
我正在使用 GSL 进行大量三次样条插值。假设我有三个自变量 a、b 和 c,所有变量都在相同的物理数据点上制表(可能是同一组位置)以米、英尺和英里为单位),以及两个因变量 y 和 z,在相同点处制表
我目前正在尝试在另一个自己编写的库(Quaternion.c)中使用我之前编写的库(matrix.c),方法是使用使用“matrix.h”的标准方法通过头文件调用它”包含“matrix.c”文件中的函
我正在尝试更新旧代码,该代码使用的是具有已弃用函数的 GSL 版本,但我在寻找如何使用新版本的归一化勒让德多项式函数时遇到了麻烦。这是总结问题的片段: #include #include #inc
我正在使用 GSL 示例页面上的代码来尝试求解一个包含四个微分方程的系统。我一直在努力将五个参数传递给 ODE 系统,并且遇到了一个最终的(我希望!)编译时错误。下面是一个片段,给我错误 114:57
我已经在 Kubuntu 14.04 中安装了最新版本的 GSL (1.16)。我使用库附带的文件 INSTALL(逐步)进行安装。我配置了 eclipse-cdt 环境以供使用。它工作,我认为,因为
我有一个非常简单的问题——我只想在 C 语言的 gsl 中将两个具有复杂条目的矩阵相乘。例如,我想定义一个函数 gsl_matrix_complex *multiply( gsl_matrix_com
我是一名优秀的程序员,十分优秀!