Plotting all numbers from a set

3 次查看(过去 30 天)
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?

采纳的回答

Walter Roberson
Walter Roberson 2013-10-25
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?

更多回答(2 个)

Jan
Jan 2013-10-25
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 个评论
Matt Kindig
Matt Kindig 2013-10-25
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 2013-10-25
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.

请先登录,再进行评论。


Azzi Abdelmalek
Azzi Abdelmalek 2013-10-25
There is an infinity of floating numbers in your interval. You can't plot all the numbers
  8 个评论
Walter Roberson
Walter Roberson 2013-10-28
-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 2013-11-1
Apologies, I did write exp(1) - 21.

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by