You are using t as an index to m_t, but that contains negative values. (in the call to trapz)
I suspect you want to run the line below instead.
energy=trapz(t,abs(m_t).^2);
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!