Unexplained warning creating vectors
Below is a printout of from my terminal when I create two vectors开发者_如何学C of ones. Does anyone know the reason why the second call to ones() issues a warning, while the first does not?
>> p1
p1 =
0.7000
>> p2
p2 =
0.3000
>> whos p1
Name Size Bytes Class Attributes
p1 1x1 8 double
>> whos p2
Name Size Bytes Class Attributes
p2 1x1 8 double
>> N
N =
100
>> T1 = ones(N*p1,1);
>> T2 = ones(N*p2,1);
Warning: Size vector should be a row vector with integer elements.
Yes, you might think that 100*.3 would be an integer, but it is not. This is because 0.3 is not stored as exactly 0.3 in the IEEE numeric representation used. Most such decimal numbers are not represented exactly. Remember that numbers are stored in a binary form. The true decimal representation of what is stored when you enter 0.3 into matlab is:
0.299999999999999988897769753748434595763683319091796875
It is close to 0.3, but not exactly so.
http://www.mit.edu/~pwb/cssm/matlab-faq_toc.html
http://download.oracle.com/docs/cd/E19957-01/806-3568/ncg_goldberg.html
Sometimes a result will turn out to be an exact integer.
精彩评论