Not quite the same due to (other) rounding errors when the interval of
the rising and/or falling part of the trapezoid becomes large enough.

trap172=: 4 : 0
  'lz dr' =. 0 >. x (-&{.,-~&{.) y
  (#y){. dr}. (lz$0), }:+/\0,(#(%...@{.,0,-...@%@{:)) 2 -~/\ x
)

The last one should be zero, so I drop it:

   +/\0,(#(%...@{.,0,-...@%@{:)) 2 -~/\ 2 6 8 11
0 0.25 0.5 0.75 1 1 1 0.6666666667 0.3333333333 1.110223025e_16


   2 6 8 10 (trap-:trap172) i.11
1

   20 60 80 180 (trap-:trap172) i.1e3
1

but:

   20 60 80 190 (trap-:trap172) i.1e3
0


-- 
=@@i

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to