Re: SetDelayed
- To: mathgroup at smc.vnet.net
- Subject: [mg92892] Re: SetDelayed
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Fri, 17 Oct 2008 05:23:17 -0400 (EDT)
On 10/16/08 at 5:06 AM, shechtma at netvision.net.il (Itzhak) wrote:
>Why does Mathematica reply with:
>
>.."Integrand [(x-Cos[y])/(1+x^2-2*x*Cos[y])^1.5 is not numerical at
>{y}={1.5708}", to the following:
>Clear[f]
>f[x_]:=NIntegrate[(x-Cos[y])/(1+x^2-2*x*Cos[y])^1.5,{y,0,Pi}];
>Plot[Evaluate[f[x],{x,0,2}]
>How should it be written?
f[x_?NumericQ]:=NIntegrate[(x-Cos[y])/(1+x^2-2*x*Cos[y])^1.5,{y,0,Pi}]
This will prevent calling NIntegrate with something that cannot
be evaluated numerically. Note, there really is no need to
follow an expression using SetDelayed with a ";"
That is
f[x_]:=2 x
and
f[x_]:=2 x;
will evaluate exactly the same with neither producing an output
until used later.