Re: Evaluate and HoldAll
- To: mathgroup at smc.vnet.net
- Subject: [mg24222] Re: Evaluate and HoldAll
- From: Andre Heinemann <andre at aflo4.ifw-dresden.de>
- Date: Sat, 1 Jul 2000 03:21:53 -0400 (EDT)
- Organization: IFW
- References: <395C69F9.44E390C9@aflo4.ifw-dresden.de>
- Sender: owner-wri-mathgroup at wolfram.com
Andre Heinemann wrote: > Hi mathgroup > > Attributes[NIntegrate] gives: {HoldAll, Protected} > > In THE BOOK (or online Help) one can find: > > ***************************************************************************** > > *You can use Evaluate to evaluate the arguments of a HoldAll function in > a controlled way. * > ***************************************************************************** > > So I built: > > rseq = Sequence[a1, a2, a3] > lseq = Sequence[a1_?NumericQ, a2_?NumericQ, a3_?NumericQ] > > My Function f[r, rseq] > > gives the output: (e.g.) a1 Exp[a2 - a3 r] > (I know that I can use Integrate here, instead of Nintegrate but it is > for testing) > > Clear[test] > test[q_, lseq] := NIntegrate[Evaluate[f[r, rseq]], {r, 0, 10^5}] > > test[0.1, 1, 0.2, 0.5 ] presented: > > NIntegrate::"inum" : ... Integrand ... is not numerical at r = .... and > so on > > NIntegrate[f[r, rseq],{r, 0, 10^5}] > > Ok, I can see that the integrand is not numerical and so I tried: > > Clear[test] > test[q_, lseq] := NIntegrate[a1 Exp[a2 - a3 r] , {r, 0, 10^5}] and > > test[0.1, 1, 0.2, 0.5 ] works very well and finds: 2.442805516320 as the > answer ! > > What is the point here ? I think my understanding of Evaluate[] is false > but > how can I solve the problem ? > > I would be glad to have an explanation or a hint. Hi Sorry for this update, but I think I found a better formulation of my problem, and I found out it has nothing to do with Evaluate and HoldAll. Here is what I mean: lseq = Sequence[a1_, a2_, a3_] rseq = Sequence[a1, a2, a3] Clear[gr] gr[x_, lseq] := a1*Exp[a2 - a3 x] In[1415]:= gr[r, rseq] Out[1415]= \!\(a1\ \[ExponentialE]\^\(a2 - a3\ r\)\) Clear[t] t[q_, lseq] := NIntegrate[(4\[Pi]/q)*r*Sin[q r]*gr[r, Sequence[a1, a2, a3]], {r, 0, 10^5}, MinRecursion -> 5, MaxRecursion -> 30, PrecisionGoal -> 10, WorkingPrecision -> 64] In[1406]:= t[0.1, 1, 2, 3] Out[1406]= 6.862786625992 Works very well ! But I need for further developments: Clear[t] t[q_, lseq] := NIntegrate[(4\[Pi]/q)*r*Sin[q r]*gr[r, rseq], {r, 0, 10^5}, MinRecursion -> 5, MaxRecursion -> 30, PrecisionGoal -> 10, WorkingPrecision -> 64] ... some errors... \!\(NIntegrate[\(\((4\ \[Pi])\)\ r\ Sin[0.1`\ r]\ gr[r, rseq]\)\/0.1`, {r, 0, 10\^5}, MinRecursion -> 5, MaxRecursion -> 30, PrecisionGoal -> 10, WorkingPrecision -> 64]\) Where you can see the problem. The right side in the definition := has not been evaluated, so mathematica doesn't know somthing about a1, a2, a3. Clear[t] t[q_, lseq] := Module[{}, core = r*Sin[q r]*gr[r, rseq] ] t[0.1, 1, 2, 3] \!\(125.66370614359172`\ a1\ \[ExponentialE]\^\(a2 - a3\ r\)\ r\ Sin[ 0.1`\ r]\) ------------------------- AND the rigth answer should be: ------------------------- Clear[t] t[q_, lseq] := Module[{}, core = (4\[Pi]/q)*r*Sin[q r]*gr[r, a1,a2,a3] ] t[0.1, 1., 2., 3.] \!\(1.\[ExponentialE]\^\(\(\(2.)\(\[InvisibleSpace]\)\) - 3. r\)\ r\ \ Sin[0.1 r]\) I have not the faintest idea how to find a solution for this. Andre
- Follow-Ups:
- Re: Re: Evaluate and HoldAll
- From: "Carl K. Woll" <carlw@u.washington.edu>
- Re: Re: Evaluate and HoldAll