Plotting all numbers from a set

Is it possible to plot all of the floating point numbers from a given set [1,2] to see the interval between consecutive numbers? How do I do this?

 Respuesta aceptada

Walter Roberson
Walter Roberson el 25 de Oct. de 2013
If you need to "prove" without reference to the documentation of how floating point values are stored, consider empirical proof:
R = 1 + rand(1,10000000); %say 10 million attempts;
D = min(diff(unique(R))); %sort the tries. Find the adjacent differences. What is the smallest difference?
Any particular answer you get with this would be an upper-bound on the difference between adjacent values in the interval.
Now, how do you know that there are not locations in the interval where the difference might be smaller? You do not, with certainty -- but you can generate more random numbers. You can also use a minor variation of The Birthday Paradox in order to calculate the confidence value that you have found the minimum.
So then, how do you know that there are no locations where the difference between adjacent values is not more than the calculated value? Well, if you take
R = rand(1,1000000);
U = unique((R+D) - R);
then what information would U give you?

Más respuestas (2)

Jan
Jan el 25 de Oct. de 2013

1 voto

The question is not clear. "all floating point numbers from a given set [1,2]" are the two numbers 1.0 and 2.0, and it is easy to "plot" them. But what does "see the interval" mean then?
Do you mean all floating point numbers of a given interval?
Please explain, what you actually want to achieve.

3 comentarios

Beaya
Beaya el 25 de Oct. de 2013
I want to plot floating point numbers in double arithmetics. The interval should be equal to epsilon, which is 2^-52. I need to prove that in this set [1,2] floating point numbers are uniformly distributed and each of them can be presented as 1 + k*epsilon, where epsilon = 2^-52.
Matt Kindig
Matt Kindig el 25 de Oct. de 2013
This question is still not clear. Given that the floating point values are defined as (by definition) on a discrete interval, of course they can be presented as 1 + k*epsilon, as floating point numbers are defined that way. The resulting will indeed be uniformly distributed, but only because you are defining them to be so (by defining them as double floating-point numbers, which have a finite set of 64-bit binary representations). In other words, you are not really proving anything.
Jan
Jan el 25 de Oct. de 2013
What do you mean by "prove"? What kind of "plot" do you want? A diagram with 2^52 values would not reveal anything. Reading the IEEE-754 definitions should clear all corresponding questions.

Iniciar sesión para comentar.

Azzi Abdelmalek
Azzi Abdelmalek el 25 de Oct. de 2013

0 votos

There is an infinity of floating numbers in your interval. You can't plot all the numbers

8 comentarios

Walter Roberson
Walter Roberson el 25 de Oct. de 2013
There is not an infinity of floating point numbers in the interval: there are only 2^53 or so of them. Too large to manage is not the same as infinite ;-)
Instead of checking the whole interval, which needs a huge amount of memory and time, we can check the beginning and the end of the interval.
a=1
n=1e+6 % number of samples
pas=1e-21; % step
t=a:pas:a+n*pas;
y=unique(t);
v=unique((diff(y)))
%Result
2.2204e-16
Check it again with
a=2-n*pas
% the result is the same
Walter Roberson
Walter Roberson el 26 de Oct. de 2013
1 + 1e+6 * 1e-21 does not reach 2, "the end of the interval" ?
Azzi Abdelmalek
Azzi Abdelmalek el 26 de Oct. de 2013
It's not what I meant, I said the first part of the interval [1,2] which is [1,1+1e+6*1e-21] and the last part of the interval [2-1e+6*1e-21,2]
Beaya
Beaya el 28 de Oct. de 2013
Could you please explain why the step is 1e-21?
Sorry if it's obvious but I don't get it. According to calculator 1e-21 = -18.2817181715
Azzi Abdelmalek
Azzi Abdelmalek el 28 de Oct. de 2013
Editada: Azzi Abdelmalek el 28 de Oct. de 2013
From Walter's answer we can see the the smallest step is 2.2204e-16. I could choose pas=1e-22 but the number of samples must be greater, for example n=1e+7. I tried to choose pas as small as possible, at the same time I have to handle the problem of memory
You wrotte 1e-21 = -18.2817181715, It's not possible
Walter Roberson
Walter Roberson el 28 de Oct. de 2013
-18.2817181715 would be exp(1) - 21, and exp(1) is often given the letter "e" as its symbol.
1e-21 on the other hand means 1 * 10^(-21), and is a syntax known to MATLAB. It can also be written 1.0E-21
Beaya
Beaya el 1 de Nov. de 2013
Apologies, I did write exp(1) - 21.

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 25 de Oct. de 2013

Comentada:

el 1 de Nov. de 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by