Example of forward-mode automatic differentiation.
#include <cmath>
#include <iomanip>
#include <iostream>
#include "xexp.h"
auto main() -> int {
const variable<double> var = create_diff_variable(1.234);
const variable<double> val = xexp(var);
constexpr int precision = 15;
std::cout << std::setprecision(precision);
std::cout << "Value: " << val.value() << std::endl;
std::cout << "Derivative: " << val.diff() << std::endl;
std::cout << "Reference: "
<< std::exp(var.value()) + var.value() * std::exp(var.value())
<< std::endl;
return 0;
}
Class of variables in forward-mode automatic differentiation kubota1998.
Definition of create_diff_variable function.
Definition of variable class.
Definition of mathematical functions for variable class.
auto create_diff_variable(const Value &value) -> variable< Value >
Create a variable by which functions will be differentiated (for scalar differential coefficients).