comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » How can I integrate? (easy question?)
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
How can I integrate? (easy question?) [message #2] Wed, 20 March 1991 04:37 Go to next message
bdb112 is currently offline  bdb112
Messages: 3
Registered: March 1991
Junior Member
How can I efficiently do a running sum of a vector (integrate)? The explicitly
coded version (IDL v2)
for i=1,n-1 x(i)=x(i) + x(i-1) achieves the desired effect, but takes (VS3100)
1 second for a 2000 element array compared to .01 sec for z=x+x, a similar
number of operations. This is such an obvious thing to do that I must be
missing something obvious - I can't find it in the userlib either (just
deriv).
Re: How can I integrate? (not so easy?) [message #146 is a reply to message #2] Mon, 25 March 1991 12:18 Go to previous message
bdb112 is currently offline  bdb112
Messages: 3
Registered: March 1991
Junior Member
In article <1991Mar20.233728.1@csc.anu.edu.au>, bdb112@csc.anu.edu.au writes:
> How can I efficiently do a running sum of a vector (integrate)? The explicitly
> coded version (IDL v2)
> for i=1,n-1 x(i)=x(i) + x(i-1) achieves the desired effect, but takes (VS3100)
> 1 second for a 2000 element array compared to .01 sec for z=x+x, a similar
> number of operations. This is such an obvious thing to do that I must be
> missing something obvious - I can't find it in the userlib either (just
> deriv).

Two respondents have suggested
sum_x = total(x(0:i)) ; where i is the maximum idex of the array
When I try this, I get a scalar result, rather like a definite integral, when
what I want is a vector which is a running total, like an indefinite integral.

e.g. x = [1,1,2] sum_x = [1,2,4]
Of course, the next step would be to allow an optional vector which contained
the abscissae, if not equally spaced, or the spacing if equally spaced, but I
would be happy with the simple result.
Re: How can I integrate? (easy question?) [message #147 is a reply to message #2] Mon, 25 March 1991 09:33 Go to previous message
ramesh is currently offline  ramesh
Messages: 7
Registered: February 1991
Junior Member
In article <1991Mar20.233728.1@csc.anu.edu.au> bdb112@csc.anu.edu.au writes:
> How can I efficiently do a running sum of a vector (integrate)? The explicitly
> coded version (IDL v2)
> for i=1,n-1 x(i)=x(i) + x(i-1) achieves the desired effect, but takes (VS3100)
> 1 second for a 2000 element array compared to .01 sec for z=x+x, a similar
> number of operations. This is such an obvious thing to do that I must be
> missing something obvious - I can't find it in the userlib either (just
> deriv).


Assuming "i" represents the current array index value upto which you want to
sum the elements of the array "x", try:

sum_x = total(x(0:i))

or a variation thereof. The dimension of array "sum_x" will be automatically
dimensioned to the value contained in "i"

Note: Function "total" is a PV Wave system routine.


R.V.
Re: How can I integrate? (easy question?) [message #150 is a reply to message #2] Thu, 21 March 1991 16:22 Go to previous message
bruce is currently offline  bruce
Messages: 3
Registered: February 1991
Junior Member
maybe you just want TOTAL(x).
--
-Bruce
"Just half a turn and there's your worm!"

-Bob Bet Bait Box
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: X window backing store
Next Topic: Re: X window backing store

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:06:08 PDT 2025

Total time taken to generate the page: 0.00613 seconds