Numerical (finite difference) and analytic (symbolic toolbox) derivative do not agree.
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a rather complicated function (6 free variables and 1 fixed variable) that I am trying to find the jacobian of. I know of 2 ways to do this: analytically and numerically.
Using the symbolic toolbox I calculated the derivative of the function w.r.t each of the 6 free variables, and then plugged in specific values for all variables to find the value of the derivative at that point.
I also tried to find each of these derivative using a simple 1st order forward difference scheme, where i look at the difference between a "baseline" value at some specific variable values and a "perturbed" value where one of the free variables has been change slightly. (i.e.: (f(x0+dx)-f(x0))/dx). I have tried many values for the "dx" perturbation and get similiar results.
My issue is that the results of the symbolic derivative and the finite difference derivative do not entirely agree. To make matters stranger, they agree perfectly for 2 (of the 6) derivatives, they are off by a scale factor (in the range of 2-3x) for another 2 of the derivatives, and they are completely different for the last 2 derivatives (except in the spacial case where the addition "fixed variable" I mentioned is set to zero).
Has anyone encountered something like this before? I have thoroughly checked the codes for errors and have literally re-wrote new versions of them without fixing this issue (that said an error still isnt out of the question). Unfortunately the expression in question is much too long to check by hand (well over 1000 individual operations), so I am stuck relying on a computer to solve for these derivatives.
I would greatly appreciate any suggestions. Thanks!
1 comentario
John D'Errico
el 22 de Jun. de 2016
So, you've made a mistake somewhere. Or perhaps your estimate using the finite difference scheme has a problem. How can we know what you have done wrong?
Are you asking if others have found that finite differences do not work? Or that symbolic differentiation fails? In both cases, these are pretty basic things. In fact, I can pretty confidently claim that your code has a problem. You have done something wrong.
You might consider the idea of using my derivest tools to check your work. It is on the file exchange. However, I wonder if you are having a difficult time getting a basic finite difference approximation to come even close, that there is some problem in your code that would likely cause that to fail too.
Respuestas (0)
Ver también
Categorías
Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!