Using MATLAB to find optimal solutions to problems in mechanics