views:

2010

answers:

10

I am looking for a method to compute a derivate using a discrete and fast method. Since now I do not know the type of equation I have, I am looking for discrete methods analog to the ones that we can find for the integral such as, the Euler method.

Thanks a lot.

A: 

I'll assume that your function is more complex than the simple one you posted, because the closed-form solution is far too simple.

When you use the word "discrete" it makes me think you need "finite differences". You'll need some discretization to calculate the approximation.

Df/Dx ~ (f2-f1)/(x2-x1), etc.

duffymo
+4  A: 

A simple method is to compute the change in f over a small value for each point of the derivative you're interested in. For example, to compute ∂f/∂x, you could use this:

epsilon = 1e-8
∂f/∂x(x, y, z) = (f(x+epsilon,y,z) - f(x-epsilon, y, z))/(epsilon * 2);

The other partials would be similar in y and z.

The value chosen for epsilon depends on the contents of f, the precision required, the floating point type used, and probably other things. I suggest you experiment with values for it with functions you're interested in.

Jesse Rusak
Unless you really want to dive into the floating point implementation of whatever language you happen to be using, it is hard to pick a good epsilon. But please post the weird floating point errors you find!
Joseph Holsten
+2  A: 

Short of using a symbolic math language, like Maple, the best you can do is to approximate the derivative at various points. (And then interpolate, if you need a function.)

If you've already got the function you want to use, then you should use the backward divided-difference forumla, and Richardson extrapolation to improve your error.

Also keep in mind that these methods work on functions of one variable. However, partial derivatives of each variable treat the other variables as constants.

The richardson extrapolation is useful, but why a backward divided-difference rather than a centered one?
Jesse Rusak
These seem to be two variable methods, not multivariate methods as in the question. Am I missing something? If not, I can't recommend adapting a two variable method to more variables. It's really error prone.
Joseph Holsten
+7  A: 

There is quite a bit of theory (and established practice) in calculating numerical ("finite") derivatives. Getting all the details correct, such that you believe the result, is not trivial. If there's any way you can get the analytical derivative of the function (using pen and paper, or a computer algebra system such as Maple, Mathematica, Sage, or SymPy), this is by far the best option.

If you can't get the analytical form, or you don't know the function (just it's output), then numerical estimation are your only option. This chapter in Numerical Recipies in C is a good start.

Barry Wark
Keep in mind that the code in Numerical Recipes is [not public domain][1] or open source. Copy at your own risk. [1]: http://www.nr.com/public-domain.html
Joseph Holsten
Yes, absolutely. I would not plan on pilfering code from NR in C (or any other copyrighted source). You may learn enough from reading the chapter, though, that you can write your own code ;)
Barry Wark
A: 

If the function is linear as you have indicated then the derivatives are trivial. The derivative with respect to 'x' is 'a'; the derivative with respect to 'y' is 'b' and the derivative with respect to 'z' is 'c'. If the equation is of a more complex form and you need a formula representing the solution rather than an empirical solution, then please submit the more complex form of the equation.

Regards

Howard May
+1  A: 

Formally, no. Either you are describing the (partial) derivitives of discrete functions or you are asking for a numerical method to approximate the (partial) derivatives of continuous functions.

Discrete functions don't have derivatives. If you review the epsilon-delta definition of a derivative, you will see that you would need to be able to evaluate the function close to the point you want the derivative at. That doesn't make sense if the function only has values at integer values of x, y and z. So there is no way to find the derivative of a discrete function for any value of fast.

If you want a numerical method exactly calculate the derivatives of a continuous function, you're out of luck as well. Numerical methods for derivatives are heuristic, not algorithmic. There is no numerical method which guarantees an exact solution. Fortunately, there exist many good heuristics. Mathematica uses a specialized version of Brent's principle axis method by default. I would recommend you use the GNU Scientific Library, which has a very good implementation of Brent's method. I owe my entire grade in one of my math courses to the GSL. The ruby bindings are pretty good if that's your thing. If necessary, most numerical differentiation libraries have a handful of different methods available.

If you really want, I can whip out some sample code. Let me know.

Joseph Holsten
Hi thansk a lot for all the information, I was hoping to find something simple, since it seems that there is no easy things for my question, I will adopt any other method that does not use derivatives. But thanks a lot.
Ryan
A: 

I hope this may be helpful NUMERICAL DIFFERENTIATION.

TheMachineCharmer
+4  A: 
Andrea Ambu
+2  A: 
Phil H
+2  A: 

Automatic differentiation is the most accurate and conceptually awesome way of doing this kind of thing. Just a bit more complicated.

Jay Kominek