[英]How do I access functions in a third party source file?
I was looking for an algorithm that would enable me to use the mathematical Bessel function for complex numbers. 我一直在寻找一种算法,使我能够对复数使用数学贝塞尔函数。 Now I have found a promising result . 现在我找到了可喜的结果 。 (I'm interested in Bessel functions Jv and Yv for real or complex arguments and real order .) (我对Bessel函数Jv和Yv的实数或复数实数和实数顺序感兴趣。)
I am working in Visual Studio 2010 Express C++ and now I want to get access to those functions implemented there. 我正在使用Visual Studio 2010 Express C ++,现在我想访问其中实现的那些功能。 How do I do that? 我怎么做?
Download this http://www.crbond.com/download/bessel.zip file and add the files to your visual studio project. 下载此http://www.crbond.com/download/bessel.zip文件,并将文件添加到Visual Studio项目中。 To use the functions, you will need to #include "BESSEL.h"
to your source file. 要使用这些功能,您需要在源文件中#include "BESSEL.h"
。
I got it compile on Visual Studio by doing the following 我通过执行以下操作在Visual Studio上对其进行了编译
_USE_MATH_DEFINES
to preprocessor definitions. 将_USE_MATH_DEFINES
添加到预处理程序定义中。 #include <complex.h>
to #include <complex>
将#include <complex.h>
更改为#include <complex>
using namespace std;
using namespace std;
添加using namespace std;
to BESSEL.H
前往BESSEL.H
Example of how to call a function: 如何调用函数的示例:
#include "BESSEL.H"
#include <iostream>
int main() {
double x, i0, i1, k0, k1, i0p, i1p, k0p, k1p;
x = 5.0;
i0 = 1.0;
i1 = 2.0;
k0 = 3.0;
k1 = 4.0;
i0p = 5.0;
i1p = 6.0;
k0p = 7.0;
k1p = 8.0;
bessik01a(x, i0, i1, k0, k1, i0p, i1p, k0p, k1p);
// Results are stored in the variables i0..k1p
cout << i0 << " " << i1 << " " << k0 << " " << k1;
return 0;
}
Add the files linked above to your project: 将上面链接的文件添加到您的项目中:
Note you have to edit out old header files in these .cpp files and .h file. 请注意,您必须在这些.cpp文件和.h文件中编辑掉旧的头文件。 More specific: change 更具体:变更
#include<complex.h>
to 至
#include<complex>
and use namespace std. 并使用命名空间std。 Also for math.h
. 也适用于math.h
In main.cpp as in picture above write: 在main.cpp中,如上图所示:
#include <iostream>
using namespace std;
#include "BESSEL.H"
int main ()
{
complex<double> z = 3;
complex<double> J0;
complex<double> J1;
complex<double> Y0;
complex<double> Y1;
complex<double> J0p;
complex<double> J1p;
complex<double> Y0p;
complex<double> Y1p;
cbessjy01(z,J0,J1,Y0,Y1,J0p,J1p,Y0p,Y1p);
cout<< "J0: " << J0 << "\n";
cout<< "J0p: " << J0p << "\n";
cout<< "J1: " << J1 << "\n";
cout<< "J1p: " << J1p << "\n";
cout<< "Y0: " << Y0 << "\n";
cout<< "Y0p: " << Y0p << "\n";
cout<< "Y1: " << Y1 << "\n";
cout<< "Y1p: " << Y1p << "\n";
cin.get();
return 0;
}
Try to run the program. 尝试运行该程序。 z
is the argument for the bessel function. z
是贝塞尔函数的参数。
You may ask what are J0
, J1
, etc they are the Bessel functions but if you need to detremine which is which try a numerical value in the formulas you have. 您可能会问什么是J0
, J1
等,它们是Bessel函数,但是如果需要确定,这是您可以尝试的公式中的数值。 for example check J0 is the result of which formula. 例如,检查J0是哪个公式的结果。 I'm not an expert in Bessel functions. 我不是贝塞尔函数专家。 But if you give me the exact formulas you need to use I can test. 但是,如果您给我确切的公式,则可以测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.