t=[0,0.5,1,1.5,2];
x=[0.8,1,0.5,2,1];
dt=t(2:5)-t(1:4);
sum(dt.*x(2:5))