首先,新建m文件,复制以下代码 function y=hb(x) [m n]=size(x); for i=1:m for j=1:n if rem(x(i,j),2*pi)>=0&&rem(x(i,j),2*pi)<0.5*pi y(i,j)=sin(2*x(i,j)-0.5*pi)+1 elseif rem(x(i,j),2*pi)>=0.5*pi&&rem(x(i,j),2*pi)<1.5*pi y(i,j)=2 elseif rem(x(i,j),2*pi)>=1.5*pi&&rem(x(i,j),2*pi)<2*pi y(i,j)=-cos(2*x(i,j))+1 end end end end 保存后,将下列代码复制到command窗口中,按回车运行即可。 t=0:0.01*pi:2*pi for i=1:5 r(i,:)=i-0.9:0.1:i+0.1; end %绘制花瓣 for i=1:5 a=r(i,:); b=t; [a,b]=meshgrid(a,b) z=(log(a)+5).*hb(5*b+pi*i).*abs(sin(pi*a)) [x,y,z]=pol2cart(b,a,z) surf(x,y,z,(40+i)*ones(size(z))) hold on end %绘制花托 [xx,yy]=meshgrid(-5:0.1:5); h=2*cos((xx.^2+yy.^2).^0.5)-0.64; surf(xx,yy,h,27*ones(size(h))); hold on %绘制补色 xxx=[-0.1 0.1]; yyy=xxx; [xxx,yyy]=meshgrid(xxx,yyy); c=zeros(size(xxx)) for i=1:50 surf(xxx,yyy,c,i*ones(size(c))) hold on end axis equal set(gca,'xtick',[],'ytick',[],'ztick',[]) 本文来源:https://www.wddqw.com/doc/0720f45f3c1ec5da50e27031.html