xlabel('independent variable X'); %加X轴说明 ylabel('independent variable Y'); %加Y轴说明 text(0,0,'sin(x)'); %在指定位置添加图形说明
text(0,1,'cos(x)'); legend('sin(x)','cos(x)') %加图例
5)在(3.3,1.1)处标上文字?sin(x)?,用鼠标在cos(x)曲线的某点处标上文字?cos(x)?;
解:x=linspace(0,2*pi,200);
plot(x,sin(x),'r:',x,cos(x),'g*');
title('sin(x)和cos(x)曲线'); %加图形标题
xlabel('independent variable X'); %加X轴说明 ylabel('independent variable Y'); %Y轴说明 legend('sin(x)','cos(x)')
text(3.3,1.1,'sin(x)'); %在指定位置添加图形说明
text(0,1,'cos(x)');
6)给图形加上网格线。
解:x=linspace(0,2*pi,200);
plot(x,sin(x),'r:',x,cos(x),'g*');
title('sin(x)和cos(x)曲线'); %加图形标题
xlabel('independent variable X'); %加X轴说明 ylabel('independent variable Y'); %加Y轴说明 legend('sin(x)','cos(x)')
text(3.3,1.1,'sin(x)'); 位置添加图形说明
text(0,1,'cos(x)'); grid on
7)回车后图形的坐标轴和网格线消失。y=sin(x); 解:
x=linspace(0,2*pi,200);
plot(x,sin(x),'r:',x,cos(x),'g*');
title('sin(x)和cos(x)曲线'); 形标题
xlabel('independent variable X'); ylabel('independent variable Y'); legend('sin(x)','cos(x)')
text(3.3,1.1,'sin(x)'); 位置添加图形说明
text(0,1,'cos(x)');
%在指定 %加图 %加X轴说明 加Y轴说明 %在指定 % grid on axis off grid off
7、 使用正态分布的随机函数产生10000个随机数;统计-3到3之间每隔0.2间隔内落入的随机数个数,并打印出其频数图。 解 :x=randn(1000,1); y=-3; i=1; while y<=3
c(i)=sum(x>=y&x<=(y+0.2)); y=y+0.2; i=i+1; end c
d=-3:0.2:2.8; plot(d,c);
8、 试打印出下列函数所表示的图像 1)e?xy?2x?xy?y?2?0;
2解:x=0:1000; y=0:1000;
[x,y]=meshgrid(x,y);
z=exp(-x.*y)-2*x.^2+x.*y-y+2; k=find(z==0); %找出解的位置 x(k),y(k) plot(x(k),y(k))
2)??tcos(2?t)1?t2?1
解:t=0:0.2:2*pi;
p=(t.*cos(2*pi*t))./(1+t.^2)+1; plot(t,p)
3)z?Re(sin(x?iy));
解:x=0:0.1:2*pi; [x,y]=meshgrid(x); t=(sin(x+i*y))'; z=(sin(x+i*y)+t)/2; plot3(x,y,z);
xlabel('x-轴'),ylabel('y-轴'),zlabel('z-轴');
?x?1?(3?cos(u))sin(v)?4)?y?1?(3?cos(u))cos(v)
?z?sin(u)?解:u=0:0.1:2*pi;