# Inconsistent results from Wolfram Cloud [closed]

More specifically, I was using the "no sign-in" option of Wolfram Programming Lab.

I was trying to solve a matrix problem, with the following code:

ClearAll["Global*"]
m={{2,0},{0,1}}*2500;
k={{3,-1},{-1,1}}*20000 Pi^2;
w1=N[2Pi,5];
w2=6.2832;
D1=Det[k-w1^2*m]
D2=Det[k-w2^2*m]


Since the numerical values of w1 and w2 should be close, I expect the numerical values of D1 and D2 should also be close. Strangely, Wolfram Cloud gives very different values: It took me a whole night to pin down this segment of code. I don't know if this is only due to my computer/browser, or some one else, if runs the same code, will have same problem? What happened?

Edit

Suppose I would like to compare the determinant using exact symbolic $$2\pi$$ and function N[2Pi,5]

ClearAll["Global*"]
m={{2,0},{0,1}}*2500;
k={{3,-1},{-1,1}}*20000 Pi^2;
w1=N[2Pi,5];
w2=2Pi;
D1=Det[k-w1^2*m]
D2=Det[k-w2^2*m]


The result is not exactly the same: So, is N[2Pi,5] exactly equal to $$2\pi$$ or not? What does the function N actually do?

• Suppose small epsilon then ClearAll["Global*"]; m={{2,0},{0,1}}*2500; k={{3,-1},{-1,1}}*20000 Pi^2; w1=2Pi+epsilon; FullSimplify[Det[k-w1^2*m]] returns 12500000*epsilon*(epsilon - 2*Pi)*(epsilon + 4*Pi)*(epsilon + 6*Pi) and for small epsilon that is approximately 12500000*epsilon*-2*Pi*4*Pi*6*Pi== -600000000*epsilon*Pi^3 so any small error in w is multiplied by about 1.86*10^10 in the determinant. – Bill May 24 '19 at 18:39
• No, N[x, p], represents, if possible, the value of x approximated to a precision of p digits. Read the documentation on N. – Michael E2 May 24 '19 at 23:58
• See reference.wolfram.com/language/tutorial/NumbersOverview.html, esp. the tutorials about exact, approximate and arbitrary-precision numbers. – Michael E2 May 25 '19 at 0:00

I get the same result in Mathematica, so it's not a Mathematica Online issue. I don't think it's even a Mathematica issue. It's due to two factors:

1. w1 is not equal to w2, because N doesn't actually truncate 2 Pi to five digits
2. Det[k-w^2*m] changes quickly, so any little inaccuracy in w becomes a big discrepancy in Det[k-w^2*m]

To see #1:

w1 == 2 \[Pi]
(* True *)
w1 - w2
(* -0.0000146928 *)


To see #2:

Plot[Det[k - w^2*m], {w, 6.2831, 6.2833}] • Regarding #1, it appears that the determinants calculated using $2\pi$ and N[2Pi,5] are not exactly the same. I have edited the question. – York Tsang May 24 '19 at 23:59
• Agreed, this is about numeric math and not Mathematica per se (as this response also notes). – Daniel Lichtblau May 25 '19 at 15:13