#include #include // Select ADOL-C version here. // Behaviour is the same for 2.5.x and 2.4.x versions. #define ADOLC_VERSION_MAJOR 2 #define ADOLC_VERSION_MINOR 5 #if ADOLC_VERSION_MAJOR==2 && ADOLC_VERSION_MINOR<=4 #define ADOLC_TAPELESS #define NUMBER_DIRECTIONS 2 # define TAPELESS # undef SAFE #include ADOLC_TAPELESS_UNIQUE_INTERNALS #elif ADOLC_VERSION_MAJOR==2 && ADOLC_VERSION_MINOR>=5 #include #endif typedef adtl::adouble adouble; void check(double xv, double ev) { adouble y(0.0); adouble x(xv); adouble e(ev); y.setADValue(0, 0.0); y.setADValue(1, 0.0); x.setADValue(0, 1.0); x.setADValue(1, 0.0); e.setADValue(0, 0.0); e.setADValue(1, 1.0); y = pow(x,e); std::cout << "x = " << x.getValue() << ", e = " << e.getValue() << std::endl; std::cout << "y = " << y.getValue() << std::endl; std::cout << "dy/dx = " << y.getADValue(0) << std::endl; std::cout << "dy/de = " << y.getADValue(1) << std::endl; } int main(int argc, char** argv) { adtl::setNumDir(2); check(0.0, 0.0); std::cout << "======================" << std::endl; check(1.0, 0.0); std::cout << "======================" << std::endl; check(0.0, 1.0); std::cout << "======================" << std::endl; check(1.0, 1.0); return 0; }