x=linspace(0,pi,100) and x=0:0.01:pi
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Allan Lee
el 26 de Mzo. de 2019
Comentada: madhan ravi
el 26 de Mzo. de 2019
what is different with x=linspace(0,pi,100) and x=0:0.01:pi??
0 comentarios
Respuesta aceptada
Image Analyst
el 26 de Mzo. de 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?
Más respuestas (1)
madhan ravi
el 26 de Mzo. de 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 comentarios
Walter Roberson
el 26 de Mzo. de 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.
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!