- 第一个子图:给出7个a的值,编程画出一组椭圆,分别使用不同的颜色,添加标题“椭圆”。
- 第二个子图:同时用plot函数绘制以红线、(2,3)为圆心、半径为2的圆,用函数ezplot绘制以(1,2)为圆心,半径为1.5的圆。标题为“圆”,图例为“plot”、“ezplot”,各自的圆心用句号“。”在对应位置标出。
- 第三个子图:以0.05p为步长绘制正弦曲线sin(2pt)和余弦曲线cos(pt)在[0,2p]之间的二维离散图,正弦曲线以绿色虚线,余弦曲线以红色实线绘制,图例为对应的函数表达式sin(2pt)、 cos(pt),添加横轴坐标标题“t”。
- 第四个子图:绘制z = x.^2 + 8*x*y^2 + y.^2 + 6*x*y + 2*y +60,x和y在-15到15之间内对应的三维曲面图。
t=0:pi/200:2*pi; %以下代码用于绘制椭椭圆 for i=1:1:7 color=['r','y','b','g','c','k','m',]; b=5; subplot(2,2,1); plot(i*sin(t),sqrt(55-i^2)*cos(t),color(i),'LineWidth',1.07); hold on; end title('椭圆'); %以下代码用于绘制圆形 r=2; %设置半径的值 subplot(2,2,2); plot(r*cos(t)+2,r*sin(t)+3,'r'); hold on; ezplot('(m-1)^2+(n-2)^2=2.25'); hold on; text(2,3,'。');text(1,2,'。'); legend('plot','ezplot'); title('圆'); axis equal; %以下代码用于绘制离散正余弦曲线 alpha=0:0.05*pi:2*pi; subplot(2,2,3); plot(alpha,sin(2*pi*alpha),'-ro','Linewidth',1.02); hold on; plot(alpha,cos(pi*alpha),'--go','Linewidth',1.1); hold on; legend('sin(2\pit)','sin(\pit)'); xlabel('t') %以下代码用于绘制三维曲面图 x=-15:0.05:15;y=-15:0.05:15; [x,y]=meshgrid(x,y); z = x.^2+ 8*x*y.^2 + y.^2+ 6*x*y + 2*y +60; subplot(2,2,4); mesh(x,y,z); hold on; axis square;
效果如下: