Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #11415
| From | Bill Rowe <readnews@sbcglobal.net> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: NIntegrate and replacements |
| Date | 2012-08-19 00:37 +0000 |
| Message-ID | <k0pcfu$e2l$1@smc.vnet.net> (permalink) |
| Organization | Time-Warner Telecom |
On 8/18/12 at 3:47 AM, kravcov.msu@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.
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: NIntegrate and replacements Bill Rowe <readnews@sbcglobal.net> - 2012-08-19 00:37 +0000
csiph-web