vectorized square error loop