This is basically a programming exercise in matlab but I do not understand the math behind it.
Say, that I have an trapezoidArea function defined like this:
function area=trapezoidArea(x1,x2,y1,y2)
area=(x2-x1).*(y1+y2)/2;
end
and my time and acceleration are as follows:
t=0:0.1:40;
a(1,1:201)=2;
a(1,201:301)=0;
a(1,301:401)=-4;
If I want to calculate velocity, I can integrate acceleration time series numerically:
t1=t(1:end-1);
t2=t(2:end);
a1=a(1,1:end-1);
a2=a(1,2:end);
v=transpose(trapezoidArea(t1,t2,a1,a2));
If I want to find displacement, then I have to apply trapezoidArea function again to velocity time series but the dimensions of velocity is smaller than the dimension of the time vector. So my question is how can I find displacement vector by numerically integrating acceleration twice? and why the method you describe works?
I was told to apply cumsum function to v and then remove the last element of t and then apply trapezoidArea to v and t but to be honest, I am not sure why this method works. When I use this method sum(s)=1.004e3.
Your
v=trapezoidArea(t1,t2,a1,a2)function returns a vector of the velocity change over intervals[t1(1),t2(1)], ... [t1(end),t2(end)]. The actual velocity at timest2(i)isv0+v(1)+...+v(i), wherev0is the initial velocity.You now have a vector of velocities at times
t2, which you can extend to velocities at timestby prependingv0tov.