finish least squares error derivation