0
$\begingroup$

I get confusing output from the code below. If I put a number after a variable value, the precision gets set just fine. But if I put a variable after the backtick, MMa multiplies the values.

Three part question: Can anyone make sense of the confusing outputs? Why does N[] give delta the correct precision but not center? How can I create a value for center with precision equal to prec?

center = -1.40115518909205060075`50
center // Precision
center = N[-1.40115518909205060075, 50]
center // Precision

(* -1.4011551890920506007500000000000000000000000000000

50.

-1.4011551890920506008

20.1465 *)

prec = 50
delta = N[(3*10^-19), prec]
center = N[-1.40115518909205060075, prec]
delta // Precision
center // Precision

(* 50

3.0000000000000000000000000000000000000000000000000*10^-19

-1.4011551890920506008

50.

20.1465 *)

center = -1.40115518909205060075` prec
center // Precision

(*

-70.0578

MachinePrecision

*)

$\endgroup$

closed as off-topic by MarcoB, user9660, Michael E2, bbgodfrey, dr.blochwave Mar 7 '16 at 13:25

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – MarcoB, Community, Michael E2, bbgodfrey, dr.blochwave
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ Remember that N does not increase the precision of a number. $\endgroup$ – bbgodfrey Mar 5 '16 at 2:17
  • $\begingroup$ @bbgodfrey It increases the precision of delta in my code. $\endgroup$ – Jerry Guern Mar 5 '16 at 2:18
  • 2
    $\begingroup$ Why not use SetPrecision[] instead? $\endgroup$ – J. M. will be back soon Mar 5 '16 at 2:18
  • 1
    $\begingroup$ 3*10^-19 is an exact (infinite precision) number, and N in this case reduces it to a precision of 50. $\endgroup$ – bbgodfrey Mar 5 '16 at 2:23
2
$\begingroup$

center = -1.40115518909205060075`prec won't work. You simply can't use variables in such expressions because the input processor is not programmed to pass expressions like 1.23`n to an evaluator. It interprets them as 1.23*n and passes that to the evaluator.

I don't know why the input processor works like this, but it has worked that way for as long as I have used Mathematica.

$\endgroup$
  • $\begingroup$ The situation is similar to that of numbers in alternate bases and numbers in abbreviated exponential notation: 2^^1001 and 2*^5 work, but x^^1001 and 2*^x don't. $\endgroup$ – J. M. will be back soon Mar 5 '16 at 11:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.