Message Boards Message Boards

GROUPS:

Why does MinPrecision affect the result of computation?

Posted 6 months ago
664 Views
|
7 Replies
|
1 Total Likes
|

Please look at the code sample given here. The matrix t.M has a precision of 19.657. When I set $MinPrecision to 20, I expected that the elements will change a little (in 20th digit) and eigenvalues may be slightly different. But notice that some of the eigenvalues now are different in the 4th decimal place. Is it possible to explain and fix this?

In[1]:= $Version

Out[1]= "10.0 for Mac OS X x86 (64-bit) (June 29, 2014)"

In[2]:= t = DiagonalMatrix[{1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1}];
M = {{0.7137918381815571041`20., 0, 0, 
    0, -0.0818845598913793050449093616880474190251622093580702678455`\
20. + 0``20.79396386163813 I, 0, 0, 
    0.2343688308366258291603440704025530543285644606954919531622`20. \
+ 0``20.337266027259396 I, \
-0.1781456332806043268557912392799948161104770751588753908233`20. + 
     0``21.549512304350156 I, 0, 
    0, -0.5098859155622219674745857688604570097577534403206352266676`\
20. + 0``21.092814469971415 I}, {0, 0.7137918381815571041`20., 0, 0, 
    0, -0.0818845598913793050449093616880474190251622093580702678455`\
20. + 0``20.79396386163813 I, \
-0.2343688308366258291603440704025530543285644606954919531622`20. + 
     0``20.337266027259396 I, 0, 
    0, -0.1781456332806043268557912392799948161104770751588753908233`\
20. + 0``21.549512304350156 I, 
    0.5098859155622219674745857688604570097577534403206352266676`20. \
+ 0``21.092814469971415 I, 0}, {0, 0, 0.7137918381815571041`20., 0, 0,
     0.2343688308366258291603440704025530543285644606954919531622`20. \
+ 0``20.337266027259396 I, \
-0.0818845598913793050449093616880474190251622093580702678455`20. + 
     0``20.79396386163813 I, 0, 
    0, -0.5098859155622219674745857688604570097577534403206352266676`\
20. + 0``21.092814469971415 I, \
-0.1781456332806043268557912392799948161104770751588753908233`20. + 
     0``21.549512304350156 I, 0}, {0, 0, 0, 
    0.7137918381815571041`20., \
-0.2343688308366258291603440704025530543285644606954919531622`20. + 
     0``20.337266027259396 I, 0, 
    0, -0.0818845598913793050449093616880474190251622093580702678455`\
20. + 0``20.79396386163813 I, 
    0.5098859155622219674745857688604570097577534403206352266676`20. \
+ 0``21.092814469971415 I, 0, 
    0, -0.1781456332806043268557912392799948161104770751588753908233`\
20. + 0``21.549512304350156 I}, \
{-0.0818845598913793050449093616880474190251622093580702678455`20. + 
     0``20.79396386163813 I, 0, 
    0, -0.2343688308366258291603440704025530543285644606954919531622`\
20. + 0``20.337266027259396 I, 0.7137918381815571041`20., 0, 0, 
    0, -0.1060166164759502210167654308580758022516732692772395255612`\
20. + 0``20.835887101121145 I, 0, 0, 
    0.3034392623674499766124318272572987558005177815882278376081`20. \
+ 0``20.379189266742404 I}, {0, \
-0.0818845598913793050449093616880474190251622093580702678455`20. + 
     0``20.79396386163813 I, 
    0.2343688308366258291603440704025530543285644606954919531622`20. \
+ 0``20.337266027259396 I, 0, 0, 0.7137918381815571041`20., 0, 0, 
    0, -0.1060166164759502210167654308580758022516732692772395255612`\
20. + 0``20.835887101121145 I, \
-0.3034392623674499766124318272572987558005177815882278376081`20. + 
     0``20.379189266742404 I, 
    0}, {0, -0.\
2343688308366258291603440704025530543285644606954919531622`20. + 
     0``20.337266027259396 I, \
-0.0818845598913793050449093616880474190251622093580702678455`20. + 
     0``20.79396386163813 I, 0, 0, 0, 0.7137918381815571041`20., 0, 0,
     0.3034392623674499766124318272572987558005177815882278376081`20. \
+ 0``20.379189266742404 I, \
-0.1060166164759502210167654308580758022516732692772395255612`20. + 
     0``20.835887101121145 I, 
    0}, {0.2343688308366258291603440704025530543285644606954919531622`\
20. + 0``20.337266027259396 I, 0, 
    0, -0.0818845598913793050449093616880474190251622093580702678455`\
20. + 0``20.79396386163813 I, 0, 0, 0, 
    0.7137918381815571041`20., \
-0.3034392623674499766124318272572987558005177815882278376081`20. + 
     0``20.379189266742404 I, 0, 
    0, -0.1060166164759502210167654308580758022516732692772395255612`\
20. + 0``20.835887101121145 I}, \
{-0.1781456332806043268557912392799948161104770751588753908233`20. + 
     0``21.549512304350156 I, 0, 0, 
    0.5098859155622219674745857688604570097577534403206352266676`20. \
+ 0``21.092814469971415 I, \
-0.1060166164759502210167654308580758022516732692772395255612`20. + 
     0``20.835887101121145 I, 0, 
    0, -0.3034392623674499766124318272572987558005177815882278376081`\
20. + 0``20.379189266742404 I, 0.7137918381815571041`20., 0, 0, 
    0}, {0, -0.\
1781456332806043268557912392799948161104770751588753908233`20. + 
     0``21.549512304350156 I, \
-0.5098859155622219674745857688604570097577534403206352266676`20. + 
     0``21.092814469971415 I, 0, 
    0, -0.1060166164759502210167654308580758022516732692772395255612`\
20. + 0``20.835887101121145 I, 
    0.3034392623674499766124318272572987558005177815882278376081`20. \
+ 0``20.379189266742404 I, 0, 0, 0.7137918381815571041`20., 0, 0}, {0,
     0.5098859155622219674745857688604570097577534403206352266676`20. \
+ 0``21.092814469971415 I, \
-0.1781456332806043268557912392799948161104770751588753908233`20. + 
     0``21.549512304350156 I, 0, 
    0, -0.3034392623674499766124318272572987558005177815882278376081`\
20. + 0``20.379189266742404 I, \
-0.1060166164759502210167654308580758022516732692772395255612`20. + 
     0``20.835887101121145 I, 0, 0, 0, 0.7137918381815571041`20., 
    0}, {-0.5098859155622219674745857688604570097577534403206352266676\
`20. + 0``21.092814469971415 I, 0, 
    0, -0.1781456332806043268557912392799948161104770751588753908233`\
20. + 0``21.549512304350156 I, 
    0.3034392623674499766124318272572987558005177815882278376081`20. \
+ 0``20.379189266742404 I, 0, 
    0, -0.1060166164759502210167654308580758022516732692772395255612`\
20. + 0``20.835887101121145 I, 0, 0, 0, 0.7137918381815571041`20.}};

In[4]:= Precision[t.M]

Out[4]= 19.657

In[5]:= Eigenvalues[t.M]

Out[5]= {-0.6434260521385389832, 0.6434260521385389832, \
-0.6434260521385389832, 0.6434260521385389832, 0.5495328432664610538, \
-0.5495328432664610537, 0.5495328432664610537, \
-0.5495328432664610537, -0.31288706030886822758, \
0.31288706030886822757, 0.31288706030886822757, \
-0.31288706030886822757}

In[6]:= $MinPrecision = 19;
Eigenvalues[t.M]

Out[7]= {-0.6434260521385389832, 0.6434260521385389832, \
-0.6434260521385389832, 0.6434260521385389832, 0.5495328432664610538, \
-0.5495328432664610537, 0.5495328432664610537, \
-0.5495328432664610537, -0.31288706030886822758, \
0.31288706030886822757, 0.31288706030886822757, \
-0.31288706030886822757}

In[8]:= $MinPrecision = 20;
Eigenvalues[t.M]

Out[9]= {0.64342605213853898318, -0.64342605213853898318, \
0.64339804735557256573, -0.64332543749200075174, \
0.54954065607255415410, -0.54953284326646105374, \
0.54953284326646105374, -0.54931890613227757447, \
-0.31288706030886822757, 0.31288706030886822757, \
-0.31288313900183744618, 0.31281340426449117539}
7 Replies

Something wrong in your version? In my version all looks as it is supposed - slight change with a slight change in the MinPrecision:

In[1]:= $Version
t = DiagonalMatrix[{1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1}];
M = {{0.7137918381815571041`20., 0, 0, 
    0, -0.0818845598913793050449093616880474190251622093580702678455`\
20. + 0``20.79396386163813 I, 0, 0, 
    0.2343688308366258291603440704025530543285644606954919531622`20. \
+ 0``20.337266027259396 I, \
-0.1781456332806043268557912392799948161104770751588753908233`20. + 
     0``21.549512304350156 I, 0, 
    0, -0.5098859155622219674745857688604570097577534403206352266676`\
20. + 0``21.092814469971415 I}, {0, 0.7137918381815571041`20., 0, 0, 
    0, -0.0818845598913793050449093616880474190251622093580702678455`\
20. + 0``20.79396386163813 I, \
-0.2343688308366258291603440704025530543285644606954919531622`20. + 
     0``20.337266027259396 I, 0, 
    0, -0.1781456332806043268557912392799948161104770751588753908233`\
20. + 0``21.549512304350156 I, 
    0.5098859155622219674745857688604570097577534403206352266676`20. \
+ 0``21.092814469971415 I, 0}, {0, 0, 0.7137918381815571041`20., 0, 0,
     0.2343688308366258291603440704025530543285644606954919531622`20. \
+ 0``20.337266027259396 I, \
-0.0818845598913793050449093616880474190251622093580702678455`20. + 
     0``20.79396386163813 I, 0, 
    0, -0.5098859155622219674745857688604570097577534403206352266676`\
20. + 0``21.092814469971415 I, \
-0.1781456332806043268557912392799948161104770751588753908233`20. + 
     0``21.549512304350156 I, 0}, {0, 0, 0, 
    0.7137918381815571041`20., \
-0.2343688308366258291603440704025530543285644606954919531622`20. + 
     0``20.337266027259396 I, 0, 
    0, -0.0818845598913793050449093616880474190251622093580702678455`\
20. + 0``20.79396386163813 I, 
    0.5098859155622219674745857688604570097577534403206352266676`20. \
+ 0``21.092814469971415 I, 0, 
    0, -0.1781456332806043268557912392799948161104770751588753908233`\
20. + 0``21.549512304350156 I}, \
{-0.0818845598913793050449093616880474190251622093580702678455`20. + 
     0``20.79396386163813 I, 0, 
    0, -0.2343688308366258291603440704025530543285644606954919531622`\
20. + 0``20.337266027259396 I, 0.7137918381815571041`20., 0, 0, 
    0, -0.1060166164759502210167654308580758022516732692772395255612`\
20. + 0``20.835887101121145 I, 0, 0, 
    0.3034392623674499766124318272572987558005177815882278376081`20. \
+ 0``20.379189266742404 I}, {0, \
-0.0818845598913793050449093616880474190251622093580702678455`20. + 
     0``20.79396386163813 I, 
    0.2343688308366258291603440704025530543285644606954919531622`20. \
+ 0``20.337266027259396 I, 0, 0, 0.7137918381815571041`20., 0, 0, 
    0, -0.1060166164759502210167654308580758022516732692772395255612`\
20. + 0``20.835887101121145 I, \
-0.3034392623674499766124318272572987558005177815882278376081`20. + 
     0``20.379189266742404 I, 
    0}, {0, -0.\
2343688308366258291603440704025530543285644606954919531622`20. + 
     0``20.337266027259396 I, \
-0.0818845598913793050449093616880474190251622093580702678455`20. + 
     0``20.79396386163813 I, 0, 0, 0, 0.7137918381815571041`20., 0, 0,
     0.3034392623674499766124318272572987558005177815882278376081`20. \
+ 0``20.379189266742404 I, \
-0.1060166164759502210167654308580758022516732692772395255612`20. + 
     0``20.835887101121145 I, 
    0}, {0.2343688308366258291603440704025530543285644606954919531622`\
20. + 0``20.337266027259396 I, 0, 
    0, -0.0818845598913793050449093616880474190251622093580702678455`\
20. + 0``20.79396386163813 I, 0, 0, 0, 
    0.7137918381815571041`20., \
-0.3034392623674499766124318272572987558005177815882278376081`20. + 
     0``20.379189266742404 I, 0, 
    0, -0.1060166164759502210167654308580758022516732692772395255612`\
20. + 0``20.835887101121145 I}, \
{-0.1781456332806043268557912392799948161104770751588753908233`20. + 
     0``21.549512304350156 I, 0, 0, 
    0.5098859155622219674745857688604570097577534403206352266676`20. \
+ 0``21.092814469971415 I, \
-0.1060166164759502210167654308580758022516732692772395255612`20. + 
     0``20.835887101121145 I, 0, 
    0, -0.3034392623674499766124318272572987558005177815882278376081`\
20. + 0``20.379189266742404 I, 0.7137918381815571041`20., 0, 0, 
    0}, {0, -0.\
1781456332806043268557912392799948161104770751588753908233`20. + 
     0``21.549512304350156 I, \
-0.5098859155622219674745857688604570097577534403206352266676`20. + 
     0``21.092814469971415 I, 0, 
    0, -0.1060166164759502210167654308580758022516732692772395255612`\
20. + 0``20.835887101121145 I, 
    0.3034392623674499766124318272572987558005177815882278376081`20. \
+ 0``20.379189266742404 I, 0, 0, 0.7137918381815571041`20., 0, 0}, {0,
     0.5098859155622219674745857688604570097577534403206352266676`20. \
+ 0``21.092814469971415 I, \
-0.1781456332806043268557912392799948161104770751588753908233`20. + 
     0``21.549512304350156 I, 0, 
    0, -0.3034392623674499766124318272572987558005177815882278376081`\
20. + 0``20.379189266742404 I, \
-0.1060166164759502210167654308580758022516732692772395255612`20. + 
     0``20.835887101121145 I, 0, 0, 0, 0.7137918381815571041`20., 
    0}, {-0.5098859155622219674745857688604570097577534403206352266676\
`20. + 0``21.092814469971415 I, 0, 
    0, -0.1781456332806043268557912392799948161104770751588753908233`\
20. + 0``21.549512304350156 I, 
    0.3034392623674499766124318272572987558005177815882278376081`20. \
+ 0``20.379189266742404 I, 0, 
    0, -0.1060166164759502210167654308580758022516732692772395255612`\
20. + 0``20.835887101121145 I, 0, 0, 0, 0.7137918381815571041`20.}};
Precision[t.M]
Eigenvalues[t.M]
$MinPrecision = 19;
Eigenvalues[t.M]
$MinPrecision = 20;
Eigenvalues[t.M]



Out[1]= "11.3.0 for Microsoft Windows (64-bit) (March 7, 2018)"

Out[4]= 19.657

Out[5]= {-0.6434260521385389832, 0.6434260521385389832, \
-0.6434260521385389832, 0.6434260521385389832, 0.5495328432664610538, \
-0.5495328432664610537, 0.5495328432664610537, \
-0.5495328432664610537, -0.31288706030886822758, \
0.31288706030886822757, -0.31288706030886822757, \
0.31288706030886822757}

Out[7]= {-0.6434260521385389832, 0.6434260521385389832, \
-0.6434260521385389832, 0.6434260521385389832, 0.5495328432664610538, \
-0.5495328432664610537, 0.5495328432664610537, \
-0.5495328432664610537, -0.31288706030886822758, \
0.31288706030886822757, -0.31288706030886822757, \
0.31288706030886822757}

Out[9]= {0.64342605213853898318, -0.64342605213853898318, \
0.64342605213853898318, -0.64342605213853898318, \
-0.54953284326646105374, 0.54953284326646105374, \
-0.54953284326646105374, 0.54953284326646105374, \
-0.31288706030886822757, 0.31288706030886822757, \
-0.31288706030886822757, 0.31288706030886822757}

Thank you very much for a very prompt reply. We have a more recent version in our office. I will run the file and post results tomorrow. But at the same time, don't you think that these kind of bugs are somewhat unexpected in 10.0 which is fairly advanced version of Mathematica?

By chance I have two other versions - 8 and 11.0.1. In the eighth version, really there are big differences with a small change in the MinPrecision:

"11.0.1 for Microsoft Windows (64-bit) (September 20, 2016)"

19.657

{-0.6434260521385389832, -0.6434260521385389832, \
0.6434260521385389832, 0.6434260521385389832, 0.5495328432664610538, \
-0.5495328432664610537, -0.5495328432664610537, \
0.5495328432664610537, -0.31288706030886822758, \
0.31288706030886822757, -0.31288706030886822757, \
0.31288706030886822757}

{-0.6434260521385389832, -0.6434260521385389832, \
0.6434260521385389832, 0.6434260521385389832, 0.5495328432664610538, \
-0.5495328432664610537, -0.5495328432664610537, \
0.5495328432664610537, -0.31288706030886822758, \
0.31288706030886822757, -0.31288706030886822757, \
0.31288706030886822757}

{0.64342605213853898318, 0.64342605213853898318, \
-0.64342605213853898318, -0.64342605213853898318, \
-0.54953284326646105374, -0.54953284326646105374, \
0.54953284326646105374, 0.54953284326646105374, \
-0.31288706030886822757, -0.31288706030886822757, \
0.31288706030886822757, 0.31288706030886822757}


"8.0 for Microsoft Windows (64-bit) (October 7, 2011)"

19.657

{-0.6434260521385389832, 0.6434260521385389832, \
-0.6434260521385389832, 0.6434260521385389832, 0.5495328432664610538, \
-0.5495328432664610537, 0.5495328432664610537, \
-0.5495328432664610537, -0.31288706030886822758, \
0.31288706030886822757, 0.31288706030886822757, \
-0.31288706030886822757}

{-0.6434260521385389832, 0.6434260521385389832, \
-0.6434260521385389832, 0.6434260521385389832, 0.5495328432664610538, \
-0.5495328432664610537, 0.5495328432664610537, \
-0.5495328432664610537, -0.31288706030886822758, \
0.31288706030886822757, 0.31288706030886822757, \
-0.31288706030886822757}

{0.64342605213853898318, -0.64342605213853898318, \
0.64339804735557256573, -0.64332543749200075174, \
0.54954065607255415410, -0.54953284326646105374, \
0.54953284326646105374, -0.54931890613227757447, \
-0.31288706030886822757, 0.31288706030886822757, \
-0.31288313900183744618, 0.31281340426449117539}

It's amazing but I also have version 10 on another computer. In this version also there is a similar bug as in version 8:

"10.0 for Microsoft Windows (64-bit) (June 29, 2014)"

19.657

{-0.6434260521385389832, 0.6434260521385389832, \
-0.6434260521385389832, 0.6434260521385389832, 0.5495328432664610538, \
-0.5495328432664610537, 0.5495328432664610537, \
-0.5495328432664610537, -0.31288706030886822758, \
0.31288706030886822757, 0.31288706030886822757, \
-0.31288706030886822757}

{-0.6434260521385389832, 0.6434260521385389832, \
-0.6434260521385389832, 0.6434260521385389832, 0.5495328432664610538, \
-0.5495328432664610537, 0.5495328432664610537, \
-0.5495328432664610537, -0.31288706030886822758, \
0.31288706030886822757, 0.31288706030886822757, \
-0.31288706030886822757}

{0.64342605213853898318, -0.64342605213853898318, \
0.64339804735557256573, -0.64332543749200075174, \
0.54954065607255415410, -0.54953284326646105374, \
0.54953284326646105374, -0.54931890613227757447, \
-0.31288706030886822757, 0.31288706030886822757, \
-0.31288313900183744618, 0.31281340426449117539}
Posted 6 months ago

For a fix, if you remove the imaginary parts, e.g. with Eigenvalues[Chop[t.M]] or Eigenvalues[Re[t.M]], the problem goes away in 10.4.3.

The issue seems to affect NSolve, too. For instance, we get the same errors in the eigenvalues:

x /. NSolve[CharacteristicPolynomial[t.M, x] == 0, x]
Block[{$MinPrecision = 20},
 x /. NSolve[CharacteristicPolynomial[t.M, x] == 0, x]
 ]
(*
{-0.6434261, -0.6434261, -0.5495328, -0.5495328,
 -0.3128871, -0.3128871, 0.3128871, 0.3128871,
 0.5495328, 0.5495328, 0.6434261, 0.6434261}

{-0.6434260521385, -0.6433254374920, -0.5495328432665, -0.5493189061323,
 -0.3128870603089, -0.3128831390018, 0.31281340426449, 0.31288706030887,
 0.549532843266, 0.549540656073, 0.643398047356, 0.643426052139}
*)

Thank you for your reply. The general matrix in our case has complex numbers so we cant use real part alone. Chop would be fine here but it will also reduce the accuracy by turning small numbers to 0, is it not true?

Is it possible that $MinPrecision affects the small numbers, I mean 0. kind?

Executed the file in my office and I can confirm that 10.4.0 has the same bug but 11.0.0 does not.

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