Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!samsung!munnari.oz.au!manuel!csc.anu.edu.au!bdb112 From: bdb112@csc.anu.edu.au Newsgroups: comp.lang.idl-pvwave Subject: Re: How can I integrate? (not so easy?) Message-ID: <1991Mar26.071841.1@csc.anu.edu.au> Date: 25 Mar 91 20:18:41 GMT References: <1991Mar20.233728.1@csc.anu.edu.au> Sender: news@newshost.anu.edu.au Organization: Computer Services, Australian National University Lines: 18 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.