residual statics algorithm