Linspace and Colon Operator Inconsistency

조회 수: 4 (최근 30일)
Assaf
Assaf 2015년 2월 17일
답변: David Young 2015년 2월 17일
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에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by