smoothed residual functions
moved residual calculation from simulation to analysis
function to save results