Re: NIntegrate where terms of integrand have unknown constant coefficients

*To*: mathgroup at smc.vnet.net*Subject*: [mg8954] Re: [mg8882] NIntegrate where terms of integrand have unknown constant coefficients*From*: Paul Abbott <paul at physics.uwa.edu.au>*Date*: Mon, 6 Oct 1997 01:59:22 -0400*Organization*: University of Western Australia*Sender*: owner-wri-mathgroup at wolfram.com

David Withoff wrote: > I would do this by defining your own function that performs the > symbolic linearity operations before calling NIntegrate, rather > than by redefining NIntegrate. For example > > In[1]:= int[p_Plus, q_] := Map[int[#, q] &, p] > > In[2]:= int[(p:c[_]) f_, q_] := p NIntegrate[f, q] > > In[3]:= int[c[1] x + c[2] x^2, {x, 0, 1}] > > Out[3]= 0.5 c[1] + 0.333333 c[2] > > This strategy could be made considerably more elaborate to do > almost anything that you might want. Another general and powerful way, is to use pattern-matching: In[1]:= f[n_][x_] = x^n; In[2]:= c[1] f[1][x] + c[2] f[2][x] /. c[n_] a_ :> c[n] NIntegrate[a, {x, 0, 1}] Out[2]= 0.5 c[1] + 0.333333 c[2] Cheers, Paul ____________________________________________________________________ Paul Abbott Phone: +61-8-9380-2734 Department of Physics Fax: +61-8-9380-1014 The University of Western Australia Nedlands WA 6907 mailto:paul at physics.uwa.edu.au AUSTRALIA http://www.pd.uwa.edu.au/~paul God IS a weakly left-handed dice player ____________________________________________________________________