3
$\begingroup$

If Im not wrong when we use the command N we are using float point numbers in machine precision, right? And the machine precision depends on the bits of the CPU where Mathematica is installed. Then, by example, irrational numbers are truncated at some place and there is some error associated to the magnitude of the truncated number.

Then I'm using the following list of values

Accumulate@Tan[N@Range[10^8]]

where I cant quit the N to speed up other calculations over this list. But I need to know what is the accumulated error of the last element in this list. And, if it would be possible, I would like to graph this list inside the increasing area of accumulated error relative to each value of the list.

But searching (almost randomly) in the documentation of Wolfram Mathematica I dont found something that make me think how I can do this. Can someone help me? Thank you in advance.

$\endgroup$

2 Answers 2

5
$\begingroup$

compare against a higher precision calculation

n = 100000;
ListPlot[Log[10, 
  Abs[Accumulate@Tan[N[Range[n]]] - 
    Accumulate@Tan[N[Range[n], 1000]]]]]

enter image description here

$\endgroup$
1
  • $\begingroup$ thank you very much, indeed this is more "powerful" than what I was searching for... This is insanely useful: I can make some statistic of the error. $\endgroup$
    – Masacroso
    Nov 13, 2017 at 18:56
2
$\begingroup$

This should give you what you need:

Accumulate@Tan[Range[10^8]]-SetPrecision[Accumulate@Tan[N@Range[10^8]],30]
$\endgroup$
2
  • $\begingroup$ but SetPrecision is not just adding extra zeros to the already truncated numbers? $\endgroup$
    – Masacroso
    Nov 13, 2017 at 18:52
  • 3
    $\begingroup$ It is doing just that. But by setting it higher than $MachinePrecision ensures that no further arithmetical error is made in the comparison. In this case this is not that relevant since the accumulated error is much bigger than the MachinePrecision threshold. $\endgroup$
    – TimRias
    Nov 13, 2017 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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