Derivative f(x)\operatorname{f}'(x), dfdx\frac{d \operatorname{f}}{d x}

The derivative measures how much a value changes with respect to another. For a function f\operatorname{f}, we can ask how much the value f(x)\operatorname{f}(x) changes, if we change xx a tiny amount.

The notations f(x)\operatorname{f}'(x) ("f prime of x") and dfdx\frac{d \operatorname{f}}{d x} ("df [over] dx") mean the same thing. The first one is often used in basic 1D calculus, the second is probably seen more often higher dimensional variants and physics. The "d" is a "differential" quantity, more or less meaning "something very very small".

There are a few different notations, but mainly we have:

dfdx=limh0f(x+h)f(x)h\frac{d \operatorname{f}}{d x} = \lim\limits_{h \rightarrow 0} \frac{\operatorname{f}(x + h) - \operatorname{f}(x)}{h}

The lim\lim is a so called limit and h0h\rightarrow 0 means "let h approach 0". When using a computer, we can't do that (we can with symbolic and automatic differentiation, but not with the simple method) actually compute this. Instead, we approximate this by using a small value of hh. How do we choose the value of h? Well, that can be more complicated, so usually you will see some slightly hacky fixed value, that is "very" small, like 10710^{-7}. As stated before, this is a very simple code that works, but could be improved in many ways, if needed.

So in math notation, that is called the "difference quotient":

dfdxf(x+h)f(x)h\frac{d \operatorname{f}}{d x} \approx \frac{\operatorname{f}(x + h) - \operatorname{f}(x)}{h}

Code: