利用matlab繪製圖形
阿新 • • 發佈:2018-12-16
一、實驗任務和目的
- 掌握Matlab的控制代碼圖形的繼承。
- 掌握Matlab的二、三維畫圖函式的用法。
- 瞭解Matlab的特殊二維繪圖函式和隱函式繪圖的方法。
二、實驗內容
1. 畫出如下圖形
這個怎麼說呢,明明就是個**,第二個圖形是cosx? 而且matlab有現成的gui可以對圖形編輯,為什麼非要用程式碼做出來? 我就是先畫個大致輪廓,然後用matlab裡邊圖形編輯做的
x=-2*pi:pi/100:2*pi; y=sin(x); subplot(2,2,2); plot(x,y,'--k'); title('plot of cos x'); xlabel('x'); ylabel('sinx'); text(-6,-0.8,'Text string 2'); subplot(2,2,3); plot(x,y); title('plot of sin x'); text(-2*pi,0,'min(x)->');
程式碼結果
然後我直接用圖形編輯器,上色加粗移動說明文字加箭頭都是分分鐘的事啊,而且matlab裡面有個固定的就是x軸範圍顯示預設為int,所以要是指定2*pi的範圍,x軸還會顯示10,那又要求不能顯示十,那隻好通過編輯器對x軸範圍更改,我改成7.9就ok了,要是直接用程式碼,我是實現不出來
2.畫出以下圖形
subplot(3, 3, 1); f = @(x)200*sin(x)./x; fplot(f, [-20 20]); title('y = 200*sin(x)/x'); subplot(3, 3, 2); ezplot('x^2 + y^2 = 1', [-1.1 1.1]); axis equal; title('單位圓'); subplot(3, 3, 3); ezpolar('1+cos(t)'); title('心形圖'); subplot(3, 3, 4); x = [10 10 20 25 35]; name = {'趙', '錢', '孫', '李', '謝'}; explode = [0 0 0 0 1]; pie(x, explode, name) title('餅圖'); subplot(3, 3, 5); stairs(-2*pi:0.5:2*pi,sin(-2*pi:0.5:2*pi)); title('樓梯圖'); subplot(3, 3, 6); stem(-2*pi:0.5:2*pi,sin(-2*pi:0.5:2*pi)); title('火柴桿圖'); subplot(3, 3, 7); Z = eig(randn(20,20)); compass(Z); title('羅盤圖'); subplot(3, 3, 8); theta = (-90:10:90)*pi/180; r = 2*ones(size(theta)); [u,v] = pol2cart(theta,r); feather(u,v); title('羽毛圖'); subplot(3, 3, 9); t = (1/16:1/8:1)'*2*pi; fill(sin(t), cos(t),'r'); axis square; title('八邊形');
3.
x=-3*pi:0.01:3*pi;
for i=1:length(x)
if(x(i)==0) y(i)=1;
else y(i)=sin(x(i))/x(i);
end
end
plot(x,y);
set(gca,'YGrid','on');
4.畫圖形
圖1:
t = 0 : 0.01 : 2*pi;
polar(t, sin(2*t).*cos(2*t))
圖2:
ezsurf('u*sin(v)','u*cos(v)', '4*v',[-2*pi,2*pi,-2*pi,2*pi])
圖3:
t=0:pi/20:2*pi; [x,y,z]= cylinder(2+sin(t),100); surf(x,y,z); xlabel('X'); ylabel('Y'); zlabel('Z'); set(gca,'color','none'); shading interp; colormap(copper); light('Posi',[-4 -1 0]); lighting phong; material metal; hold on; %plot3(-4,-1,0,'p','markersize', 18); % text(-4,-1,0,'光源','fontsize',14,'fontweight','bold');
圖4:
不知道函式不會畫鴨