Applying numerical integration twice (trapezoidal rule)

1.7k Views Asked by At

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.

3

There are 3 best solutions below

0
On BEST ANSWER

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 times t2(i) is v0+v(1)+...+v(i), where v0 is the initial velocity.

You now have a vector of velocities at times t2, which you can extend to velocities at times t by prepending v0 to v.

1
On

So my question is how can I find displacement vector by numerically integrating acceleration twice? and why the method you describe works?

Because: $$a=\frac{{\rm d}v}{{\rm d}t}=\frac{{\rm d}}{{\rm d}t}\left(\frac{{\rm d}x}{{\rm d}t}\right)=\frac{{\rm d^2}x}{{\rm d}t^2}$$ So: $$v-v_0=\int {\rm d}v=\int a{\rm d}t$$ And: $$x-x_0=\int {\rm d}x=\int v{\rm d}t=\int\int a{\rm d}t{\rm d}t$$

0
On

After a bit of thinking about this, I think I have got the answer. This answer is motivated by @Conrad Turner's answer. Let's call the velocity vector that is obtained by numerically integrating acceleration vector, be V and let's call the actual acceleration vector be v. It is clear that $v(2)=V(1)$, $v(3)=V(1)+V(2)$ and in general $v(i)=V(1)+V(2)+\cdots+V(i-1)$. Therefore, the need for cumsum.