1. A method for controlling an operation of a machine according to a model of the machine, comprising: controlling iteratively the operation of the machine with control inputs determined using the model based on an optimization of a cost function subject to constraints on the control inputs, wherein at least one current iteration comprises: determining a current state of the machine after the controlling with a previous control input determined for a previous iteration by optimizing a previous cost function using a previous model of the machine; determining a current model of the machine to reduce a difference between the current state and a state estimated using the previous model of the machine; updating the cost function based on a difference between the previous model and the current model to produce a current cost function; and determining a current control input for the controlling at the current iteration using the current model and the current cost function, wherein steps of the methods are performed by a processor of a controller controlling the operation of the machine.