Re: Re: Evaluate and HoldAll

• To: mathgroup at smc.vnet.net
• Subject: [mg24234] Re: [mg24222] Re: Evaluate and HoldAll
• From: "Carl K. Woll" <carlw at u.washington.edu>
• Date: Mon, 3 Jul 2000 20:39:16 -0400 (EDT)
• References: <395C69F9.44E390C9@aflo4.ifw-dresden.de> <200007010721.DAA03344@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Andre,

The simplest solution is to use double blanks instead of your lseq and rseq
approach. For example,

Clear[gr]
gr[x_, a1_,a2_,a3_] := a1*Exp[a2 - a3 x]

Clear[t]
t[q_, seq__] :=
NIntegrate[(4\[Pi]/q)*r*Sin[q r]*gr[r, seq], {r, 0, 10^5},
MinRecursion -> 5,
MaxRecursion -> 30,
PrecisionGoal -> 10,
WorkingPrecision -> 64]

should do the trick. If you insist on using the lseq and rseq approach, then use =

Carl

Andre Heinemann wrote:

> Andre Heinemann wrote:
>
> > Hi mathgroup
> >
> > Attributes[NIntegrate] gives: {HoldAll, Protected}
> >
> >
> > *****************************************************************************
> >
> > *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
> >
> > 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

```

• Prev by Date: Re: PrimeQ queries
• Next by Date: Re: Re: Evaluate and HoldAll
• Previous by thread: Re: Evaluate and HoldAll
• Next by thread: Re: Re: Evaluate and HoldAll