The arguments in the integration function trapz were in the wrong order. Solved the error.