1
$\begingroup$

Please help me to determine the Jacobian matrix of $n$ functions with $n$ parameters with C++. I know MATLAB has the possibility to determine the Jacobian matrix by using jacobian(f,v), but I have to use C++.

I will appreciate your help.

  • 2
    The [Jacobian matrix](http://en.wikipedia.org/wiki/Jacobian_matrix_and_determinant) consists of the partial derivatives of the functions with respect to their arguments, so what you're really asking is "How do I calculate the derivative of a function in C++?" A quick Google search turned up [this](http://stackoverflow.com/questions/422594/derivatives-in-c-c) and [this](http://stackoverflow.com/questions/1559695/implementing-the-derivative-in-c-c) StackOverflow question which might be relevant to that.2011-07-24

2 Answers 2

4

This is not an easy task, and I wonder whether or not you should also ask at StackOverflow. You certainly do not want to hardcode symbolic derivatives in C++ all by your lonesome, so I would recommend reading the following sources.

Automatic Differentiation has a great set of C/C++ toolkits designed specifically for automatic differentiation (creatively titled, of course). I have also read that many people embed different bits within their code, like maxima. Finally, the source code for this symbolic differentiation software is freely available, and can likely be adapted to suit your needs.

I hope this helps!

  • 0
    ... you're supposed to feed the routine to "differentiate" into the software linked to, and then you get the corresponding Jacobian routine, @solarium.2011-07-27
0

For c++, have a look at Eigen's numerical differentiation module. I personally only used the nonlinear solvers from Eigen, but they use the same numerical differentiation module to evaluate the jacobian numerically).

  • 0
    For 2: Stiff DEs are a different application of Jacobian computations, where exact Jacobians are required. For 1... that was a slip up; I should have said "Broyden's method" which is for nonlinear equations as opposed to optimization. That method constructs Jacobian approximations through rank-1 corrections, not through finite differences.2011-07-31