Re: A faster alternative to ListIntegrate? [2]

• To: mathgroup at smc.vnet.net
• Subject: [mg35752] Re: A faster alternative to ListIntegrate? [2]
• From: "Allan Hayes" <hay at haystack.demon.co.uk>
• Date: Mon, 29 Jul 2002 03:13:26 -0400 (EDT)
• References: <200207250846.EAA12103@smc.vnet.net> <ahr122\$l2v\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Mark,
I missed out the data that was used in my previous posting.
It was

data = Table[{x, 100Sin[x]}, {x, 0, 100, .01}];

However, a restatement might be better:

For a list of y values, at x values equally spaced at h apart use

TrapeziumIntegrate[{a_, r___, b_}, h_] := (a + b + 2Tr[{r}])h/2

For a list of {x,y}-values with x abitrarilly spaced use:

TrapeziumIntegrate[data_] :=
(Drop[#1, 1] - Drop[#1, -1]).(Drop[#2, -1] + Drop[#2, 1]) &[data[[All,
1]],
data[[All, 2]]]/2

--
Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Matthew Rosen" <mrosen at cfa.harvard.edu> wrote in message
news:ahr122\$l2v\$1 at smc.vnet.net...
> Hi Everyone;
>  I've tracked down the slow operation of my Mathematica simulation code to
> lie in the ListIntegrate command:
>
> G[n_] := ListIntegrate[xsec Phi[n], 1]
>
> where both xsec and Phi[n] are 400 values long.
>
> Is there a way to speed up ListIntegrate via Compile or a similar
technique?
>
> Thanks in advance and best regards,
>
> Matt
> ---
> Matthew Rosen
> Harvard-Smithsonian Center for Astrophysics
> Mail Stop 59
> 60 Garden Street
> Cambridge, MA 02138
>
> e: mrosen at cfa.harvard.edu
> o: (617) 496-7614
>

```

• Prev by Date: Re: Question about Replace
• Next by Date: Re: Max[Min[#,b],a]&
• Previous by thread: Re: A faster alternative to ListIntegrate?
• Next by thread: Setting Notebook Options in a StyleSheet