   Algorithm for Differentiation
  I'd like to write a program to differentiate a function, and I'm wondering what technique is most appropriate to compute it. I'm thinking maybe using matrix math could work, but I'm not sure -- does anyone know any resources out there that could give me an overview of a process I could write that could take, for example:2x^2+x+1And return:4x+1Even though I can differentiate by hand, I just can't seem to wrap my mind around how I could write a method to do it for me without degrading into a mess of special cases.Thanks!   
  I would do it by simply asking the user to input the degree of the polynomiali.e. 2show them what the equation should look likei.e. ax^2+bx+cthen just create an array to hold all the variables and simply multiply the first value a by n (n being the degree of the polynomial).This is obviously going to be more complicated with different types of differentiation but this is what I did for the power rule :).   ;  You want to split a function into its terms and express them using a recursive grammar.  Each term has a coefficient, an exponent, and an inner expression.  You recurse on the inner expression in order to implement the chain rule.  So for some term "A*fb(x)", the derivative is A*b*fb-1(x)*diff(f(x))", where the diff() function represents the recursive step.  You'd only have to special case a few functions like log(), sin()/cos(), etc.  It gets a bit more complicated if you want to handle multivariate functions, but still not too bad.Be glad you're not trying to do integration as well :)   ;  What type of function do you want to differentiate? If you want to differentiate only polynomials than you can simply use a vector to represent the coefficients of the polynomial. If the function is more general than the method presented by Zipster is better.   