Finding critical values and derivatives for functions