Example of backward-mode automatic differentiation.
#include <cmath>
#include <iomanip>
#include <iostream>
#include "xexp.h"
auto main() -> int {
const auto var = variable<double>(1.234, variable_tag());
const variable<double> val = xexp(var);
const double derivative = differentiate(val, var);
constexpr int precision = 15;
std::cout << std::setprecision(precision);
std::cout << "Value: " << val.value() << std::endl;
std::cout << "Derivative: " << derivative << std::endl;
std::cout << "Reference: "
<< std::exp(var.value()) + var.value() * std::exp(var.value())
<< std::endl;
return 0;
}
Definition of node class.
Definition of mathematical functions for variable class.
Class of variables in backward-mode automatic differentiation kubota1998.
Definition of differentiate function.
auto differentiate(const variable< Scalar > &func_value, const variable< Scalar > &arg) -> Scalar
Compute a differential coefficient.
Tag class to specify variables.