实验7:图形绘制一、实验目的1、掌握绘制二维图形的常用函数。2、掌握绘制三维图形的常用函数。3、掌握绘制图形的辅助操作。二、实验内容1、已知2*13),2cos(2,12yyyxyxy,完成下列操作:(1)在同一坐标系下用不同的颜色和线型绘制三条曲线。%homework_7_1_1.mx=0:pi/100:2*pi;y1=x.*x;y2=cos(2*x);y3=y1.*y2;plot(x,y1,'r--',x,y2,'k:',x,y3,'b-.');(2)以子图形式绘制三条曲线。%homework_7_1_2.mx=0:pi/100:2*pi;y1=x.*x;y2=cos(2*x);y3=y1.*y2;subplot(2,2,1);plot(x,y1,'r--');subplot(2,2,2);plot(x,y2,'k:');subplot(2,2,3);plot(x,y3,'b-.');(3)分别用条形图、阶梯图、杆图和填充图绘制三条曲线。%homework_7_1_3.m%ÌõÐÎͼ¡¢½×ÌÝͼ¡¢¸ËͼºÍÌî³äͼx=0:pi/100:2*pi;y1=x.*x;y2=cos(2*x);y3=y1.*y2;%µÚÒ»ÐÐsubplot(4,3,1);bar(x,y1,'r');subplot(4,3,2);bar(x,y2,'k');subplot(4,3,3);bar(x,y3,'b');%µÚ¶þÐÐsubplot(4,3,4);stairs(x,y1,'r');subplot(4,3,5);stairs(x,y2,'k');subplot(4,3,6);stairs(x,y3,'b');%µÚÈýÐÐsubplot(4,3,7);stem(x,y1,'r');subplot(4,3,8);stem(x,y2,'k');subplot(4,3,9);stem(x,y3,'b');%µÚËÄÐÐsubplot(4,3,10);fill(x,y1,'r');subplot(4,3,11);fill(x,y2,'k');subplot(4,3,12);fill(x,y3,'b');2、绘制极坐标曲线)sin(nba,并分析参数a,b,n对曲线形状的影响。%homework_7_2.mfunctionhomework_7_2(a,b,n)theta=0:0.01:2*pi;rho=a.*sin(b+n.*theta);polar(theta,rho,'k');%homework_7_2_tiao.m%aµÄÓ°Ïìsubplot(3,4,1);homework_7_2(1,1,1)subplot(3,4,2);homework_7_2(2,1,1)subplot(3,4,3);homework_7_2(3,1,1)subplot(3,4,4);homework_7_2(4,1,1)%bµÄÓ°Ïìsubplot(3,4,1);homework_7_2(1,1,1)subplot(3,4,2);homework_7_2(1,2,1)subplot(3,4,3);homework_7_2(1,3,1)subplot(3,4,4);homework_7_2(1,4,1)%nµÄÓ°Ïìsubplot(3,4,1);homework_7_2(1,1,1)subplot(3,4,2);homework_7_2(1,1,2)subplot(3,4,3);homework_7_2(1,1,3)subplot(3,4,4);homework_7_2(1,1,4)3、分别用plot和fplot函数绘制函数xy1sin的曲线,分析两曲线的差别。%homework_7_3.mx=0:pi/100:2*pi;y=sin(1./x);plot(x,y);%homework_7_3_2_fplot.mfunctiony=homework_7_3_fplot(x)y=sin(1./x);%homework_7_3_2.mfplot('homework_7_3_fplot',[0,7],1e-3);4、绘制函数曲面图和等高线图:(1)xyyxexxz22)2(2%homework_7_4_1_6.mx=-pi:0.1:pi;[x,y]=meshgrid(x);z=(x.*x-2.*x).*exp(-x.*x-y.*y-x.*y);surfc(x,y,z);xlabel('x-Öá'),ylabel('y-Öá'),zlabel('z-Öá');title('ÈýάmeshÍø¸ñͼ');(2)),(yxf2222)1(11)1(11yxyx%homework_7_4_2_1.mx=-pi:0.1:pi;[x,y]=meshgrid(x);z=1./(1+sqrt((x-1).^2+y.^2))-1./(1+sqrt((x+1).^2+y.^2));surfc(x,y,z);xlabel('x-Öá'),ylabel('y-Öá'),zlabel('z-Öá');title('ÈýάmeshÍø¸ñͼ');提示:绘制三维曲面图,首先要选定一个平面区域并在该区域产生网格坐标矩阵。在做本题之前,先分析并上机验证下列的命令执行结果。从中体会产生网格坐标矩阵的方法。5、绘制由下列参数方程表示的曲面图形(未绘制图形之前,你能看出其是什么图形吗?)uzvuyvuxsinsin)cos1(cos)cos1(,其中)2,0(),2,0(vu。%homework_7_5_1.mx=inline('(1+cos(u)).*cos(v)');y=inline('(1+cos(u)).*sin(v)');z=inline('sin(u)');ezmesh(x,y,z);title('轮胎面');text(0,0,0,'origin');xlabel('X'),ylabel('Y'),zlabel('Z');grid;6、在一幅图上打印出函数sin(x)和cos(x)在[0,2]区间上的图形,要求如下1)sin(x)和cos(x)图形分别用红色的点划线和绿色星号打印;2)坐标轴的窗口大小范围设为[-1,7][-1.5.1.5];3)分别给x轴和y轴加上标注说明,图形加上名称;4)给出图例说明标注;5)在(3.3,1.1)处标上文字‘sin(x)’,用鼠标在cos(x)曲线的某点处标上文字‘cos(x)’;6)给图形加上网格线。7)回车后图形的坐标轴和网格线消失。y=sin(x);//此项没完成%homework_7_6_1.mx=0:pi/100:2*pi;y1=sin(x);y2=cos(x);plot(x,y1,'r-.',x,y2,'g*');title('sin(x)ºÍcos(x)ÔÚ[0£¬2*pi]Çø¼äÉϵÄͼÐÎ');%¼ÓͼÐαêÌâxlabel('XÖá');%¼ÓXÖá˵Ã÷ylabel('YÖá');%¼ÓYÖá˵Ã÷text(3.3,1.1,'sin(x)');gtext('cos(x)')legend('sin(x)','cos(x)')%¼ÓͼÀýaxis([-1,7,-1.5,1.5]);gridon%¼ÓÉÏÍø¸ñÏß7、使用正态分布的随机函数产生10000个随机数;统计-3到3之间每隔0.2间隔内落入的随机数个数,并打印出其频数图。%homework_7_7.mx=-3:0.2:3;y=randn(1,10000);hist(y,x);8、试打印出下列函数所表示的图像1)0222yxyxexy%homework_8_1.mf=inline('exp(-x*y)-2*x*x+x*y-y+2');ezplot(f,[-5,5]);gridon;2)11)2cos(2ttt%homework_8_2.mf=inline('(t*cos(2*pi*t))/(1+t*t)+1');ezplot(f);gridon;3)))Re(sin(iyxz%homework_8_3.mz=inline('real(sin(x+i*y))');%real取实部imag取虚部ezplot(z);gridon;4))sin()cos())cos(3(1)sin())cos(3(1uzvuyvux%homework_7_8_4.mx=inline('1+(3-cos(u))*sin(v)');y=inline('1+(3-cos(u))*cos(v)');z=inline('sin(u)');ezmesh(x,y,z);gridon;9、设函数22yxxez试打印出下列图形:1)打印函数的网格图和曲面图网格图%homework_7_9_1_1.mz=inline('x*exp(-x*x-y*y)');ezmesh(z);title('网格图');text(0,0,0,'origin');xlabel('X'),ylabel('Y'),zlabel('Z');grid;曲面图%homework_7_9_1_2.mz=inline('x*exp(-x*x-y*y)');ezsurf(z);title('网格图');text(0,0,0,'origin');xlabel('X'),ylabel('Y'),zlabel('Z');grid;2)打印出函数的高度为v=[-0.4,-0.2,-.10,0.3,0.35]二维等值线图,并在图形上标出其高度。(提示:使用clable命令标高度)%homework_7_9_2.mv=[-0.4,-0.2,-.10,0.3,0.35];x=-2:0.1:2;y=-2:0.1:2;[x,y]=meshgrid(x,y);z=x.*exp(-x.*x-y.*y);[c,v]=contour(z,v);clabel(c,v);title('二维等值线图');xlabel('X'),ylabel('Y');%axis([40,80,40,80]);grid;3)打印出函数有20条等值线的三维等值线图%homework_7_9_3.mx=-2:0.1:2;y=-2:0.1:2;[x,y]=meshgrid(x,y);z=x.*exp(-x.*x-y.*y);contour3(z,20);title('三维等值线图');xlabel('X'),ylabel('Y'),zlabel('Z');grid;4)打印函数的伪彩色图。(提示使用Contourf(z))%homework_7_9_4.mx=-2:0.1:2;y=-2:0.1:2;[x,y]=meshgrid(x,y);z=x.*exp(-x.*x-y.*y);contourf(z)title('伪彩色图');xlabel('X'),ylabel('Y');grid;10、Chebyshev多项式的定义如下:y=cos(m*cos-1x)其中x的值介于[-1,1]。当m的值由1变化到5,我们可得到五条曲线。请将这五条曲线画在同一张图上面,记得要使用legend指令来标明每一条曲线。%homework_7_10.mx=-pi:pi/100:pi;y1=cos(1.*(1./cos(x)));y2=cos(2.*(1./cos(x)));y3=cos(3.*(1./cos(x)));y4=cos(4.*(1./cos(x)));y5=cos(5.*(1./cos(x)));plot(x,y1,x,y2,x,y3,x,y4,x,y5);legend('m=1','m=2','m=3','m=4','m=5');%Chebyshev(y);title('Chebyshev');xlabel('X'),ylabel('Y');grid;%homework_7_10_1.mx=linspace(-1,1)';y=[];form=1:5y