为什么MatLab会破坏某些变量输入?

Rak*_*sha 0 error-handling matlab plot graph

这是我的代码:

function test(n)
r = (0:1000)/n;
Phi = 2*pi*r;
[x,y] = pol2cart(Phi,r);
plot(x,y)
end
Run Code Online (Sandbox Code Playgroud)

这是n = 100,10,1的输出顺序: 在此输入图像描述

最后一张图表发生了什么?它为什么吓坏了?>.> ......

n = 1后更有趣的形状:这里n = 0.9,0.8,0.7,0.6

在此输入图像描述

Dan*_*iel 5

在数学上,最右边的一个应该连接点(n,0),其中n是0到1000之间的自然数.由于浮点精度,它略微偏离0并且得到非常小的值,接近于0-值.请注意10 ^ -x(不能读取x,因为它是小的),表示y轴的比例.这些数字非常小.

对于任何<4的值,几乎不可能识别原始螺旋,这里是显示四个不同n值的内部20转的图.

在此输入图像描述

对于n的任何小值,您将看到类似于n = 0.01的输出,但是对于任何大的n,它只是一些混叠,这是一条线(由于精度错误,如果你放大得足够看起来很粗糙)或一些螺旋.

用于绘图的代码:

r = 0:.01:20;
Phi = 2*pi*r;
[x,y] = pol2cart(Phi,r);
plot(x,y,'r')
hold on
r = 0:.9:20;
Phi = 2*pi*r;
[x,y] = pol2cart(Phi,r);
plot(x,y,'g')
r = 0:1:20;
Phi = 2*pi*r;
[x,y] = pol2cart(Phi,r);
plot(x,y,'b')
r = 0:1.1:20;
Phi = 2*pi*r;
[x,y] = pol2cart(Phi,r);
plot(x,y,'black')
legend({'0.01','.9','1','1.1'})
Run Code Online (Sandbox Code Playgroud)