Optimal Trajectory Planning for a Flexible Manipulator