MATLAB绘制爱心曲线并导出
爱心曲线的表达式:
f
(
x
)
=
x
2
/
3
+
e
3
(
π
−
x
2
)
1
/
2
s
i
n
(
a
π
x
)
f(x)=x^{2/3}+\frac e 3(\pi-x^2)^{1/2}sin(a\pi x)
f(x)=x2/3+3e(π−x2)1/2sin(aπx)
f = @(x,a)x.^2.^(1/3)+exp(1)/3*(pi-x.^2).^(1/2).*sin(a*pi*x);
h = figure('color',[1 1 1]);
set(gcf,'position',[100 100 800 800])
axis square
axis([-2 2 -1.5 2.5])
hold on
filename = 'photo.gif';
x = -2:.01:2;
y = real(f(x,0));
h0 = plot(x,y,'r','linewidth',3);
title('$$x^{2/3}+\frac{e}{3}(\pi-x^2)^{1/2}sin(a\pi x)$$',...
'color','r','fontsize',18,'Interpreter','latex')
t = text(-0.2,2.3,strcat('a=',num2str(0)),...
'color','r','fontsize',15);
for a = 0.02:.02:10
h0.YData = real(f(x,a));
t.String = strcat('a=',num2str(a));
frame = getframe(h);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if a == 0.02
imwrite(imind,cm,filename,'gif', 'DelayTime',0.03);
else
imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',0.03);
end
end