function has to return x AFTER applying sort to it
in example2, deepcopy was needed
in example3, it has to be trapz(y,x)
in example4, again deepcopy was needed