Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!

# Method to find derivative

dhwani mathur
Ranch Hand
Posts: 621
ok
I have to find derivative of a function in java,but i am not getting which method and from which class of java package i should use.Please
if anyone has any idea your suggestions are welcome.

Peter Chase
Ranch Hand
Posts: 1970
I presume by derivative, you mean f'(x) = dy/dx, where y = f(x).

There's no function, to my knowledge, to find the derivative in Java. You won't find that in many, if any, general-purpose programming languages. You'd need something maths-specific - maybe Matlab (I don't know if it actually has this feature, but it might).

There are two completely different ways you might want your derivative.

First, you might want to do it analytically. That is, given some machine-understandable formula for f(x), it should be able to work out an exact formula for f'(x). This would only be possible for certain classes of function, for which derivatives are reasonably easy to compute analytically.

The alternative is that you might want to compute the derivative numerically, at a particular value of x. A numerical method can work for any type of f(x) - well any f(x) that's not discontinuous anyway. There are various algorithms for this: try the Numerical Recipes books, for instance. All of these will be inexact, but they can get close to an exact answer, depending on the algorithm chosen and the type of function f(x).

dhwani mathur
Ranch Hand
Posts: 621
Thanks for giving an idea.