第一题:
x=linspace(0,2*pi,101);
y=(0.5+3*sin(x)./(1+x.^2)).*cos(x);
plot(x,y)
%第二题:
%(1)
x=linspace(-2*pi,2*pi,100);
y1=x.^2;
y2=cos(2*x);
y3=y1.*y2;
plot(x,y1,'b-',x,y2,'r:',x,y3,'y--');
text(4,16,'\leftarrow y1=x^2');
text(6*pi/4,-1,'\downarrow y2=cos(2*x)');
text(-1.5*pi,-2.25*pi*pi,'\uparrow y3=y1*y2');
%(2)
x=linspace(-2*pi,2*pi,100);
y1=x.^2;
y2=cos(2*x);
y3=y1.*y2;
subplot(1,3,1);%分区
plot(x,y1);
title('y1=x^2');%设置标题
subplot(1,3,2);
plot(x,y2);
title('y2=cos(2*x)');
subplot(1,3,3);
plot(x,y3);
title('y3=x^2*cos(2*x)');
%(3)
x=linspace(-2*pi,2*pi,20);
y1=x.^2;
subplot(2,2,1);%分区
bar(x,y1);
title('y1=x^2的条形图');%设置标题
subplot(2,2,2);
stairs(x,y1);
title('y1=x^2的阶梯图');
subplot(2,2,3);
stem(x,y1);
title('y1=x^2的杆图');
subplot(2,2,4);
fill(x,y1,'r');%如果少了'r'则会出错
title('y1=x^2的填充图');
%其他的函数照样做。
%第三题
x=-5:0.01:5;
y=[];%起始设y为空向量
for x0=x
if x0<=0 %不能写成x0=<0
y=[y,(x0+sqrt(pi))/exp(2)]; %将x对应的函数值放到y中
else
y=[y,0.5*log(x0+sqrt(1+x0^2))];
end
end
plot(x,y)
%第四题:
a=input('a=');
b=input('b=');
n=input('n=');
t=-2*pi:0.01:2*pi;
r=a*sin(b+n*t);
polar(t,r)
%第五题
x=linspace(-5,5,21);
y=linspace(0,10,31);
[x,y]=meshgrid(x,y);%在[-5,5]*[0,10]的范围内生成网格坐标
z=cos(x).*cos(y).*exp(-sqrt(x.^2+y.^2)/4);
subplot(2,1,1);
surf(x,y,z);
subplot(2,1,2);
contour3(x,y,z,50);%其中50为高度
的等级数,越大越密
%第六题
ezsurf('cos(s)*cos(t)','cos(s)*sin(t)','sin(s)',[0,0.5*pi,0,1.5*pi]); %利用ezsurf隐函数
shading interp %进行插值着色处理