Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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.

share|improve this question
The Jacobian matrix 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 and this StackOverflow question which might be relevant to that. –  Ilmari Karonen Jul 24 '11 at 22:47
add comment

2 Answers

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!

share|improve this answer
+1; additionally, I'd like to point out that Andreas Griewank and others have done a fair bit of work in this area; see for instance this article and this book. –  J. M. Jul 25 '11 at 4:07
Thank you for your help. But I can not understand how can I use this in xcode to determine the jacobian matrix? –  solarium Jul 26 '11 at 23:04
... you're supposed to feed the routine to "differentiate" into the software linked to, and then you get the corresponding Jacobian routine, @solarium. –  J. M. Jul 27 '11 at 6:15
add comment

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).

share|improve this answer
Numerical differentiation might be appropriate for nonlinear equations (but then methods like BFGS or CG which don't need numerical Jacobians might be more competitive), but not so much for solving stiff DEs... –  J. M. Jul 30 '11 at 21:36
Can you clarify that? 1. To my knowedge both CG and BFGS need to evaluate/numerically approximate gradients to know the direction in which to move. 2. I don't see how the question implies that the problem is stiff. –  eudoxos Jul 31 '11 at 8:09
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. –  J. M. Jul 31 '11 at 11:45
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.