[英]How to use surf to plot sphere function in matlab
sphere(10)
它是MatLab內置函數。
請負責任地享受。
如果需要查看源代碼,請使用:當sphere函數不在路徑help sphere
時, edit sphere
或help sphere
。
為了完整起見,您的代碼無法正常工作,因為您只對[-10,10]中的一些\\ \\對(x,x)上的函數進行求值,因此不會涵蓋整個域。 它可以這樣工作:
x1 = [-10:1:10];
x2 = [-10:1:10];
y = zeros(1,21);
for i = 1:21
for j=1:21
Y(i,j) = sphere([x1(i) x2(j)]);
end
end
surf(x1,x2,Y);
colormap hsv;
或更快(因為出於計算時間的原因,您應始終避免不必要的循環):
x1 = meshgrid([-10:1:10]);
x2 = x1';
Y = x1.^2+x2.^2;
surf(x1,x2,Y)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.