created new function for each type of sorting
fitting for coefficients