x=linspace(0,pi,100) and x=0:0.01:pi
17 ビュー (過去 30 日間)
古いコメントを表示
what is different with x=linspace(0,pi,100) and x=0:0.01:pi??
0 件のコメント
採用された回答
Image Analyst
2019 年 3 月 26 日
Does this help?
x1 = linspace(0,pi,100) % 100 elements with spacing to be determined (it's pi/100)
x2 = 0:0.01:pi % N elements with spacing of 0.01, but N to be determined (it's 315)
fprintf(' x1 x2\n')
for k = 1 : length(x2)
if k <= length(x1)
fprintf('%10.4f', x1(k));
else
fprintf(' ');
end
fprintf('%10.4f\n', x2(k));
end
You'll see in the command window:
x1 x2
0.0000 0.0000
0.0317 0.0100
0.0635 0.0200
0.0952 0.0300
0.1269 0.0400
0.1587 0.0500
Does that clarify it?
その他の回答 (1 件)
madhan ravi
2019 年 3 月 26 日
linspace creates vector from to 0 to pi with 100 numbers
The other creates a vector with a step .01.
Please read the below documentations:
doc linspace
doc colon
3 件のコメント
Walter Roberson
2019 年 3 月 26 日
Also, there are some differences in how the two handle round-off error.
linspace calculates the average step size, and then each entry is the first entry plus an integer multiple of the step size.
The colon operator controls for round off from the middle, calculating the first half and second half separately to try to reduce drift.
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!