Optimization-Based Iterative Learning Control for Trajectory Tracking