Numeric precision using colon

3 次查看(过去 30 天)
Adam
Adam 2015-4-6
回答: Jan 2015-4-6
See image below. I have noticed some very interesting issues when generating a vector using the colon operator. It seems that some sort of error is introduced which isn't THAT big of a deal unless you start using that data for logic operations. Does anyone know what's going on here? The same thing occurs of you repeat the process with division instead of multiplication.

回答(2 个)

Sebastian Castro
Sebastian Castro 2015-4-6
This is often associated with floating-point rounding error. The value "0.02" is not exactly represented using the "double" data type (this is the default in MATLAB).
Check out the section "Avoiding Common Problems with Floating-Point Arithmetic" in this link .
If you redefine your time vector as follows, does this resolve what you see?
time = 2*(0:10000)/100;
- Sebastian

Jan
Jan 2015-4-6

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by