I want to do a small program to take the derivative of a function. Does anyone know offhand an algorithm to do that or where I can find info about it?
code:<HR>Code:class Term { Term(float c, int e) : coeff(c), exp(e) {}; Term& derivative(){ return Term(coeff * exp, e - 1); } public: float coeff; int exp; };<P>class Polynomial { public: float evaluate(float x){ // use horner's rule to evaluate return ...; } Polynomial(const vector<Term>& p) : poly(p) {} Polynomial derivative(){ vector<Term> v; for (vector<Term>::const_iterator i = poly.begin(); i != poly.end(); ++i){ v.push_back(i->derivative()); } return Polynomial(v); } private: vector<Term> poly; };
Originally posted by wet behind the ears:
Pardon my ignorance but isn't the definition of a derivative
Df(x)=f(a+h)-f(a)/a as the limit goes to 0, if not then
Df(x)=f(a+h)-f(a)/a-h?
wbte/