The calculus of variations is used to find functions that optimize quantities expressed in terms of integrals. Optimal control theory …