# Solve numerically the following integral?

Posted 1 year ago
1150 Views
|
10 Replies
|
6 Total Likes
|
 If I have a simple integral that I wish to solve numerically, such as NIntegrate[x^a, {a, 1., 2., .1}] often on the first evaluation, I just get the function back since x is undefined.However, the second time I do this, I get: "NIntegrate::inumr: The integrand x^a has evaluated to non-numerical values for all sampling points in the region with boundaries {{1.,2.}}"When I ClearAll or Clear x and the variable, the integral still tries to evaluate and I get the same statement as above.Why does Mathematica try to evaluate the integral when all terms are not defined? In other more complex functions, if I miss a variable or screw up the syntax, the function does not evaluate and the function is repeated as the output, and I get no statement such as the above, which is a cue to look for a syntax error.Also, in some cases, when I set up the accuracy and precision to be some value and set the working precision to be twice these values, I also get inane statements like "the precision in the argument is less than the working precision." Of course it is!!These behaviors likely have an obvious cause and can likely be simply explained...I hope.Thanks for the help.Luther
10 Replies
Sort By:
Posted 1 year ago
 It would be much easier to respond if examples of each phenomenon were included in the post. The one example provided is NIntegrate[x^a, {a, 1., 2., .1}].In a fresh session I get the following . In[1]:= NIntegrate[x^a, {a, 1., 2., .1}] During evaluation of In[1]:= NIntegrate::inumr: The integrand x^a has evaluated to non-numerical values for all sampling points in the region with boundaries {{1.,2.}}. Out[1]= NIntegrate[x^a, {a, 1., 2., 0.1}] Is this an unexpected behavior? I could not tell from the wording of the post whether this, or something else, was unexpected.
Posted 1 year ago
 Daniel, your reply did not post in the User Group. I got your message and logged in on the User Group web site but your reply is not here. It seems you duplicated my issue, which is why I did not attach a worksheet, since I wanted an independent verification outside of my Mathematica application.The issue is to me clear: somehow the simple numerical integration does not execute on the first attempt to evaluate but it does execute on the second attempt with the message you posted. Why does it execute the second time and throw out an inane comment? If I use the same process on a more complete numerical integration with the precision and accuracy goal and the working precision indicated, the same thing happens: it does not execute on the first iteration but does on the second, even though all parameters are not defined and so the numerical integration cannot proceed...yet on the second evalution is does with the second inane comment I posted.Why does this happen and how do I keep it from happening? The reason I would like some clarity is that these integrals are defined as functions that are embedded in more complex expressions and I cannot assure that the second and unexpected execution has not created an expression that is incorrect in the more complete expression.Now, my concern may not mean anything to you but to me it means that I cannot trust the results that I calculate. The reason is that I am preparing a worksheet to post in the physics section that identifies a particular integral that needs to be numerically evaluated and there are some issues I am addressing on how to interpret the results given how Mathematical performs the numerical calculations.
Posted 1 year ago
 (1) My response is in the forum. Not sure why it ws not visible to you, might be a glitch on one of our servers.(2) The only behavior from that NIntegrate example I can elicit is where it gives the error message and returns unevaluated. I find it to be a very useful error message, by the way. Returning unevaluated with no indication as to why would be unhelpful, not to mention annoying.(3) The warning messages associated with precision could be better. The usual reason such a message appears is that one requests WorkingPrecision that is higher than the precision of the input. So again, the message is useful, but sometimes people fail to understand what it is telling them and that could perhaps be due to the wording.(4) The questions posed do not have inputs where I can actually figure out what is the underlying issue.
Posted 1 year ago
 If I set a variable, call it d and evaluate d without giving it a value, I simply get d back....no matter how many times I evaluate d.In the simple function I used as an example, when I evaluate that function without defining certain variables, I get the function back with no comment. If I evaluate this function a second time or more, I get the comment back that it evaluates with indeterminate values.If a more complicated function with the accuracy and precision and working precision limits set but no variables defined, again, the first evaluation gives back the function with no comments. The second and later evaluations with the variable still not defined gives back the statement that it tried to evaluate the function and that the function's precision was less than the working precision. What can this possibly mean, since the function should not evaluate at all? And, I do not want some spurious evaluation to "contaminate" the function.
Posted 1 year ago
 I don't understand what the expected output is for the example. You have variables x and a but you specify limits only for a, Second, what is the last parameter for? Usually, limits of integration are, for example, like {a, 1., 2.} -- the extra value doesn't seem to have any use -- and it is not included in the documentation.The error message is clear. Since you did not specify any range for x, this is a symbolic integration, and that does not work for NIntegrate. If you replace x with a number, the result appears immediately.If I leave off the last parameter, I get a different result, but the documentation does not cover any limits other than {x, xmin, xmax}.
Posted 1 year ago
 There are two issues. The first is that if there is nothing to execute, then why show any results? I have input the function NIntegrate[x^a, {a, 1., 2., .1}], it should not execute, and when it is first executed, in fact I simply get back NIntegrate[x^a, {a, 1., 2., .1}]. If I re-execute an evaluation on the same function, it evaluates. Why?My goal is to set fff=NIntegrate[x^a, {a, 1., 2., .1}] and then to use fff over variable x to do a parametric evaluation. But if, when setting fff, the function evaluates to something, what is it evaluating to and what is the function fff that I am using? I don't really have to do it this way but I did and I got an output that is ambiguous...at least to me. To my simple way of looking at things, if it should not evaluate, and so, then, it should not give back something I don't understand.I simply want to understand what is going on and what the "false" evaluation is leaving hidden in or associated with the function fff.
Posted 1 year ago
 (1) I have never seen NIntegrate[x^a, {a, 1., 2., .1}] do anything other than return unevaluated. Below is the behavior i get every time. In[89]:= NIntegrate[x^a, {a, 1., 2., .1}] During evaluation of In[89]:= NIntegrate::inumr: The integrand x^a has evaluated to non-numerical values for all sampling points in the region with boundaries {{1.,2.}}. (* Out[89]= NIntegrate[x^a, {a, 1., 2., 0.1}] *) Notice the output is the same as the input (that's what "returning unevaluated" means). If you are getting anything different from this, then either x had been given a value somewhere, or else we (at Wolfram Research) really need to see a screen shot, and also the notebook itself, for further diagnosis.(2) As had been noted, the use of {a, 1., 2., .1} as an integration range is suspect. It almost certainly does not do whatever you might be thinking it does.(3) One can (and typically does) define a function to do a parametrized numeric integration. I show a very simple example of this below, based on the integrand under discussion. f[x_?NumericQ] := Integrate[x^a, {a, 1., 2.}] Table[f[x], {x, .1, 1., .1}] (* Out[96]= {0.0390865033713, 0.0994135895295, 0.174422544467, \ 0.261925600305, 0.360673760222, 0.469827645353, 0.588771382932, \ 0.717027218836, 0.854209942293, 1.} *) 
Posted 1 year ago
 @GeorgeWoodrowIII The multi-point form is not heavily covered in the NIntegrate reference page documentation but it is shown under Scope > Basic Uses in the example in "Along a piecewise linear contour in the complex plane:". That said, the use in this post seems unlikely to be what was intended-- why would one integrate along a path from 1 to 2 and then back to 0.1, instead of just integrating from 1 to 0.1 to begin with?