Re: NIntegrate and Plot
- To: mathgroup at smc.vnet.net
- Subject: [mg63884] Re: [mg63859] NIntegrate and Plot
- From: "Peter Rolnick" <abrahams_rolnick at sbcglobal.net>
- Date: Fri, 20 Jan 2006 04:32:42 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Hi. Thank you for getting back to me. I will try what you suggested. Also, I have found out from Mathematica something that may be the problem: When you do Plot, it tries doing whatever it is you are plotting analytically, even if it is something numerical such as NIntegrate, and that would explain why it was giving error messages but still, once it realized that it had to do it numerically, giving me the plot I wanted. They suggested that I wrap the function in Hold, which would keep Plot from trying to do it analytically first, but I haven't tried that yet so I'm not positive that is the problem. Peter Peter Rolnick, <mailto:prolnick at truman.edu> prolnick at truman.edu 216 N New St, Kirksville MO 63501, 660-665-2703 <http://www2.truman.edu/~prolnick> http://www2.truman.edu/~prolnick _____ From: bsyehuda at gmail.com [mailto:bsyehuda at gmail.com] To: mathgroup at smc.vnet.net Subject: [mg63884] Re: [mg63859] NIntegrate and Plot Hi, Since you give no description of the function at hand I can only speculate from my past experience.... The Plot function is sampling the range of interest with $MachinePrecision. I encountered a problem in the past with this effecting Integrate (not NIntegrate as in your case) but I wonder if such effect can cause that in your case too. This is easy to check. Crate a set of accurate samples (high precision or rational numbers) in the range of interest and then use these points with your NIntegrate. If this is OK use ListPlot in place of Plot for the results you calculated above. I hope it helps yehuda On 1/19/06, Peter Rolnick <abrahams_rolnick at sbcglobal.net> wrote: Hello. I have a 3D function that I am integrating numerically, and it has a parameter, q. As far as I can tell, the integrand is never infinite or complex. When I use NIntegrate for a particular value of q, it does the numerical integral and gives me a reasonable value for the result (for q = 0 it gives me the expected analytic value). I can do this for many values of q, and it seems to work just fine. However... when I try to Plot the numerical integral as a function of q, though it does actually give me a reasonable plot, it also gives me this message: It gives the message repeatedly, always at the same values of k, X, and gamma (the variables of integration). There is nothing weird or singular at those points, and if I ask the numerical integral to skip any or all of those points, it gives the same message at some slightly different points. This makes me think that the problem does not have to do with those particular points. (It does this weird behavior even if I just use the Real part of the integrand, so it can't be that the value of the integrand is complex anywhere.) So my question is, why does Mathematica let me do NIntegrate for a single value of q, but get upset if I try to Plot the numerical integral over a range of values of q (even though it actually ends up doing what I asked it to do)? I'm suspecting this is some simple but subtle quality of Mathematica that has to do with using the function NIntegrate inside the function Plot. Thanks very much. Peter Rolnick Peter Rolnick, <mailto:prolnick at truman.edu> prolnick at truman.edu 216 N New St, Kirksville MO 63501, 660-665-2703 <http://www2.truman.edu/~prolnick> http://www2.truman.edu/~prolnick <http://www2.truman.edu/~prolnick>