Re: NIntegrate where terms of integrand have unknown constant coefficients
- To: mathgroup at smc.vnet.net
- Subject: [mg8931] Re: [mg8882] NIntegrate where terms of integrand have unknown constant coefficients
- From: David Withoff <withoff>
- Date: Sat, 4 Oct 1997 22:08:09 -0400
- Sender: owner-wri-mathgroup at wolfram.com
> I'm trying to do something along the lines of NIntegrate[c[1] f[1][x] + > c[2] f[2][x] + ..., {x, 0, a}], where c[n_] is unknown, but the f[n_] are > defined so that NIntegrate[f[n][x], {x, 0, a}] would work. I'd like to be > able to do the numerical integration, and keep the coefficients, so I'd get > as an answer c[1] NIntegrate[f[1][x], {x, 0, a}] + c[2] NIntegrate[f[2][x], > {x, 0, a}] + ... with all the NIntegrate's evaluated. The constant > coefficients are all of the same form c[n] (actually, each term will have > two coefficients c[n1] c[n2]). > Is there some way of doing this by changing the definition of NIntegrate so > it will automatically acheive this, or do I have to do something more > complicated? I'm not at all sure here, as I've never tried adding to the > definitions of complicated objects like NIntegrate. > > Any help or suggestions would be very gratefully accepted! > > Thanks, Scott Morrison > scott at morrison.fl.net.au 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. Dave Withoff Wolfram Research