MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: nested SetDelayed

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113368] Re: nested SetDelayed
  • From: Peter Breitfeld <phbrf at t-online.de>
  • Date: Tue, 26 Oct 2010 05:31:45 -0400 (EDT)
  • References: <ia3mr3$rl4$1@smc.vnet.net>

O wrote:

> hello,
> maybe somebody can explain what i'm doing wrong in this SIMPLE
> example:
>
> In[1] := f[v_, k_] := Sin[v*k]
> In[2] := test[v_] := NIntegrate[f[v, k], {k, 0, Pi}]
> In[3] := FindRoot[test[x] == 1, {x, 1}]
>
> I have NIntegrate errors:
>
> NIntegrate::inumr: The integrand Sin[k x] has evaluated to non-
> numerical values for all sampling points in the region with boundaries
> {{0,3.14159}}. >>
> NIntegrate::inumr: The integrand k Cos[k x] has evaluated to non-
> numerical values for all sampling points in the region with boundaries
> {{0,3.14159}}. >>
> NIntegrate::inumr: The integrand k Cos[k x] has evaluated to non-
> numerical values for all sampling points in the region with boundaries
> {{0,3.14159}}. >>
> General::stop: Further output of NIntegrate::inumr will be suppressed
> during this calculation. >>
>
> and CORRECT answer:
> Out[3] = {x -> 1.37697}
>
> Why expression `test` is evaluated with nonnumerical arguments??
>
> I guess my VisualBasic oriented brain can't understand how SetDelayed
> work and how i should use it.
>
> Thanks
>

When defining a function using NIntegrate (and some other numerical
functions), you should restrict your functions parameters to numeric
Values, so define

test[v_?NumericQ]:=NIntegrate[f[x,k],{k,0,Pi}]

-- 
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de


  • Prev by Date: Re: nested SetDelayed
  • Next by Date: Re: := vs = in some function definitions
  • Previous by thread: Re: nested SetDelayed
  • Next by thread: Re: nested SetDelayed