0
$\begingroup$

I want to make a table for my calculus 1 class learning limits. I am calculating $\lim_{x\to 0} \frac{sin(x)}{x}$. I am using the approximation given by N. The problem is with the expression up to 15 (or however many) digits. For example, calculating this with $x=.5$, I type

N[Sin[.5]/(.5),15]

The output is

.958851077208

which only has 12 decimal places. I assume this is because the last 3 (and the forever) are just zero. (Either that or Mathematica cannot calculate it to more than 12 digits, which I doubt). How can I get it to show it with all 15 digits and not just the 12 non-zero ones?

$\endgroup$
  • 1
    $\begingroup$ Look at SetAccuracy and SetPrecision. $\endgroup$ – corey979 Jan 9 '17 at 21:56
  • 3
    $\begingroup$ Replace .5 with 1/2. $\endgroup$ – Chip Hurst Jan 9 '17 at 22:04
  • $\begingroup$ Thanks @ChipHurst! Why did this work? $\endgroup$ – user46348 Jan 9 '17 at 23:12
  • 1
    $\begingroup$ The expression Sin[.5]/.5 is evaluated first, hence you've computed a machine number first, which has a limited number of digits. If you use 1/2 instead, you'll have an exact value to take an arbitrary amount of digits from. $\endgroup$ – Chip Hurst Jan 9 '17 at 23:17
  • 1
    $\begingroup$ This is also mentioned in the third example in the docs for N $\endgroup$ – Michael E2 Jan 9 '17 at 23:45
2
$\begingroup$

Try this:

In[2580]:= ndigits = 20;
SetPrecision[Sin[0.5]/0.5, ndigits]

Out[2581]= 0.95885107720840601075
$\endgroup$
  • 3
    $\begingroup$ It's worth pointing that out this gives 20 digits of a roughly 16-digit-accurate result. One might want a result that is accurate to 20 digits, in which case something else should be done. $\endgroup$ – Michael E2 Jan 9 '17 at 23:42

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