average_curve_optim function

Generate an average curve using optim