以下为爱心的MATLAB源代码与对应图片
代码开源无误,皆可复现
clear;clc b=0:0.01*pi:2*pi; a=2; r=a*(1-sin(b)); h=polarplot(b,r,'r'); box on set(h,'LineWidth',3); title({'公式1';'笛卡尔表白:p=a(1-sin(\theta))'});
clear;clc a=ezplot('x^2-abs(x)*y+y^2-15'); axis square grid on set(a,'color','r','LineWidth',3); title({'公式2';'x^2-|x|y+y^2-15=0'});
clear;clc f=@(x,y,z)(x.^2+2.*y.^2+z.^2-1).^3-x.^2.*z.^3-0.1.*y.^2.*z.^3; [x,y,z]=meshgrid(linspace(-3,3)); val=f(x,y,z); [p,v]=isosurface(x,y,z,val,0); patch('faces',p,'vertices',v,'facevertexcdata',jet(size(v,1)),'facecolor','w','edgecolor','flat'); view(3); title({'公式3';'(x^2+2y^2+z^2-1)^3-x^2z^3-0.1y^2z^3=0'}); box on; grid on; axis equal;
clear;clc [x,y]=meshgrid(-5:0.01:5,-4:0.01:5); v=x.^2-abs(x).*y+y.^2+10./abs(5*x+sin(5*y))<15; contourf(x,y,v); axis square; title({'公式4';'x^2-|x|y+y^2+10/|5x+sin(5y)|<15'}); colormap(jet);
clear;clc b=ezplot('x^2+(y-(x^2)^(1/3))^2=13'); set(b,'color','g','LineWidth',5); title({'公式5';'(x^2+(y-(x^2)\^(1/3))^2=9'}); axis square; grid on axis([-5,5,-5,6])
clear;clc [x,y,z]=meshgrid(linspace(-1.3,1.3)); val=(x.^2+2*y.^2+z.^2-1).^3-x.^2.*z.^3-0.1*y.^2.*z.^3; isosurface(x,y,z,val,0) title({'公式6';'(x^2+2y^2+z^2-1)^3-x^2z^3-0.1y^2z^3=0'}); axis equal grid on box on; view(-10,24);
clear;clc subplot(2,3,1) b=0:0.01*pi:2*pi; a=2; r=a*(1-sin(b)); h=polarplot(b,r,'r'); box on set(h,'LineWidth',3); title({'公式1';'p=a(1-sin(\theta))'}); subplot(2,3,2) a=ezplot('x^2-abs(x)*y+y^2-15'); axis square grid on set(a,'color','r','LineWidth',3); title({'公式2';'x^2-|x|y+y^2-15=0'}); subplot(2,3,3) f=@(x,y,z)(x.^2+2.*y.^2+z.^2-1).^3-x.^2.*z.^3-0.1.*y.^2.*z.^3; [x,y,z]=meshgrid(linspace(-3,3)); val=f(x,y,z); [p,v]=isosurface(x,y,z,val,0); patch('faces',p,'vertices',v,'facevertexcdata',jet(size(v,1)),'facecolor','w','edgecolor','flat'); view(3); title({'公式3';'(x^2+2y^2+z^2-1)^3-x^2z^3-0.1y^2z^3=0'}); box on; grid on; axis equal; subplot(2,3,4) [x,y]=meshgrid(-5:0.01:5,-4:0.01:5); v=x.^2-abs(x).*y+y.^2+10./abs(5*x+sin(5*y))<15; contourf(x,y,v); axis square; title({'公式4';'x^2-|x|y+y^2+10/|5x+sin(5y)|<15'}); colormap(jet); subplot(2,3,5) b=ezplot('x^2+(y-(x^2)^(1/3))^2=13'); set(b,'color','g','LineWidth',5); title({'公式5';'(x^2+(y-(x^2)\^(1/3))^2=9'}); axis square; grid on axis([-5,5,-5,6]) subplot(2,3,6) [x,y,z]=meshgrid(linspace(-1.3,1.3)); val=(x.^2+2*y.^2+z.^2-1).^3-x.^2.*z.^3-0.1*y.^2.*z.^3; isosurface(x,y,z,val,0) title({'公式6';'(x^2+2y^2+z^2-1)^3-x^2z^3-0.1y^2z^3=0'}); axis equal grid on box on; view(-10,24);