Message Boards Message Boards

0
|
6622 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

[?] Set WorkingPrecision in NIntegrate?

Posted 7 years ago

Consider the following input:

In[1]:= c = 1.2``200; n = 7;
2/Pi NIntegrate[ChebyshevU[n, x]^2 Sqrt[1 - x^2], {x, -1, 1}, 
  WorkingPrecision -> 200]
(2 I)/(c^2 Pi) 
 NIntegrate[ ChebyshevU[n, k/(I c)]^2 Sqrt[c^2 + k^2], {k, I c, -I c},
   WorkingPrecision -> 200]

Out[2]= 1.\
0000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000

During evaluation of In[1]:= NIntegrate::precw: The precision of the \
argument function \
(\[Sqrt](1.\
4400000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000\
00000000000000000000000000000000000000000000000000000000000+k^2) \
((0.+<<18>> \[ImaginaryI]) k+<<2>>+(0.+<<1>>) <<1>>)^2) is less than \
WorkingPrecision (200.`). >>

Out[3]= 1.\
0000000000000000838554115034660068008817729444357599619488431719194210\
2454049745574593544006347656250000000000000000000000000000000000000000\
00000000000000000000000000000000000000000000000000000000000

These two integrals are related by a simple transformation. Why then the first integral is calculated with the prescribed accuracy, and the second is not? What to change in the code so that the second integral would also be computed with accuracy 200 digits?

3 Replies

It's because Precision[c^2] is 199.778. I would set c = 12/10 (infinite precision), unless the uncertainty in c is an important consideration.

POSTED BY: Michael Rogers

Yes, if I set c=12/10, it works well. However, it is important for me to understand how to work with c=1.2, because I got c as a result of computation of some function, and i don't want to rewrite it each time as a ratio of two integers.

i still don't understand the following issues: 1) Precision[c^2] is 199.788, but the Output[3] gives only 16 correct digits. It is far from 199 digits. 2) If i set c=1.2``201, then Precision[c^2] is 200.778, but the Output[3] still gives only 16 digits.

Concerning setting the precision of c: Have you seen Rationalize and SetPrecision? Consider using c = Rationalize[1.2], c = Rationalize[1.2, 0], c = Rationalize[Rationalize[1.2], 0] or c = SetPrecision[1.2, Infinity]. And so forth. You can substitute for 1.2 the computed value/variable in your actual use-cases.

I get an accuracy of 199.5 correct digits for c = 1.2`200 and 199.9 digits for c = 1.2`201 in V11.1.1. For WorkingPrecision -> 200, the default PrecisionGoal for a one-dimensional integral is half (I think), or 100 digits. In both cases, I'm getting considerably more accuracy than requested. So I can't really comment on your results, since I cannot reproduce them. -- Aha, I may have a guess. The 0.+<<18>>... in the error message has a machine-precision float 0., which suggests a machine-precision parameter was used. There are none in your code, but if I set n = 7. (to a machine-precision float, instead of an exact integer 7), then the following reproduces the expression in your error message.

Sqrt[c^2 + k^2] ChebyshevU[7., k/(I c)]^2 // Short[#, 3] &

Note the differences between WorkingPrecision, PrecisionGoal, and AccuracyGoal in NIntegrate. With PrecisionGoal -> p and AccuracyGoal -> a, NIntegrate tries to make the estimated error for a result $I$ less than $10^{-a} + |I|\,10^{-p}$. They control the algorithm. WorkingPrecision on the other hand controls the rounding error in the computations. For convenience, when PrecisionGoal and AccuracyGoal are set to Automatic, Mathematica makes them depend on WorkingPrecision, usually setting them to half the setting for WorkingPrecision. One generally needs a higher working precision than the precision goal.

POSTED BY: Michael Rogers
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract