File:Cubic equation with three real roots.gif

Summary
%MATLAB Source code
 * Other information:

clc clear all

opengl software filename = 'cubicanimation.gif'; myfig=figure; set(gcf, 'Position', [1 1 640 480]); i=0; for alpha=0:0.01:2*pi/3 hold off x=-2.1:0.01:2.1; y=x.^3-3*x; plot3(x,y,0*x,'LineSmoothing','on','LineWidth',2); hold on   plot3(0*x,y,0*x,'LineSmoothing','on','LineWidth',2); set(gca,'FontSize',15,'FontWeight','bold')

alph=0:0.01:2*pi; X=2*cos(alph); Y=2*cos(3*alph); Z=2*sin(alph);

hold on   plot3(X,Y,Z,'r-','LineSmoothing','on','LineWidth',2); xlabel('X'); ylabel('Y'); zlabel('Z'); hold on   a=alpha+2*pi/3*[0 1 2 3]; plot3(2*cos(a),2*cos(3*a),2*sin(a),'green','LineSmoothing','on','LineWidth',2); a=alpha+2*pi/3*[0 1 2]; zero=[0 0 0]; plot3([zero;2*cos(a)],[2*cos(3*a);2*cos(3*a)],[zero;2*sin(a)],'black','LineSmoothing','on','LineWidth',2); plot3([2*cos(a);2*cos(a)],[2*cos(3*a);2*cos(3*a)],[2*sin(a);zero],'cyan','LineSmoothing','on','LineWidth',2);

a=[alpha alpha+2*pi/3 alpha+4*pi/3 alpha+2*pi]; plot3(2*cos(a),2*cos(3*a),0*a,'co-','MarkerSize',10,'LineSmoothing','on','LineWidth',2);

view([42,26]) axis tight axis equal

drawnow; i=i+1; if i==1 pause(2); end; pause(0.1); frame = getframe(myfig,[100 1 450 450]); im = frame2im(frame); [A,map] = rgb2ind(im,256); if i == 1; imwrite(A,map,filename,'gif','LoopCount',Inf,'DelayTime',0.05); else imwrite(A,map,filename,'gif','WriteMode','append','DelayTime',0.05); end end