t=[0,0.5,1,1.5,2];
x=[0.8,1,0.5,2,1];

sum((t(2:3)-t(1:3-1)).*x(2:3))