在matlab中编程一个光滑的圆锥体

Programming a smooth cone in matlab

我正在尝试在

的 matlab 中编写一个平滑的(?)圆锥体

z = x^2+y^2

x^2+y^2 = C

C = [1 1.4 1.7 2 2.2]

我已经意识到我应该使用极坐标因为它是一个圆形图形

clear all, clc, clf


theta = linspace(0,2*pi,1000)
r = [1 1.4 1.7 2 2.2] % De olika radierna

[r,theta] = meshgrid(r,theta)
z = r
x = r.*cos(theta)
y = r.*sin(theta)
figure
grid on
meshc(x,y,z)
xlabel('x')
ylabel('y')
zlabel('z')

然而,它建模的问题似乎更像是一条平滑的曲线,我得到一条线性曲线,不确定我是否做对了,原来的问题不是

如果有人有 Adams/Essex 第 8 版的《微积分》一书,我正在尝试在 matlab 中建模的是第 674 页的图 12.5。

实际上,您的代码很棒。我只想添加分号,这样它就不会显示所有变量(而且它运行得更快)。问题是您直接以线性方式绘制了 Z 值。您实际上想保留平方项。看看我的代码,我只改了两行

clear all, clc, clf

theta = linspace(0,2*pi,1000);
%i added extra terms .1 through .7
r = sqrt([.1,.2,.7,1,2,3,4,5]);
%r = [1 1.4 1.7 2 2.2] % De olika radierna

[r,theta] = meshgrid(r,theta)
z = r.*r;        %this restores the curve
%z = r
x = r.*cos(theta);
y = r.*sin(theta);
figure
grid on
meshc(x,y,z)
xlabel('x')
ylabel('y')
zlabel('z')

我在 r 中添加了几个点,因此曲线更明显