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.

I am optimizing an equation that involves a number of trigonometric functions and Exp[]. How do I make sure that all my calculations have an accuracy of 120-200 digits after the decimal point? This includes the accuracy of Exp[] and trig functions.

To get my point across, here is part of the equation: z[x_, y_]:= Exp[Sin[60.0*x]] + Sin[50.0*Exp[y]]

Mathematica lets you control Precision of computations (which is total number of digits in the number) with two global variables - $MinPrecision and $MaxPrecision. However, I am not looking for precision.

share|improve this question
2  
Do you know that keeping expressions in terms of integers and rationals will keep exact values? Try NestList[16 # (1 - #)/3 &, 1/5, 4] ? Though for heavy computations you will lose speed. –  Vitaliy Kaurov Jul 1 '12 at 17:53
    
I am aware that Mathematica will give me exact values for integer & rational calculations, but my calculations are far from exact. –  newprint Jul 1 '12 at 18:00
add comment

3 Answers

Short answer

If you want Mathematica to return arbitrary-precision calculations with (approximately) a given Accuracy you could ask for it in MantissaExponent form:

MantissaExponent[Exp[150] 123``50][[1]] // Accuracy
52.8558

Supporting information

Accuracy of input numbers can be set with double backticks:

12345.5678``50   // Accuracy
12345``50        // Accuracy
50.
50.

Single backticks define Precision:

12345.5678`50   // Precision
12345`50        // Precision
50.
50.

A "constant accuracy" doesn't make much sense for floating point calculations. Mathematica tracks and preserves Precision. This is called "arbitrary-precision" after all.

Exp[150] 123`50  // Precision
Exp[150] 123``50 // Accuracy
50.
-15.1442
share|improve this answer
1  
I think in the "Short answer" section you use wrong formulation because MantissaExponent does not alter the accuracy of the result (I know, you know it - just for correctness). The right formulation could be: "If you want Mathematica to give you the accuracy of the result of calculations you could ask for it using MantissaExponent form: ..." –  Alexey Popkov Jul 2 '12 at 17:43
    
@Alexey I wasn't sure how to say what I wanted to. I'll try to rephrase it as you suggest later today. –  Mr.Wizard Jul 2 '12 at 18:00
    
One problem is that Wolfram's understanding of precision and accuracy is significantly misleading and the second one is that you use in this sentence the term "accuracy" with another meaning: the number of precise digits right to the decimal point in ScientificForm. In other words, it is something always approximately equal to Precision minus 1. –  Alexey Popkov Jul 2 '12 at 18:14
    
Discussion on Precision and Accuracy in Mathematica: groups.google.com/d/msg/comp.soft-sys.math.mathematica/… –  Alexey Popkov Jul 2 '12 at 18:20
add comment

If you use inexact constant in your equation it helps if you increase their accuracy as well. You can do that easily using the backtick notation:

z[x_, y_] := Exp[Sin[60.0`200*x]] + Sin[50.0`200*Exp[y]]
z[SetAccuracy[20., 200], SetAccuracy[20., 200]] // Accuracy

190.0318717

share|improve this answer
    
Initially, I used the backtick for floating point values as well(I read about in Mathematical Cookbook), though it becomes somewhat cumbersome within long equation. –  newprint Jul 2 '12 at 1:19
add comment

How about something like

z[x_, y_] := Exp[Sin[60*x]] + Sin[50*Exp[y]]
z[SetAccuracy[20., 200], SetAccuracy[20., 200]] // Accuracy

does this not do what you need?

share|improve this answer
    
In[8]:= z[SetAccuracy[20., 200], SetAccuracy[20., 200]] // Accuracy Out[8]= 13.6508 Don't think it worked. –  newprint Jul 1 '12 at 18:25
1  
@newprint Sorry, I forgot to add the modified definition of z I used. Or, is it that you simply don't know the coeffs? Because that's different... –  acl Jul 1 '12 at 18:47
    
Thanks, I understood the SetAccuracy and // Accuracy –  newprint Jul 2 '12 at 1:13
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.