One simple technique that I know of for computing derivative is assuming a small change in x axis (like 0.0001, the smaller the better) and computing corresponding change in y. The derivative then is dy / dx, which is just a slope at that point. With this idea, lets say were given a function y = f(x) and we want to compute derivative at x = a. Consider a small value h (the smaller the value h, the more accurate is the derivative) then we will consider interval a and a + h. For the given interval we can calculate change in y as f(a + h) - f(a). Now we already know that derivative at a point is the slope at that point, which is given by:
m = [f(a+h) - f(a)]/ h
This formula is sufficient to compute derivative. The pseudo code for this would be :
double compute_derivative(double a) {
double h = 0.0000001;
double faph = compute the function for x = a+h;
double fa = compute the function for x =a;
return (faph - fa) /h;
}
Derivatives are useful for many numerical algorithms. So knowing this can be handy for programmers.
No comments:
Post a Comment