您的当前位置:首页matlab经典算法的程序

matlab经典算法的程序

2023-12-21 来源:爱问旅游网
matlab经典算法的程序——绘图

时间:2010-03-19 18:56:25 作者:Admin 点击:239 程序代码:

clear clc

subplot(1,2,1); t = 0:0.01:2*pi;

x = cos(2*t).*(cos(t).^2); y = sin(2*t).*(sin(t).^2); comet(x,y) subplot(1,2,2);

t = -10*pi:pi/250:10*pi;

comet3((cos(2*t).^2).*sin(t),(sin(2*t).^2).*cos(t),t) clear clc

subplot(2,2,1)

contour3(peaks,50); %画出曲面在三度空间中的等高线 axis([-inf inf -inf inf -inf inf]); subplot(2,2,2)

contour(peaks, 50); %画出曲面等高线在XY平面的投影 subplot(2,2,3)

t=linspace(0,20*pi, 501);

plot3(t.*sin(t), t.*cos(t), t);% 画出三度空间中的曲线 subplot(2,2,4)

plot3(t.*sin(t), t.*cos(t), t, t.*sin(t), t.*cos(t), -t);% 同时画出两条三度空间中的曲线

clear clc

t=(0:0.02:2)*pi; x=sin(t); y=cos(t); z=cos(2*t);

plot3(x,y,z,'b-',x,y,z,'bd') view([-82,58]); box on

legend('链','宝石'); clear clc

subplot(3,3,1) ezplot('cos(x)') subplot(3,3,2)

ezplot('cos(x)', [0, pi]) subplot(3,3,3)

ezplot('1/y-log(y)+log(-1+y)+x - 1') subplot(3,3,4)

ezplot('x^2 - y^2 - 1') subplot(3,3,5)

ezplot('x^2 + y^2 - 1',[-1.25,1.25]); axis equal subplot(3,3,6)

ezplot('x^3 + y^3 - 5*x*y + 1/5',[-3,3]) subplot(3,3,7)

ezplot('x^3 + 2*x^2 - 3*x + 5 - y^2') subplot(3,3,8) ezplot('sin(t)','cos(t)') subplot(3,3,9)

ezplot('sin(3*t)*cos(t)','sin(3*t)*sin(t)',[0,pi])

clear clc

subplot(2,2,1), fplot('humps',[0 1])

subplot(2,2,2), fplot('abs(exp(-j*x*(0:9))*ones(10,1))',[0 2*pi])

subplot(2,2,3), fplot('[tan(x),sin(x),cos(x)]',2*pi*[-1 1 -1 1])

subplot(2,2,4), fplot('sin(1 ./ x)', [0.01 0.1],1e-3)

clear clc

[X0,Y0,Z0]=sphere(30); %产生单位球面的三维坐标 X=2*X0;Y=2*Y0;Z=2*Z0; %产生半径为2的球面的三维坐标 clf

subplot(1,2,1);

surf(X0,Y0,Z0); %画单位球面

shading interp %采用插补明暗处理

hold on,mesh(X,Y,Z),colormap(hot),hold off %采用hot色图 hidden off %产生透视效果 axis equal,axis off %不显示坐标轴

title('透视图') subplot(1,2,2);

surf(X0,Y0,Z0); %画单位球面

shading interp %采用插补明暗处理

hold on,mesh(X,Y,Z),colormap(hot),hold off %采用hot色图 hidden on %产生消隐效果 axis equal,axis off %不显示坐标轴 title('消隐图')

clear clc

[x,y,z] =peaks; subplot(2,3,1);

meshz(x,y,z); %曲面加上围裙,即给出曲面和零平面 axis([-inf inf -inf inf -inf inf]); subplot(2,3,2);

waterfall(x,y,z); %在x方向产生水流效果 axis([-inf inf -inf inf -inf inf]); subplot(2,3,3);

meshc(x,y,z); %同时画出网状图与等高线 axis([-inf inf -inf inf -inf inf]); subplot(2,3,4);

surfc(x,y,z); %同时画出曲面图与等高线 axis([-inf inf -inf inf -inf inf]); subplot(2,3,5)

surfl(x,y,z); %给出带光照效果的彩色表面图 axis([-inf inf -inf inf -inf inf]); subplot(2,3,6) contourf(x,y,z);

axis([-inf inf -inf inf -inf inf]);

clear clc

x=-2:0.01:2;

[x,y]=meshgrid(x,x); %x和y都是401x401的矩阵 r=sqrt(x.^2+x.^2)+eps; z=sinc(r); subplot(2,1,1); mesh(z); subplot(2,1,2); surf(x,y,z);

clear clc

x=[11.4 23.5 35.4 15.6]; explode=zeros(size(x)); [c,offset]=min(x); explode(offset)=c; pie(x,explode)

clear

clc

t=0:0.001:10; y=sin(t); % plot(t,y); Y=sin(10*t); c=y.*Y;

plot(t,y,'r:',t,c,'b')

t=-10:1:10; subplot(2,2,1); bar(t,cos(t)); subplot(2,2,2); compass(t,cos(t)); subplot(2,2,3); rose(t,cos(t)); subplot(2,2,4); fill(t,cos(t),'b');

因篇幅问题不能全部显示,请点此查看更多更全内容