Linspace and Colon Operator Inconsistency

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

采纳的回答

David Young
David Young 2015-2-17
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by