Questions tagged [precision-and-accuracy]
622 questions
12
votes
4 answers
How to deal with loss of significance in the case $f(x) = \sqrt{x+2} -\sqrt{x}$?
I would like to evaluate the expression $f(x) = \sqrt{x+2} -\sqrt{x}$ with cases when $x = 3.2 \times 10^{30}$ and $x= 3.2 \times 10^{16}$. I tried using N[Sqrt[x+2] - Sqrt[x], 100] and
ScientificForm[Sqrt[x+2] - Sqrt[x], 100], both yielding 0 as an…
Rico
- 133
- 4
11
votes
2 answers
Floating point operations — division vs multiplication; how do they affect accuracy?
Given two functions:
f[x_] := x ((x + 1)^(1/2) - x^(1/2))
g[x_] := x/((x + 1)^(1/2) + x^(1/2))
Which one is more accurate?
Side note: If you could explain why, that would really help me out, I have a feeling it's f(x) as there isn't a denominator…
Claire Blackman
- 113
- 1
- 5
7
votes
1 answer
Change system options in package
I use Mathematica mostly for numerical calculations, and sometimes the performance of numerical calculations can be greatly improved if the high-precision arithmetic can be switched off by
Developer`SetSystemOptions["CatchMachineUnderflow" ->…
xslittlegrass
- 27,549
- 9
- 97
- 186
7
votes
2 answers
Large Number times Tiny Number
A (maybe noob) question: Let
a = 1234567891234567889998.5
b = 1234567891234567889999.5
Mathematica (v8) yields for
a*0.5 - b*0.5
--> 0. (wrong answer) and
(a - b)*0.5
--> -0.5 (correct answer)
although both expressions a*0.5 - b*0.5 and (a -…
Michelle Rudolph
- 71
- 1
6
votes
1 answer
Output precision
I've solved some equations using FindRoot and then computed some values. Now when I print the output, I only get a certain precision
{{0.01, 496.983, 61.3147, 80., 0.047},
{0.02, 496.983, 61.3147, 80., 0.047},
{0.03, 496.983, 61.3147, 80.,…
Amatya
- 6,888
- 3
- 26
- 35
6
votes
3 answers
SetAccuracy behavior
I'm puzzled by the output I get from SetAccuracy. According to the documentation, when SetAccuracy is used to increase the accuracy of a number, the number is padded with zeros.
But, let's take a look at a couple of examples:
SetAccuracy[1.2, 5]
(*…
VLC
- 9,818
- 1
- 31
- 60
5
votes
1 answer
Mysterious behavior of Precision for complex arrays
Mysterious behavior of Precision:
{{1.0+I*0.0},{0.0+I*0.0}} // SetPrecision[#,30]& // Precision // Print;
0.
{{1.0},{0.0}} // SetPrecision[#,30]& // Precision // Print;
30.
Why is the precision zero in the first instance, but not the…
John Sidles
- 51
- 1
5
votes
1 answer
Find the number of correct digits to compare approximation with exact value
A) For simple example suppose i want to approximate $\pi$ using $\frac{22}{7}$ and $\frac{355}{113}$.
In[120]:=
N[Pi, 10]
N[22/7, 10]
N[355/113, 10]
Out[120]= 3.141592654
Out[121]= 3.142857143
Out[122]= 3.141592920
I need a function to find the…
user516076
- 373
- 1
- 8
4
votes
1 answer
Why is chop being ignored?
If I use
Chop[10^-4, 10^-3]
then I'd expect the output to be zero. However, this is not the case. There is of course a very easy workaround since I can define my own "chop"
chop[x_,dx_] := If[Abs[x] < dx, 0, x]
but why is the innate version…
JeffDror
- 1,880
- 1
- 13
- 29
4
votes
1 answer
Exp[x] answers 1 for small x
I'm getting the same answer "1" for Exp[x] with x less than "1.1*10^-16", and I really need to calculate much smaller numbers (in order of 10^-40).
I tried using SetPrecision[Exp[x],1000].
Obviously I'm doing something wrong. #_-
I've searched about…
Pedram
- 330
- 2
- 10
3
votes
2 answers
How to get the digits after the decimal point
I have N[Sqrt[2], 8] which outputs 0.4142136
How do I get the 4142136 part out of it?
I tried RealDigits[N[Sqrt[2], 8] - Floor@Sqrt[2]][[1]] but because in the solution above the last digit was rounded up (0.41421356), it doesn't come out the same :…
Raksha
- 633
- 1
- 6
- 19
3
votes
1 answer
Deferent results depending on the input form of the matrix
Why is it so,
N[Eigenvectors[{{1., 0.5, 4.}, {2., 1., 2.}, {0.25, 0.5, 1.}}]]
returns:
{{-0.603584, -0.760468, -0.239532}, {0.301792 -
0.522719 I, -0.760468 + 0. I,
0.119766 + 0.207441 I}, {0.301792 + 0.522719 I, -0.760468 + 0. I,
…
jano
- 31
- 1
3
votes
1 answer
the default option of NDSolve
How should I find out what the default value of Accuracy and Precision is in the NDSolve?
I have a pde that when I asked it to solve for me the equation with a special Accuracy and precision it gave me back an error, but if I live the NDSolve with…
kaveh karbakhsh
- 31
- 4
3
votes
3 answers
Equality of almost equal lists
Can you help me with this common problem I have?
Given two lists:
a={339.66666666666697`, -287.4444444444446`, 0.`}
and
b = {339.6666666666667`, -287.44444444444684`, -2.1316282072803006`*^-13}
Equal[a,b] gives False…
Александр Миллер
- 385
- 1
- 7
3
votes
1 answer
About Numerical Precision Related with Zeros
I encounted the following precision issue. I define c = a + b, but the result for 'c - a - b' does not equal zero. I am not sure how to resolve this.
'''
In[1]:=
a = N[Exp[3]];
b = N[Exp[4]];
c = a + b;
c - a - b
Out[4]= 7.10543*10^-15
'''
HB_LUKE
- 33
- 3