Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2012

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

Search the Archive

Re: NIntegrate and replacements

  • To: mathgroup at
  • Subject: [mg127756] Re: NIntegrate and replacements
  • From: Bill Rowe <readnews at>
  • Date: Sat, 18 Aug 2012 20:37:14 -0400 (EDT)
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:

On 8/18/12 at 3:47 AM, kravcov.msu at (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
  • 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