Re: NIntegrate a list
- To: mathgroup at smc.vnet.net
- Subject: [mg52978] Re: NIntegrate a list
- From: Simon Anders <simon.anders at uibk.ac.at>
- Date: Sat, 18 Dec 2004 04:00:08 -0500 (EST)
- Organization: University of Innsbruck, Austria
- References: <cpug13$gna$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Aaron, Aaron Fude wrote: > I can Integrate this, but apparently not NIntegrate this: > > Integrate[x*Sin[x]*{1, 2}, {theta, -Pi, Pi}] > > but not > > NIntegrate[x*Sin[x]*{1, 2}, {theta, -Pi, Pi}] > > Is there a good way to do this (w/o writing loops)? First, I assume, you meant x instead of theta: NIntegrate[x*Sin[x]*{1, 2}, {x, -Pi, Pi}] Now, you can, of course, put N[_] around it: N[Integrate[x*Sin[x]*{1, 2}, {x, -Pi, Pi}]] But this might try to do it first analytically, which you do not want. So, use Map: Map [NIntegrate[x*Sin[x]*#, {x, -Pi, Pi}] &, {1, 2}] (In case, you are not too experienced, let me explain: I have written the left argument to 'Map' as "pure function", i.e. a function where the parameters are referred to not by name but by position, i.e. we write '#1', '#2', '#3' etc. for them, or here, just '#', which is short for '#1', the one and only parameter of the function. The '&' at the end marks the construct before it as pure fucntion. And 'Map' takes the elements of the second parameter, the list, and puts them into the position maked with the '#'. This is, by the way, precisely, what Mathemtica does automatically in the first case (Integrate without N).) HTH, Simon