MathGroup Archive 2012

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

Search the Archive

Re: NIntegrate and replacements

  • To: mathgroup at smc.vnet.net
  • Subject: [mg127756] Re: NIntegrate and replacements
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Sat, 18 Aug 2012 20:37:14 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net

On 8/18/12 at 3:47 AM, kravcov.msu at gmail.com (S-Tat) wrote:

>I have a simple question. There is my code, it integrates a function
>which is a solution of the equation:

>bc[r_, x_] := r + x^2;
>sol[r_] := Re[x /. FindRoot[bc[r, x] == 0, {x, 1.1 + I}]];
>NIntegrate[sol[r], {r, 1, 8}]

Change the definition for sol to be

sol[r_?NumericQ]:=Re[x /. FindRoot[bc[r, x] == 0, {x, 1.1 + I}]]

THe problem with your code is Mathematica wants to evaluate
sol[r] before r is given a numeric value by NIntegrate causing
the error. Adding the test ?NumericQ prevents sol from returning
values when non-numeric arguments are supplied.




  • Prev by Date: Re: Using a huge list of random numbers from random.org
  • Next by Date: Re: Inconsistent behavior of RegionFunction in ContourPlot and ListContourPlot
  • Previous by thread: Re: NIntegrate and replacements
  • Next by thread: Thread::tdlen: Objects of unequal length in