Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!apple!tahoe!jimi!arrakis!ramesh From: ramesh@nevada.edu (RAMESH VISWANATHAN) Newsgroups: comp.lang.idl-pvwave Subject: Re: How can I integrate? (easy question?) Message-ID: <1991Mar25.173317.15255@nevada.edu> Date: 25 Mar 91 17:33:17 GMT References: <1991Mar20.233728.1@csc.anu.edu.au> Organization: University of Nevada, System Computing Services Lines: 22 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.