added mylog() and devectorized the max(abs()) line.