Trapezoidal rule to find total work?

3 views (last 30 days)
I'm given 6 values for time, Force, and velocity. And I'm told to find total work with trapezoidal rule. (first time value is zero)
Does this seem correct? I excluded the code where I assign t=[0,#, #,...] & v=[.2, #, #...] & F=[2.0, #, #...]
for i=2:length(t)
pos(i)=pos(i-1) + area
work(i)= (pos(i) + pos(i-1))*(F(i)-F(i-1))/2
totalwork= totalwork + work(i)
Rachel Dawn
Rachel Dawn on 28 Mar 2018
Hi David, thank you for your response. The Force values I'm given are not constant throughout. But, I'm wondering, how would I actually change my code to account for a constant force? What do you mean by "describe the correct trapezoid"?

Sign in to comment.

Accepted Answer

Roger Stafford
Roger Stafford on 28 Mar 2018
Edited: Roger Stafford on 28 Mar 2018
I would think your code should be this:
work = 0;
for k = 2:length(t)
work = work + (F(k)+F(k-1))/2*(v(k-1)+v(k))/2*(t(k)-t(k-1));
That is, the quantity "(v(k-1)+v(k))/2*(t(k)-t(k-1))" is the approximate displacement during the time interval t(k-1) to t(k), and if it is multiplied by the average force (trapezoid rule), "(F(k)+F(k-1))/2", during that time interval you would get the approximate work done then. The sum of the five work values should give you the total work done.
[Addendum: Or perhaps you could use this:
work = 0;
for k = 2:length(t)
work = work + (F(k)*v(k)+F(k-1)*v(k-1))/2*(t(k)-t(k-1));
because you are approximating the integral of F*v with respect to time, t.]
Roger Stafford
Roger Stafford on 28 Mar 2018
" I just tried both those sections of code you included and they give different answers." Yes, they are not identical, but are different approximations. Assuming F and v vary in a reasonably smooth fashion, they should not be greatly different. It is the difference between
It is not clear which of these best represents the trapezoidal rule. I would hazard the guess that the first of these (that is, the second in the answer) is likely to be the best.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by