Trapezoidal rule to find total work?

3 次查看(过去 30 天)
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, #, #...]
pos(1)=0
work(1)=0
totalwork=0
for i=2:length(t)
area=(v(i)+v(i-1))*(t(i)-t(i-1))/2
pos(i)=pos(i-1) + area
work(i)= (pos(i) + pos(i-1))*(F(i)-F(i-1))/2
totalwork= totalwork + work(i)
end
totalwork
  2 个评论
David Goodmanson
David Goodmanson 2018-3-28
编辑:David Goodmanson 2018-3-28
Hi Rachel,
you should take a look at the (pos(i) + pos(i-1))*(F(i)-F(i-1))/2 term. If the force is constant everywhere, your expression will produce zero for the total work. So you need to describe the correct trapezoid.
Rachel Dawn
Rachel Dawn 2018-3-28
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"?
Thanks!

请先登录,再进行评论。

采纳的回答

Roger Stafford
Roger Stafford 2018-3-28
编辑:Roger Stafford 2018-3-28
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));
end
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));
end
because you are approximating the integral of F*v with respect to time, t.]
  2 个评论
Rachel Dawn
Rachel Dawn 2018-3-28
编辑:Rachel Dawn 2018-3-28
Hi Roger, Thank you! I checked this code and got a totally different answer for work then my previous code. What was wrong with mine, though?
Hmm. I just tried both those sections of code you included and they give different answers. I'm not sure why.
Update: I figured out what was wrong with my code! I had position as my bases & force as my height (should be the other way around). Thanks!
Roger Stafford
Roger Stafford 2018-3-28
编辑:Roger Stafford 2018-3-28
" 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
(F(k)*v(k)+F(k-1)*v(k-1))/2
and
(F(k)*v(k)+F(k)*v(k-1)+F(k-1)*v(k)+F(k-1)*v(k-1))/4
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by