How to get equispaced values with a more exact result than using linspace and column functions?
5 次查看(过去 30 天)
显示 更早的评论
Hi all,
I just realized that the linspace function does not give equispaced values (they are somewhat equispaced, but not exactly), However, I want to use the output values in another function which requires equispaced input. I was wondering is there a function that can produce equispaced output over an interval? I want exactly equispaced output, not something like linspace and coloum which does not produce exactly equispaced output. Is there a way to do that with interp1 function for example?
Thanks in advance!
0 个评论
回答(2 个)
Matt J
2024-1-31
编辑:Matt J
2024-1-31
I want exactly equispaced output
There is no such thing as exactly anything in floating point computation. The inaccuracies you refer to in linspace are presumably due to finite floating point precision. There is no way you will be able to avoid that issue in any alternative method you pursue to subdivide an interval, unless of course it is an integer-valued interval with integer-valued partition widths. But in that case, linspace will be exact, e.g.,
linspace(1,9,5) == [1,3,5,7,9]
0 个评论
Steven Lord
2024-1-31
How are you determining that the vector is not equally spaced? And can you prove that for your values the points that are exactly the same distance apart are even representable as double precision values?
x = linspace(0, 1, 4)
Is one-third exactly representable in double precision? [The answer is no. It is exactly representable neither in a finite number of decimal digits nor a finite number of bits.]
d = diff(x)
d(1) == d(3)
differenceInSpacing = d(1)-d(3)
But is it uniformly spaced to within roundoff? The isuniform function, introduced in release R2022b, can tell us that.
[isUniformlySpaced, distanceBetweenPoints] = isuniform(x)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Vector Fields 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!