There is something about output power of battery in circuits that bothering me. I hope you help me. So we know the formula for power in electrical circuits is (current x voltage) or: $$ P=IV $$ and the voltage of a battery while there is a current running through it is: $$ V = \varepsilon - Ir $$ where $\varepsilon$ is the electromotive force, and $r$ is the internal resistance of the battery. Now if we replace $V$ in the power equation with the voltage of battery, we have: $$ P = I(\varepsilon - Ir) = I\varepsilon-rI^2 $$ if we make a function out of it like this: $$ P(I) = I\varepsilon - rI^2 $$ and graph it, we get something like this for example:
My problem is the derivative of this function: $$ \frac{dP}{dI} = \varepsilon - 2rI $$ which is clearly not equal to the output voltage of the battery, but as far as I know, it should be. If there is something I'm mistaking about, please correct me