difference between lines using linespace

22 次查看(过去 30 天)
Hi there, I need to know what is the difference between these: f=linspace(-fs/2,fs/2,samp_Tr); f = -fs/2 + (0:samp_Tr-1)*fs/samp_Tr; actually it gives me in my system different solution
thanks in advance

采纳的回答

Walter Roberson
Walter Roberson 2016-12-26
The two are very similar. The difference is that linspace taked some extra care to reduce the effect of accumulated round-off error. For example, because 1/3 cannot be exactly represented in binary, if you add the closest binary value to 1/3 together three times, you will get a value slightly less than 1. Imagine that you did that 300 times in a row; the result would have to end up 100 times that small difference less than 100. That would happen with the : operator. linspace works with that by dividing the range into two pieces and allowing accumulated error from the beginning to the middle and accumulated error from the end towards the middle, so right in the middle the gap might be a slightly different size.

更多回答(1 个)

KSSV
KSSV 2016-12-26
f1=linspace(-fs/2,fs/2,samp_Tr); % gives samp_tr number of numbers between -fs/2 and fs/2, always this length will be samp_tr
f2 = -fs/2 + (0:samp_Tr-1)*fs/samp_Tr ;
% 0:samp_Tr-1 makes numbers from 0 to samp_Tr with difference one -----1
% (0:samp_Tr-1)*fs/samp_Tr this multiplies all the aobe generated (1)
% numbers with fs/samp_Tr ----2
% -fs/2 + (0:samp_Tr-1)*fs/samp_Tr this adds the above generated numbers
% (2) to -fs/2
This is a simple one, you can check on your own giving numbers for fs and samp_Tr
  1 个评论
ahmed youssef
ahmed youssef 2016-12-26
but it gives me the same line when plot individually. moreover, -fs/2 + (0:samp_Tr-1)*fs/samp_Tr means numbers with begin from -fs/2 ending fs/2. I beleive it is the same when I put linspace(-fs/2,fs/2,samp_Tr). any discussion

请先登录,再进行评论。

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by