Derivative Calculator

burki picture burki · May 25, 2010 · Viewed 13.8k times · Source

I'm interested in building a derivative calculator. I've racked my brains over solving the problem, but I haven't found a right solution at all. May you have a hint how to start? Thanks

I'm sorry! I clearly want to make symbolic differentiation.

Let's say you have the function f(x) = x^3 + 2x^2 + x

I want to display the derivative, in this case f'(x) = 3x^2 + 4x + 1

I'd like to implement it in objective-c for the iPhone.

Answer

SLaks picture SLaks · May 25, 2010

I assume that you're trying to find the exact derivative of a function. (Symbolic differentiation)

You need to parse the mathematical expression and store the individual operations in the function in a tree structure.

For example, x + sin²(x) would be stored as a + operation, applied to the expression x and a ^ (exponentiation) operation of sin(x) and 2.

You can then recursively differentiate the tree by applying the rules of differentiation to each node. For example, a + node would become the u' + v', and a * node would become uv' + vu'.