Linspace and Colon Operator Inconsistency

1 view (last 30 days)
Hi, I am running the next two commands:
V1 = 0:1/8000:0.2 ;
V2 = linspace(0,0.2,1601) ;
I expected both commands to generate the exact same vector, however, they are not the same. In linspace documentation it is said that: "It is similar to the colon operator ":"..." which is obviously not so true.
I guess the difference stems from the floating point representation (I took a look at the linspace implementation which uses the colon operator too but differently), yet the inconsistency bothers me.
My questions are why is it so? shold not the two lines coincide? is there anyway to predict the inconsistency in advance?
Thanks!

Accepted Answer

David Young
David Young on 17 Feb 2015
Note that the maximum absolute difference between V1 and V2 is of the order of 10^(-17).
The difference is likely due to the colon operator's behaviour, discussed in this answer.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!