In this paper, we focus on identifying the transmission rate associated with a COVID-19 mathematical model by using a predefined prevalence function. To do so, we use a Python code to extract the Lagrange interpolation polynomial from real daily data corresponding to an appropriate period in Morocco. The existence of a perfect control scheme is demonstrated. The Pontryagin maximum technique is used to explain these optimal controls. The optimality system is numerically solved using the 4th-order Runge-Kutta approximation.