Archived

This topic is now archived and is closed to further replies.

finding derivatives.

This topic is 5744 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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/

Share on other sites
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

Share on other sites
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.

Share on other sites
Sorry, should be 10^(-n/2).

Share on other sites
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?

Share on other sites
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

Share on other sites
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....

Share on other sites
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

Share on other sites
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.

Share on other sites
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...

1. 1
2. 2
3. 3
4. 4
Rutin
18
5. 5

• 11
• 12
• 9
• 12
• 37
• Forum Statistics

• Total Topics
631420
• Total Posts
2999989
×