finding derivatives.

Started by
14 comments, last by laeuchli 21 years, 6 months ago
Dear All, I seem to remember reading a article on writing programs to compute derivates, but I sure can remember where is was. If anyone knows, could they tell me? Thanks, Jesse www.laeuchli.com/jesse/
Advertisement
Evaluating a derivative numerically is really easy. Remember its definition:
f''(x) = lim   f(x+h) - f(x)        h->0  -------------                    h 

(Uh... Something doesn''t look right there. Anybody?)

You can apply that definition literally even with a calculator.

Cédric
A much better approximation of f''(x) is usually given by (f(x+h)-f(x-h))/2h, which is second order accurate. The trick is to pick an optimal value for h. As a rule of thumb, set h to 10^(n/2), where n is the number of significant digits of the number representation.
Sorry, should be 10^(-n/2).

If you really need it, you can make symbollic derivation, using "jets". An old idea of mine that I never implemented is making a C++ class to manipulate 1-jets. This means, the value of a function together with the value of the first derivative. Something like this:


  struct Jet{   double value,derivative;   Jet(double v, double d = 0.0):value(v),derivative(d){}   Jet operator+(const Jet &j){      return Jet(value+j.value,derivative+j.derivative);   }   Jet operator*(const Jet &j){      return Jet(value*j.value,derivative * j.value+value*j.derivative);   }   // etc.};Jet sin(const Jet &j){   return Jet(sin(j.value),cos(j.value)*j.derivative);}  


I haven''t tried this code, but I hope you get the idea. You can then define a function like

  Jet my_func(Jet j){   return j*(sin(j)+j);}  

and you get both the value of the function and its derivative. How cool is that?

quote:Original post by laeuchli
I seem to remember reading a article on writing programs to compute derivates, but I sure can remember where is was. If anyone knows, could they tell me?


Was it an article posted here at GD.net?

Were you looking to compute symbolic derivatives, numerical approximations of derivatives or find exact derivatives of n order polynomials? I''m guessing the latter, but of course I could be wrong.

Cheers,

Timkin

sorry, I can''t rember where I read it. I was looking for info on the latter. Basicly, I''m trying to figure out the algoritim my ti-92+ uses find derivates and integrals.
Jesse....
quote:Original post by laeuchli
sorry, I can''t rember where I read it. I was looking for info on the latter. Basicly, I''m trying to figure out the algoritim my ti-92+ uses find derivates and integrals.
Jesse....

For polynomials? That''s trivial.
(x^n)'' = n * x^(n-1)

If you''re looking for a numerical derivative, then AP''s method is probably the one used.

Cédric
sorry, yes I know that. I also know how to do numerical calculation. I meant symbolic, not ployinminal. For example, what do I do if I have a more complex equations that I have to differinate? I know how to do it by hand, but I''m trying to find out if there is a well know good way to solve them on the computer. Or are they usally just computed numerically?
Thanks,
Jesse.
To do symbolic derivation you will have to build a recursive data structure representing the expression. You can then determine the derivative by recursive substitution. For example, if your expressions are built from the the basic expressions: (expr + expr), (expr * expr), sin(expr), x, and numeral, the derivative of any expression can be determined by recursively applying the rules:
D((expr1 + expr2)) = (D(expr1) + D(expr2))D((expr1 * expr2)) = ((D(expr1) * expr2) + (expr1 * D(expr2)))D(sin(expr)) = (cos(expr) * D(expr))D(x) =  1D(numeral) =  0 

Then you will probably want to simplify the resulting expression, but that''s another topic...

This topic is closed to new replies.

Advertisement