Real-time model predictive control for the optimal charging of a lithium-ion battery