Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/150.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法生成C++;来源(由于图书馆?) < >为了了解C++如何处理微分方程,我尝试了在Internet教程中找到的下面的脚本。它应该会起作用 我不直接使用C++。我使用R和Rcpp库编译/运行脚本。以下是脚本: #include <iostream> #include <boost/numeric/odeint.hpp> using namespace Rcpp; using namespace std; using namespace boost::numeric::odeint; /* we solve the simple ODE x' = 3/(2t^2) + x/(2t) * with initial condition x(1) = 0. * Analytic solution is x(t) = sqrt(t) - 1/t */ void rhs( const double x , double &dxdt , const double t ) { dxdt = 3.0/(2.0*t*t) + x/(2.0*t); } void write_cout( const double &x , const double t ) { cout << t << '\t' << x << endl; } // state_type = double typedef runge_kutta_dopri5< double > stepper_type; int main() { double x = 0.0; integrate_adaptive( make_controlled( 1E-12 , 1E-12 , stepper_type () ) ,rhs , x , 1.0 , 10.0 , 0.1 , write_cout ); } #包括 #包括 使用名称空间Rcpp; 使用名称空间std; 使用名称空间boost::numeric::odeint; /*我们求解简单常微分方程x'=3/(2t^2)+x/(2t) *初始条件x(1)=0。 *解析解为x(t)=sqrt(t)-1/t */ 无效rhs(常数双x、常数双dxdt、常数双t) { dxdt=3.0/(2.0*t*t)+x/(2.0*t); } 无效写入权限(常量双精度&x,常量双精度) { cout_C++_Windows_Rcpp - Fatal编程技术网

无法生成C++;来源(由于图书馆?) < >为了了解C++如何处理微分方程,我尝试了在Internet教程中找到的下面的脚本。它应该会起作用 我不直接使用C++。我使用R和Rcpp库编译/运行脚本。以下是脚本: #include <iostream> #include <boost/numeric/odeint.hpp> using namespace Rcpp; using namespace std; using namespace boost::numeric::odeint; /* we solve the simple ODE x' = 3/(2t^2) + x/(2t) * with initial condition x(1) = 0. * Analytic solution is x(t) = sqrt(t) - 1/t */ void rhs( const double x , double &dxdt , const double t ) { dxdt = 3.0/(2.0*t*t) + x/(2.0*t); } void write_cout( const double &x , const double t ) { cout << t << '\t' << x << endl; } // state_type = double typedef runge_kutta_dopri5< double > stepper_type; int main() { double x = 0.0; integrate_adaptive( make_controlled( 1E-12 , 1E-12 , stepper_type () ) ,rhs , x , 1.0 , 10.0 , 0.1 , write_cout ); } #包括 #包括 使用名称空间Rcpp; 使用名称空间std; 使用名称空间boost::numeric::odeint; /*我们求解简单常微分方程x'=3/(2t^2)+x/(2t) *初始条件x(1)=0。 *解析解为x(t)=sqrt(t)-1/t */ 无效rhs(常数双x、常数双dxdt、常数双t) { dxdt=3.0/(2.0*t*t)+x/(2.0*t); } 无效写入权限(常量双精度&x,常量双精度) { cout

无法生成C++;来源(由于图书馆?) < >为了了解C++如何处理微分方程,我尝试了在Internet教程中找到的下面的脚本。它应该会起作用 我不直接使用C++。我使用R和Rcpp库编译/运行脚本。以下是脚本: #include <iostream> #include <boost/numeric/odeint.hpp> using namespace Rcpp; using namespace std; using namespace boost::numeric::odeint; /* we solve the simple ODE x' = 3/(2t^2) + x/(2t) * with initial condition x(1) = 0. * Analytic solution is x(t) = sqrt(t) - 1/t */ void rhs( const double x , double &dxdt , const double t ) { dxdt = 3.0/(2.0*t*t) + x/(2.0*t); } void write_cout( const double &x , const double t ) { cout << t << '\t' << x << endl; } // state_type = double typedef runge_kutta_dopri5< double > stepper_type; int main() { double x = 0.0; integrate_adaptive( make_controlled( 1E-12 , 1E-12 , stepper_type () ) ,rhs , x , 1.0 , 10.0 , 0.1 , write_cout ); } #包括 #包括 使用名称空间Rcpp; 使用名称空间std; 使用名称空间boost::numeric::odeint; /*我们求解简单常微分方程x'=3/(2t^2)+x/(2t) *初始条件x(1)=0。 *解析解为x(t)=sqrt(t)-1/t */ 无效rhs(常数双x、常数双dxdt、常数双t) { dxdt=3.0/(2.0*t*t)+x/(2.0*t); } 无效写入权限(常量双精度&x,常量双精度) { cout,c++,windows,rcpp,C++,Windows,Rcpp,请安装boost头文件。这不是库问题 使用软件包管理器*或从boost.org下载boost解包并将标题目录/boost添加到您的include目录-I *Ubuntu上的F.e.sudo apt-y安装libboost1.65-dev 安东尼·豪瑟,忘记那些反对票吧。试试我的建议,你会没事的 假设您将其解压缩到/home/anthony/include,然后添加-I/home/anthony/include/boost-1.65或在Windows C:\Users\anthony\boost-

请安装boost头文件。这不是库问题

使用软件包管理器*或从boost.org下载boost解包并将标题目录
/boost
添加到您的include目录
-I

*Ubuntu上的F.e.
sudo apt-y安装libboost1.65-dev

安东尼·豪瑟,忘记那些反对票吧。试试我的建议,你会没事的

假设您将其解压缩到/home/anthony/include,然后添加-I/home/anthony/include/boost-1.65或在Windows C:\Users\anthony\boost-add-ic:\Users\anthony\boost\boost-1.65上,您有多个严重错误:

  • 您想从R调用它,但没有Rcpp接口
  • 从R调用的代码不能有
    main()
  • 无Boost头:您需要安装包
更正了下面的代码

代码 这个版本的代码可以工作并运行示例。我在其中添加了一些注释

// include Rcpp, it takes care of most other headers you need
#include <Rcpp.h>

// include Boost's odeint
#include <boost/numeric/odeint.hpp>

// tell R you need Boost
// [[Rcpp::depends(BH)]]

using namespace Rcpp;
using namespace std;
using namespace boost::numeric::odeint;


/* we solve the simple ODE x' = 3/(2t^2) + x/(2t)
* with initial condition x(1) = 0.
* Analytic solution is x(t) = sqrt(t) - 1/t
*/

void rhs( const double x , double &dxdt , const double t ) {
  dxdt = 3.0/(2.0*t*t) + x/(2.0*t);
}

void write_cout( const double &x , const double t ) {
  // use Rcpp's stream
  Rcpp::Rcout << t << '\t' << x << endl;
}

// state_type = double
typedef runge_kutta_dopri5< double > stepper_type;

// call this from R
// [[Rcpp::export]]
bool boostExample() {
  double x = 0.0;    
  integrate_adaptive(make_controlled( 1E-12 , 1E-12 , stepper_type () ) ,
                     rhs , x , 1.0 , 10.0 , 0.1 , write_cout );
  return true;
}

/*** R
boostExample()                  // call from R
*/

看起来您没有安装boost库。这是一个编译错误,而不是链接错误。boost numeric是一个纯头库。这意味着当编译器试图编译您的程序(即ex1.cpp)时,它会在行号
2
处找到
\include
。它所做的是在搜索文件之后(即,
odeint.hpp
),它在指定的位置找不到它。因此,您需要获取文件并将其放在正确的位置。@热爱编码。是的,它找不到odeint.hpp文件。我如何知道正确的位置?有人能解释否决票吗?人们怎么了?这是一个不成熟的答案。我们还没有完全澄清这个问题,我们会例如,我们不知道OP的操作系统(如果是Ubuntu,我们已经知道了)你的一般答案只不过是一个.Crazy。注释是错误的。你不需要为odeint.h安装库。这纯粹是boost的一个标题部分。如果他接受我的建议,他会在几分钟内完成。问题是,有几个复杂的人真的与世界有矛盾。天哪!Running
apt install libboost1.65-dev
正在安装库。@KavehVahedipour库不需要编译代码。它可以是头文件,就像大部分Boost一样。库在这里被用作通用术语,意思是“一些打包的例程供您使用”谢谢Drk。我的脚本仍然不起作用。这里的错误信息:致命错误:Booost /Multic /ODETIN。HPP:没有这样的文件或目录。所以我想我应该安装名为Boost的C++库,对吗?我说你需要安装并提供一个链接。Ie做代码>安装。包(BH)安装此R软件包,就像您对Rcpp所做的那样。我确实安装了BH软件包,但仍然出现了错误。然后您又犯了其他错误。我向您展示了一个工作正常的示例。BH在Windows上工作,并由CRAN进行了测试。我想您的示例中有一个输入错误。我将“/[[Rcpp::Dependes(BH)]”改为“//”[[Rcpp::dependens(BH)]“它是有效的,对吗?
// include Rcpp, it takes care of most other headers you need
#include <Rcpp.h>

// include Boost's odeint
#include <boost/numeric/odeint.hpp>

// tell R you need Boost
// [[Rcpp::depends(BH)]]

using namespace Rcpp;
using namespace std;
using namespace boost::numeric::odeint;


/* we solve the simple ODE x' = 3/(2t^2) + x/(2t)
* with initial condition x(1) = 0.
* Analytic solution is x(t) = sqrt(t) - 1/t
*/

void rhs( const double x , double &dxdt , const double t ) {
  dxdt = 3.0/(2.0*t*t) + x/(2.0*t);
}

void write_cout( const double &x , const double t ) {
  // use Rcpp's stream
  Rcpp::Rcout << t << '\t' << x << endl;
}

// state_type = double
typedef runge_kutta_dopri5< double > stepper_type;

// call this from R
// [[Rcpp::export]]
bool boostExample() {
  double x = 0.0;    
  integrate_adaptive(make_controlled( 1E-12 , 1E-12 , stepper_type () ) ,
                     rhs , x , 1.0 , 10.0 , 0.1 , write_cout );
  return true;
}

/*** R
boostExample()                  // call from R
*/
R> sourceCpp("/tmp/sobh.cpp")

R> boostExample()                  
1   0
1.00843 0.0125618
1.0197  0.0291282
1.03098 0.0454238
1.04226 0.061457
1.05409 0.0779974
1.06591 0.0942666
1.07774 0.110273
1.09015 0.126803
1.10257 0.14306
1.11498 0.159055
1.12802 0.175574
1.14106 0.191821
1.15409 0.207804
1.16778 0.224315
1.18147 0.240553
1.19516 0.256527
1.20954 0.273032
1.22392 0.289264
1.2383  0.305233
1.25341 0.321735
1.26852 0.337966
1.28414 0.354468
1.29976 0.370699
1.31591 0.387205
1.33207 0.403439
1.34877 0.419952
1.36548 0.436192
1.38276 0.452714
1.40004 0.468964
1.41791 0.485498
1.43579 0.501761
1.45428 0.518311
1.47278 0.534589
1.49191 0.551159
1.51105 0.567457
1.53086 0.58405
1.55067 0.600373
1.57117 0.616993
1.59167 0.633343
1.6129  0.649996
1.63412 0.666378
1.6561  0.683067
1.67808 0.699487
1.70084 0.716217
1.7236  0.732678
1.74718 0.749455
1.77075 0.765963
1.79517 0.782792
1.8196  0.799352
1.8449  0.816238
1.87021 0.832857
1.89643 0.849806
1.92266 0.866487
1.94984 0.883505
1.97702 0.900256
2.0052  0.91735
2.03338 0.934176
2.0626  0.951351
2.09182 0.96826
2.12212 0.985523
2.15242 1.00252
2.18385 1.01988
2.21528 1.03697
2.24789 1.05443
2.28049 1.07163
2.31432 1.0892
2.34816 1.1065
2.38327 1.12419
2.41838 1.14161
2.45482 1.15943
2.49127 1.17697
2.5291  1.19492
2.56694 1.2126
2.60622 1.23068
2.64551 1.2485
2.68631 1.26674
2.72711 1.28471
2.7695  1.3031
2.81188 1.32123
2.85591 1.33979
2.89994 1.35809
2.9457  1.37682
2.99145 1.39529
3.039   1.41422
3.08655 1.43287
3.13598 1.45199
3.18541 1.47084
3.23679 1.49016
3.28818 1.50921
3.34162 1.52875
3.39505 1.54802
3.45062 1.56778
3.50619 1.58727
3.56399 1.60727
3.6218  1.627
3.68193 1.64724
3.74206 1.66721
3.80463 1.68771
3.8672  1.70794
3.93231 1.7287
3.99743 1.7492
4.0652  1.77024
4.13297 1.79101
4.20352 1.81235
4.27406 1.83341
4.34751 1.85505
4.42096 1.87641
4.49744 1.89837
4.57392 1.92004
4.65356 1.94232
4.7332  1.96432
4.81615 1.98694
4.89911 2.00927
4.98551 2.03225
5.07192 2.05493
5.16194 2.07826
5.25196 2.10131
5.34575 2.12502
5.43953 2.14844
5.53726 2.17254
5.63499 2.19635
5.73684 2.22086
5.83868 2.24507
5.94483 2.26999
6.05097 2.29461
6.16161 2.31996
6.27224 2.34501
6.38757 2.37081
6.50289 2.3963
6.62311 2.42255
6.74334 2.4485
6.86867 2.47523
6.99401 2.50164
7.12469 2.52885
7.25537 2.55575
7.39162 2.58347
7.52788 2.61086
7.66995 2.63909
7.81203 2.66699
7.96018 2.69575
8.10834 2.72418
8.26284 2.75349
8.41733 2.78246
8.57845 2.81233
8.73957 2.84185
8.9076  2.8723
9.07562 2.90239
9.25086 2.93342
9.4261  2.96411
9.60886 2.99575
9.79162 3.02703
9.98222 3.05929
10  3.06228
[1] TRUE
R>