// NOTE: 向量函数的雅可比矩阵 // C++ includes #include // autodiff include #include #include using namespace autodiff; // The vector function for which the Jacobian is needed VectorXreal f(const VectorXreal& x) { return x * x.sum(); } int main() { using Eigen::MatrixXd; VectorXreal x(5); // the input vector x with 5 variables x << 1, 2, 3, 4, 5; // x = [1, 2, 3, 4, 5] VectorXreal F; // the output vector F = f(x) evaluated together with Jacobian matrix below MatrixXd J1 = jacobian(f, wrt(x), at(x), F); // evaluate the output vector F and the Jacobian matrix dF/dx std::cout << "F = \n" << F << std::endl; // print the evaluated output vector F std::cout << "J1 = \n" << J1 << std::endl; // print the evaluated Jacobian matrix dF/dx MatrixXd J2 = jacobian(f, wrt(x), at(x)); std::cout << "J2 = \n" << J2 << std::endl; // print the evaluated Jacobian matrix dF/dx }