use sum instead of trapz