1strictly speaking we should not diļ¬€erentiate on closed interval, since the maximum can show up at the end point and this method will overlook these