用matlab绘制的漂亮图形.docx
- 文档编号:27311699
- 上传时间:2023-06-29
- 格式:DOCX
- 页数:35
- 大小:1.64MB
用matlab绘制的漂亮图形.docx
《用matlab绘制的漂亮图形.docx》由会员分享,可在线阅读,更多相关《用matlab绘制的漂亮图形.docx(35页珍藏版)》请在冰豆网上搜索。
用matlab绘制的漂亮图形
用matlab绘制的漂亮图形
1.不同坐标系下的图形对比
theta=0:
pi/20:
4*pi;
phi=theta.^2-theta;
[t,p]=meshgrid(theta,phi);
r=t.*p;
subplot(1,2,1);mesh(t,p,r);
ylabel('x');xlabel('y');zlabel('z');
[x,y,z]=sph2cart(t,p,r);
subplot(1,2,2);mesh(x,y,z);
ylabel('x');xlabel('y');zlabel('z');
2.球曲面的法线
[x,y,z]=sphere;
Surfnorm(x,y,z)
3.
x=rand(100,1)*16-8;
y=rand(100,1)*16-8;
r=sqrt(x.^2+y.^2)+eps;
z=sin(r)./r;
xlin=linspace(min(x),max(x),33);
ylin=linspace(min(y),max(y),33);
[X,Y]=meshgrid(xlin,ylin);
Z=griddata(x,y,z,X,Y);
mesh(X,Y,Z);
axistight;holdon;
ylabel('x');xlabel('y');zlabel('z');
plot3(x,y,z,’r’,’MarkerSize’,15)
x=rand(1000,1)*16-8;
y=rand(1000,1)*16-8;
r=sqrt(x.^2+y.^2)+eps;
z=sin(r)./r;
xlin=linspace(min(x),max(x),99);
ylin=linspace(min(y),max(y),99);
[X,Y]=meshgrid(xlin,ylin);
Z=griddata(x,y,z,X,Y);
mesh(X,Y,Z);
axistight;holdon;
ylabel('x');xlabel('y');zlabel('z');
plot3(x,y,z,'r','MarkerSize',30);
去掉网格后:
4.圆通
fnplt(fncmb(rsmak(‘cylinder’,1,2),[00-1;010;100]));
axisequal,axisoff;
shadinginterp
5.
c=8.01*10^(-6);
T=9.8*0.940*10^(-7);
form=1:
100
a=m/10000000;
forn=1:
100
b=n/10000000;
omiga(m,n)=sqrt((10.6667*a^3*b^5+10.6667*a^5*b^3)/(2.3112*a^5*b^5*c)*T)/(2*pi);
end
end
mesh((1:
100)/10000000,(1:
100)/10000000,omiga);
ylabel('半短轴b');xlabel('半长轴a');zlabel('频率f');
6.马鞍面
x=-8:
8;y=-8:
8;
[X,Y]=meshgrid(x,y);
Z=(X.^2./4.^2-Y.^2./5.^2);
meshz(X,Y,Z);
ylabel('x');xlabel('y');zlabel('z');
x=-8:
8;y=-8:
8;
[X,Y]=meshgrid(x,y);
Z=X.^2./4.^2-Y.^2./5.^2;
surfc(X,Y,Z);
ylabel('x');xlabel('y');zlabel('z');
7.螺旋线
t=0:
pi/60:
10*pi;
x=sin(t);y=cos(t);
plot3(x,y,t,'*-b');
ylabel('x');xlabel('y');zlabel('z');
t=0:
pi/60:
10*pi;
x=sin(t);y=cos(t);
fill3(x,y,t,'*-b');
ylabel('x');xlabel('y');zlabel('z');
8.
[x,y]=meshgrid([-2:
0.2:
2]);
f=x.^2+y.^2;
[fx,fy]=gradient(f,0.2,0.2);
quiver(x,y,fx,fy);
holdon
contour(x,y,f);
9.
[x,y]=meshgrid([-4:
0.1:
4]);
z=x.*exp(-x.^2-y.^2);
plot3(x,y,z);
10.[x,y]=meshgrid([-2:
0.05:
2]);
z=x.*exp(-x.^2-y.^2);
surf(x,y,z);
11.牛顿环(动态的)
clear
R=1;N=400;lamda=200e-9;rr=0.0017;
[x,y]=meshgrid(linspace(-rr,rr,N));
r=sqrt(x.^2+y.^2);
phi=r.^2/R./lamda.*pi.*2+pi;
I=4.*cos(phi./2).^2;
H=imshow(I);
t=0;k=1;
whilek;
s=get(gcf,'currentkey');
ifstrcmp(s,'space');
clc;k=0;
end
t=t+0.01;
pause(0.2);
phi=phi+t;
I=4.*cos(phi./2).^2;
set(H,'CData',I);
end
12.衍射调制下的双孔干涉条纹
clearall
lambda=500e-9;D=1;d=1e-6;a=3.5*d;
ymax=10*lambda*D/a;xmax=ymax;
N=101;
xs=linspace(-xmax,xmax,N);
ys=linspace(-ymax,ymax,N);
fori=1:
N;
forj=1:
N;
r1(i,j)=sqrt(D.^2+(ys(i)-a./2).^2+xs(i).^2);
r2(i,j)=sqrt(D.^2+(ys(j)-a./2).^2+xs(j).^2);
Dr=r2-r1;
phi(i,j)=Dr(i,j)./lambda.*pi.*2;
m(i,j)=pi.*d.*sin(phi(i,j))./lambda;
I(i,j)=(4.*cos(phi(i,j)./2).^2).*real((2.*besselj(1,m(i,j))./m(i,j)).^2);
end
end
NC=225;
Ir=I*NC;
subplot(1,2,1);
image(xs,ys,Ir);
axisequal
colormap(gray(NC));
subplot(1,2,2);
plot(I,m),holdon
clearall
lambda=600e-9;D=1;d=1e-6;a=2.5*d;
ymax=10*lambda*D/a;xmax=ymax;
N=101;
xs=linspace(-xmax,xmax,N);
ys=linspace(-ymax,ymax,N);
fori=1:
N;
forj=1:
N;
r1(i,j)=sqrt(D.^2+(ys(i)-a./2).^2+xs(i).^2);
r2(i,j)=sqrt(D.^2+(ys(j)-a./2).^2+xs(j).^2);
Dr=r2-r1;
phi(i,j)=Dr(i,j)./lambda.*pi.*2;
m(i,j)=pi.*d.*sin(phi(i,j))./lambda;
I(i,j)=(4.*cos(phi(i,j)./2).^2).*real((2.*besselj(1,m(i,j))./m(i,j)).^2);
end
end
NC=225;
Ir=I*NC;
colormap(gray(NC));
plot(m,I),holdon
13.
clearall
lambda=500e-9;D=1;d=1e-6;a=3.5*d;
ymax=10*lambda*D/a;xmax=ymax;
N=101;
xs=linspace(-xmax,xmax,N);
ys=linspace(-10000*ymax,10000*ymax,N);
fori=1:
N;
forj=1:
N;
r1(i,j)=sqrt(D.^2+(ys(i)-a./2).^2+xs(i).^2);
r2(i,j)=sqrt(D.^2+(ys(j)-a./2).^2+xs(j).^2);
Dr=r2-r1;
phi(i,j)=Dr(i,j)./lambda.*pi.*2;
I(i,j)=real(4.*cos(phi(i,j)./2).^2);
end
end
NC=225;
Ir=I/3.*NC;
image(xs,ys,Ir);
colormap(gray(NC));
holdon
14.沙丘
figure('Position',[20031700696],'color','w');holdon;axisequal;axisoff
title('沙丘','fontsize',16,'color','k');
text(180,480,'——万祎龙','fontsize',12,'color','k');
i=1;
forpy=1:
2:
360
c=py*4*pi/360;
b=pi*cos(c);
a=0:
pi/30:
6*pi;
x=100*a/pi+20;
y=10*sin(a+cos(a)*pi-b)*cos(c)+py;
plot(x,y,'color','k');
Z(i,:
)=sin(a+cos(a)*pi-b)*cos(c);
i=i+1;
end
15.
%存脚本文件heart.m
%%一个半径为R的圆周等分成N份,然后一等分点为圆心,以等分点到该圆垂直直径
%%的距离为半径画圆。
N=90;R=1;
t0=(1:
N)*2*pi/N;%%中央圆
x0=R*cos(t0);
y0=R*sin(t0);
t1=linspace(0,2*pi,100);%运动圆
X=cos(t1);
Y=sin(t1);
figure('color','k');
holdon
fori=1:
N
x=x0(i)+x0(i)*X;
y=y0(i)+x0(i)*Y;
plot(x,y,'g');
end
axisequal
axisoff
16.
figure('color','k','Position',[1311280696]);
axes1=axes('position',[0.20.60.30.3]);
axis(axes1,'equal');
axis(axes1,'off');
holdon
rl=1;rs=0.5;
N=30;
t1=linspace(0,2*pi,N);xl=rl*cos(t1);yl=rl*sin(t1);
t2=linspace(0,2*pi,100);xs=rs*cos(t2);ys=rs*sin(t2);
fori=1:
N
plot(xl(i)+xs,yl(i)+ys);
end
axes2=axes('position',[0.50.60.30.3]);
axis(axes2,'equal');
axis(axes2,'off');
holdon
rl=1;rs=1;
N=30;
t1=linspace(0,2*pi,N);xl=rl*cos(t1);yl=rl*sin(t1);
t2=linspace(0,2*pi,100);xs=rs*cos(t2);ys=rs*sin(t2);
fori=1:
N
plot(xl(i)+xs,yl(i)+ys);
end
axes3=axes('position',[0.350.200.30.3]);
axis(axes3,'equal');
axis(axes3,'off');
holdon
rl=1;rs=1.5;
N=30;
t1=linspace(0,2*pi,N);xl=rl*cos(t1);yl=rl*sin(t1);
t2=linspace(0,2*pi,100);xs=rs*cos(t2);ys=rs*sin(t2);
fori=1:
N
plot(xl(i)+xs,yl(i)+ys);
end
17.%%一个半径为R的圆周等分成N份,然后一等分点为圆心,以等分点到定点
%%的距离为半径画圆。
N=60;R=1;
t0=(1:
N)*2*pi/N;%%中央圆
x0=R*cos(t0);
y0=R*sin(t0);
t1=linspace(0,2*pi,100);%运动圆
X=cos(t1);
Y=sin(t1);
figure('color','k');
holdon
fori=1:
N
Rm=(x0(i)^2+(y0(i)-1)^2)^.5;
x=x0(i)+Rm*X;
y=y0(i)+Rm*Y;
plot(x,y,'color','r');
end
axisequal
axisoff
18.
%存函数文件diamond.m
functiondiamond
N=20;
t=linspace(0,2*pi,N);
y=sin(t);
x=cos(t);
figure('color','b');
holdon
fori=1:
N-1
forj=i+1:
N
line(x([ij]),y([ij]),'color','y');
end
end
axisequal
axisoff
19.
subplot(2,2,1);mesh(peaks);
view(-37.5,30); %指定子图1的视点
title('azimuth=-37.5,elevation=30')
subplot(2,2,2);mesh(peaks);
view(0,90); %指定子图2的视点
title('azimuth=0,elevation=90')
subplot(2,2,3);mesh(peaks);
view(90,0); %指定子图3的视点
title('azimuth=90,elevation=0')
subplot(2,2,4);mesh(peaks);
view(-7,-10); %指定子图4的视点
title('azimuth=-7,elevation=-10')
20.[x,y,z]=sphere(20);
colormap(copper);
subplot(1,3,1);
surf(x,y,z);
axisequal
subplot(1,3,2);
surf(x,y,z);shadingflat;
axisequal
subplot(1,3,3);
surf(x,y,z);shadinginterp;
axisequal
21.
[x,y]=meshgrid(-5:
0.1:
5);
z=cos(x).*cos(y).*exp(-sqrt(x.^2+y.^2)/4);
surf(x,y,z);shadinginterp;
pause %程序暂停
i=find(x<=0&y<=0);
z1=z;z1(i)=NaN;
surf(x,y,z1);shadinginterp;
22.(动画的)
[X,Y,Z]=peaks(30);
surf(X,Y,Z)
axis([-3,3,-3,3,-10,10])
axisoff;
shadinginterp;
colormap(hot);
m=moviein(20); %建立一个20列大矩阵
fori=1:
20
view(-37.5+24*(i-1),30) %改变视点
m(:
i)=getframe; %将图形保存到m矩阵
end
movie(m,2); %播放画面2次
23.瀑布图
subplot(1,2,1);
[X,Y,Z]=peaks(30);
waterfall(X,Y,Z)
xlabel('X-axis'),ylabel('Y-axis'),zlabel('Z-axis');
subplot(1,2,2);
contour3(X,Y,Z,12,'k'); %其中12代表高度的等级数
xlabel('X-axis'),ylabel('Y-axis'),zlabel('Z-axis');
24.
t=0:
pi/20:
2*pi;
[x,y,z]=cylinder(2+sin(t),30);
subplot(2,2,1);
surf(x,y,z);
subplot(2,2,2);
[x,y,z]=sphere;
surf(x,y,z);
subplot(2,1,2);
[x,y,z]=peaks(30);
surf(x,y,z);
25.[x,y]=meshgrid(-8:
0.5:
8);
z=sin(sqrt(x.^2+y.^2))./sqrt(x.^2+y.^2+eps);
subplot(2,2,1);
mesh(x,y,z);
title('mesh(x,y,z)')
subplot(2,2,2);
meshc(x,y,z);
title('meshc(x,y,z)')
subplot(2,2,3);
meshz(x,y,z)
title('meshz(x,y,z)')
subplot(2,2,4);
surf(x,y,z);
title('surf(x,y,z)')
26.
t=0:
pi/100:
20*pi;
x=sin(t);
y=cos(t);
z=t.*sin(t).*cos(t);
plot3(x,y,z);
title('Linein3-DSpace');
xlabel('X');ylabel('Y');zlabel('Z');
27.
[x,y,z]=sphere(20);
subplot(1,2,1);
surf(x,y,z);axisequal;
light('Posi',[0,1,1]);
shadinginterp;
holdon;
plot3(0,1,1,'p');text(0,1,1,'light');
subplot(1,2,2);
surf(x,y,z);axisequal;
light('Posi',[1,0,1]);
shadinginterp;
holdon;
plot3(1,0,1,'p');text(1,0,1,'light');
28.
data=rand(10,10,10);
datas=smooth3(data,’box’,3);%box是光滑方法,Matlab中提供可好几种方法,具体查看帮助
subplot(121)
p=patch(isosurface(data,0.5));
patch(isocaps(data,0.5));
isonormals(data,p);
camlight
lightingphong
axisvis3doff
view(3)
subplot(122)
p=patch(isosurface(datas,0.5));
patch(isocaps(datas,0.5));
isonormals(datas,p);
camlight
lightingphong
axisvis3d off
view(3)
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- matlab 绘制 漂亮 图形
![提示](https://static.bdocx.com/images/bang_tan.gif)