Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rationalize(878159.58,1*10^-12) - Rationalize(431874.32,1*10^-12) // N returns wrong result #1065

Open
tranleduy2000 opened this issue Sep 15, 2024 · 5 comments

Comments

@tranleduy2000
Copy link
Collaborator

tranleduy2000 commented Sep 15, 2024

There is the input:

Rationalize(878159.58,1*10^-12) - Rationalize(431874.32,1*10^-12) // N

That gives wrong result:

𝟦𝟦𝟨𝟤𝟪𝟧.𝟥
image image

Expected result:

446285.25999999995
@tranleduy2000
Copy link
Collaborator Author

tranleduy2000 commented Sep 15, 2024

There is too much precision loss for the following input:

m = {{-2,-2,4},
{-1,-3,7},
{2,4,6}};

s= Transpose[Eigenvectors[m]];

j = {{1+Sqrt[61],0,0},{0,1-Sqrt[61],0},{0,0,-1}};

s1 = Inverse[s];

s.j.s1 // N
image

The result should be

{{-2.0,-2.0,4.0},
{-1.0,-3.0,7.0},
{2.0,4.0,6.0}}

@axkr
Copy link
Owner

axkr commented Sep 15, 2024

That gives wrong result:

𝟦𝟦𝟨𝟤𝟪𝟧.𝟥

It's only the "output format" if you get the result as "input format"

Rationalize(878159.58,1*10^-12) - Rationalize(431874.32,1*10^-12) // N //InputForm

it returns 446285.26

@axkr
Copy link
Owner

axkr commented Sep 15, 2024

s.j.s1 // N

You can get a better result, if you increase the precision:

N[s.j.s1 ,30]

A simplification before the numeric calculation may also get a better result.

s.j.s1 // FullSimplify // N

@axkr
Copy link
Owner

axkr commented Sep 21, 2024

The result should be

{{-2.0,-2.0,4.0},
{-1.0,-3.0,7.0},
{2.0,4.0,6.0}}

See test case testNIssue1065()

with Config.USE_EXTENDED_PRECISION_IN_N = true; you can enable using apfloat for calculating in better precision.

@axkr
Copy link
Owner

axkr commented Sep 25, 2024

with Config.USE_EXTENDED_PRECISION_IN_N = true; you can enable using apfloat for calculating in better precision.

Note: Because of using Simplify for evaluating the Dot(...) function:

it's not necessary anymore to use Config.USE_EXTENDED_PRECISION_IN_N = true at least for this Eigenvectors example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants