The trapz function is just defined another way. Calling it with the right parameters let you getting the right result
working with references let you get unexpected results