我正在尝试使用该autodiff
包。
我试图实现他们的第一个例子。我的代码如下:
#include <iostream>
// autodiff include
#include <autodiff/forward/dual.hpp>
using namespace autodiff;
// The single-variable function for which derivatives are needed
dual f(dual x)
{
return 1 + x + x*x + 1/x + log(x);
}
int main()
{
dual x = 2.0; // the input variable x
dual u = f(x); // the output variable u
double dudx = derivative(f, wrt(x), at(x)); // evaluate the derivative du/dx
std::cout << "u = " << u << std::endl; // print the evaluated output u
std::cout << "du/dx = " << dudx << std::endl; // print the evaluated derivative du/dx
}
我从我的 Ubuntu 终端使用 编译它g++ autodiff2.cpp -std=c++1z
,但出现以下错误:
autodiff2.cpp:4:10: fatal error: autodiff/forward/dual.hpp: No such file or directory
4 | #include <autodiff/forward/dual.hpp>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
我该如何解决这个问题?