custom matlab functions used by Sherrick 2ed