x=linspace(0,pi,100) and x=0:0.01:pi
91 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Allan Lee
il 26 Mar 2019
Commentato: madhan ravi
il 26 Mar 2019
what is different with x=linspace(0,pi,100) and x=0:0.01:pi??
0 Commenti
Risposta accettata
Image Analyst
il 26 Mar 2019
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?
Più risposte (1)
madhan ravi
il 26 Mar 2019
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 Commenti
Walter Roberson
il 26 Mar 2019
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.
Vedere anche
Categorie
Scopri di più su Annotations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!