资源描述
光电073-1 刘颖 200713503117
实验六 高层绘图操作
运行结果:
1.设y=,在x=2π区间取101点,绘制函数的曲线.
程序设计:
x=0:pi/50:2*pi;
y=(0.5+3*sin(x)./(1+x.^2)).*cos(x);
plot(x,y)
2.已知,完成下列操作:
(1)在同一坐标系下用不同的颜色和线性绘制三条曲线。
运行结果:
程序设计:
close all
x=(0:pi/100:2*pi)';
y1=x.^2;
y2=cos(2*x);
y3=y1.*y2;
plot(x,y1,'m.');
hold on;
plot(x,y2,'g-.');
hold on;
plot(x,y3,'y--');
hold off
(2)以子图形式绘制三条曲线。
运行结果:
程序设计:
close all
x=(0:pi/100:2*pi)';
y1=x.^2;
y2=cos(2*x);
y3=y1.*y2;
subplot(3,1,1);
plot(x,y1);
title('y1');
subplot(3,1,2);
plot(x,y2);
title('y2');
subplot(3,1,3);
plot(x,y3);
title('y3');
(3)分别用条形图、阶梯图、杆图和填充图绘制三条曲线。
程序设计:
close all
x=(0:pi/100:2*pi)';
y1=x.^2;
y2=cos(2*x);
y3=y1.*y2;
subplot(3,4,1);bar(x,y1,'y');title('bar(x,y1,"y")');
subplot(3,4,2);stairs(x,y1,'m');title('stairs(x,y1,"m")');
subplot(3,4,3);stem(x,y1,'g');title('stem(x,y1,"g")');
subplot(3,4,4);fill(x,y1,'c');title('fill(x,y1,"c")');
subplot(3,4,5);bar(x,y2,'y');title('bar(x,y2,"y")');
subplot(3,4,6);stairs(x,y2,'m');title('stairs(x,y2,"m")');
subplot(3,4,7);stem(x,y2,'g');title('stem(x,y2,"g")');
subplot(3,4,8);fill(x,y2,'c');title('fill(x,y2,"c")');
subplot(3,4,9);bar(x,y3,'y');title('bar(x,y3,"y")');
subplot(3,4,10);stairs(x,y3,'m');title('stairs(x,y3,"m")');
subplot(3,4,11);stem(x,y3,'g');title('stem(x,y3,"g")');
subplot(3,4,12);fill(x,y3,'c');title('fill(x,y3,"c")');
运行结果:
3.已知
在-5区间绘制函数曲线。
程序设计:
close all
x=-5:0.1:5;
运行结果:
if x<=0
y=(x+sqrt(pi))./(exp(2));
else
y=1/2*(log(x+sqrt(1+x.^2)));
end
y
plot(x,y)
4.绘极坐标曲线ρ=asin(b+nθ),并分析参数a、b、n对曲线形状的影响。
运行结果:
程序设计:
close all
a=input('请输入a=');
b=input('请输入b=');
n=input('请输入n=');
theta=0:0.01:2*pi;
rho=a*sin(b+n*theta);
polar(theta,rho,'k')
运行结果:
请输入a=1
请输入b=2
请输入n=3
5.绘制函数的曲面图和等高线
其中x的21个值均匀分布在[-5,5]范围,y的31个值均匀分布在[0,10],要求使用subplot(2,1,1)和subplot(2,1,2)将产生的曲面图和等高线图画在同一个窗口上。
程序设计:
close all
x=-5:0.5:5;
y=0:1/3:10;
[x,y]=meshgrid(x,y);
z=cos(x).*cos(y).*exp(-(sqrt(x.^2+y.^2)/4));
subplot(2,2,1);
surf(x,y,z);
subplot(2,2,2);
contour3(x,y,z);
运行结果:
6.绘制曲面图形,并进行插值着色处理。
程序设计:
s=0:0.05:pi/2;
t=0:0.05:3*pi/2;
[s,t]=meshgrid(s,t);
[x,y,z]=peaks(30);
x=cos(s).*cos(t);
y=cos(s).*sin(t);
z=sin(s);
surf(x,y,z);shading flat;
运行结果:
4
展开阅读全文