Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

How can I set the output precision of the following statement to 10 decimal places? I was looking through the documentation, and for some reason, all I could find was Accuracy[] or Precision[].

f[x_] := E^Cos[x]
NIntegrate[f[x], {x, 0, 2*Pi}]

Which, by default, evaluates to:

7.95493

Thank you for your time.

share|improve this question
2  
This is all in the documentation: N, guides to numerical precision, presentation of numbers using NumberForm. Please at least make some effort with the documentation. –  Verbeia Mar 28 '12 at 3:56
    
@Verbeia I was looking through the documentation, and for some reason, all I could find was Accuracy[] or Precision[] but nothing like what Artes mentioned. –  spryno724 Mar 28 '12 at 3:58
2  
It is helpful to mention this in your question, so we know what you've tried. Anyway, the documentation for Precision links to the tutorial I mentioned and to the guide page that mentions PrecisionGoal and AccuracyGoal. It was all one click away. –  Verbeia Mar 28 '12 at 4:04
    
Thank you Verbeia. I will keep this in mind! –  spryno724 Mar 28 '12 at 4:06
1  
It's notable that the documentation for Precision links only indirectly through the tutorials to NumberForm. The direct links are only Accuracy, RealExponent, N, Chop, SetPrecision, MachineNumberQ, MachinePrecision, PrecisionGoal, WorkingPrecision, ExactNumberQ, NumberMarks. IMO, it'a a lot to go trawling through when looking for this answer. –  Reb.Cabin Mar 31 '12 at 0:07
add comment

4 Answers

up vote 5 down vote accepted
NIntegrate[f[x], {x, 0, 2*Pi}, WorkingPrecision -> 15, PrecisionGoal -> 10]
 7.95492652101285
share|improve this answer
    
Oh yeah! Just what I needed. Thank you, Artes! –  spryno724 Mar 28 '12 at 3:56
add comment

The number of digits displayed for machine reals can also be controlled via a setting in the preferences dialog. Under Appearance > Formatting > Numbers, change the value for Number of digits displayed in output:

In[4]:= f[x_] := E^Cos[x]
In[5]:= NIntegrate[f[x], {x, 0, 2*Pi}]

Out[5]= 7.954926521

Note that this doesn't affect arbitrary-precision numbers, which show the digits appropriate for their precisions (shown in these examples after the backticks):

In[6]:= 1.23456789`4

Out[6]= 1.235

In[7]:= 1.23456789`14

Out[7]= 1.2345678900000
share|improve this answer
add comment

If you just want "10 decimal places" - you already have them and more. Mathematica just displays shorter version. You get your answer on default with 16 significant digits, - use NumberForm to see it:

f[x_] := E^Cos[x]
NumberForm[NIntegrate[f[x], {x, 0, 2*Pi}], 100]
 7.954926521012846

I intentionally exaggerated with 100 digit precision so you can see where the default digits are cut off. Also if SHIFT+ENTER (evaluate) your answer/number (output cell), you will see it again - your 16 digits appear in the input and shorten in the output:

In[1]:= 7.954926521012846`

Out[1]= 7.95493
share|improve this answer
add comment

Use in the following way also.

 SetPrecision[NIntegrate[f[x], {x, 0, 2*Pi}], 15]
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.