difference between lines using linespace
조회 수: 21 (최근 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
댓글 수: 0
채택된 답변
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
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Visual Exploration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!