A simple algorithm for the selection of terminal penalty weighting matrices