function Lemniscates % "Lemniscates" plots one or more examples of each of the following: % The Lemniscate of Bernoulli, The Leminiscate of Gerono, The Lemniscate of % Booth, The Cassinian Oval, and "The Inverse Lemniscate". Just choose an % example from the drop-down menus and click on it. It's that easy! % by Andrew Smith, Dec.8 2008 % close all existing open figures close all % define the figure (the GUI itself) Fig = figure('Units','Normalized',... 'Position',[.6,.2,.68,.76],... 'color',[.01 .035 .43],... 'menubar','none',... 'name','Lemniscates'); % define the axes ha = axes('Units','Normalized',... 'position',... [.12 .13 .76 .73],... 'Box','on',... 'Fontname','Lucida Sans',... 'FontSize',12,... 'FontWeight','d',... 'Visible','off',... 'XTick',[],'YTick',[],... 'GridLineStyle','-.',... 'Color',[.01 .435 .63]); % the title text TitleText = uicontrol('style','text',... 'Units','Normalized',... 'pos',[.078,.89,.81,.04],... 'Fontsize',17,... 'Fontweight','b',... 'string','The Lemniscates of Bernoulli, Gerono, Booth, and Cassini',... 'horiz','right',... 'FontName','Bookman Old Style',... 'Background',[.01 .035 .43],... 'visible','on',... 'foregroundcolor','y'); % The Menus %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Tools Menu ========================================================================= tmenu = uimenu('Label','Tools','ForegroundColor',[.5 0 .5]); uimenu(tmenu,'Label','Grid On/Off','Callback',@GridOnOff) uimenu(tmenu,'Label','Black Axes','Callback',@AxBW); uimenu(tmenu,'Label','Close','Accelerator','X','Callback','close',... 'Separator','on'); % Lemniscate of Bernoulli Menu ======================================================== bmenu = uimenu('Label','Lemniscate of Bernoulli','ForegroundColor',[.5 0 .5]); uimenu(bmenu,'Label','Parametric','Callback',@BernPar,... 'Separator','on','Accelerator','b'); uimenu(bmenu,'Label','Contour Map 1','Callback',@BernContour1); uimenu(bmenu,'Label','Gradient Vectors for Contour Map 1','Callback',@BernContourGrad); uimenu(bmenu,'Label','Contour Map 2','Callback',@BernContour2); uimenu(bmenu,'Label','Contour Map 3','Callback',@BernContour3); % Lemniscate of Gerono Menu =========================================================== gmenu = uimenu('Label','Lemniscate of Gerono','ForegroundColor',[.25 .6 .25]); uimenu(gmenu,'Label','Parametric','Callback',@GeronoPar,... 'Separator','on','Accelerator','g'); uimenu(gmenu,'Label','Parametric 2','Callback',@GeronoPar2); uimenu(gmenu,'Label','Polar (Cartesian Graph)','Callback',@GeronoPol); uimenu(gmenu,'Label','Polar (Polar Graph)','Callback',@GeronoPol2); uimenu(gmenu,'Label','Contour Map','Callback',@GeronoLevel); % Lemniscate of Booth Menu ============================================================= bbmenu = uimenu('Label','Lemniscate of Booth','ForegroundColor',[.85 .14 .25]); uimenu(bbmenu,'Label','Contour Map 1','Callback',@Booth,... 'Separator','on'); uimenu(bbmenu,'Label','Gradient Vectors for Contour Map 1','Callback',@BoothContourGrad); % Lemniscate of Cassinni Menu =========================================================== cmenu = uimenu('Label','Cassinian Oval ','ForegroundColor',[.05 .35 .25]); uimenu(cmenu,'Label','Cassinian Oval Lemniscate','Callback',@CassOval,... 'Separator','on'); uimenu(cmenu,'Label','Contour Map 1','Callback',@CasContour); uimenu(cmenu,'Label','Contour Map 2','Callback',@CassOvalContour); % Inverse Lemniscate of Bernoulli Menu ==================================================== Imenu = uimenu('Label','The Inverse Lemniscate',... 'ForegroundColor',[.05 .35 .25]); uimenu(Imenu,'Label','The Inverse Lemniscate','Callback',@InverseLem); movegui(Fig,'center'); % Callbacks % =============================================================================== %============================================================================================ function GridOnOff(src, evnt) grid end %Close ===================================================================================== function Close(src, evnt) delete(Fig) end % Black/White Axes ============================================================================ function AxBW(hObject,src, evnt) set(gca,'color','k'); end % Bernoulli Parametric ======================================================================= function BernPar(src,evnt) hold off set(TitleText,'visible','off'); theta = 0:.003:2*pi ; x = cos(theta).*sqrt(cos(2.*theta)); y = sin(theta).*sqrt(cos(2.*theta)); h = plot(x,y);grid on axis equal set(h,'Color',[.6 .11 .45]); set(h,'Linewidth',3); set(gca,'xcolor',[.5 .5 .5],'ycolor',[.5 .5 .5],'Fontsize',10); xl = xlabel('0 \leq \theta \leq 2\pi','Color','y'); set(xl,'Fontname','Euclid','Fontsize',18); % Title =================================================================================================================== TS = ['$$','The~Lemniscate~of~Bernouli:x=cos(\theta){\sqrt{cos(2\theta)}}~~~y=sin(\theta){\sqrt{cos(2\theta)}}','$$']; L = title(TS); set(L,'Interpreter','latex'); set(L,'FontWeight','b'); set(L,'Fontsize',19); set(L,'color','y'); end % Bernoulli Contours ================================================================ function BernContour1(src, evnt) hold off set(TitleText,'visible','off'); [x,y] = meshgrid(-2.3403:.01:2.3403); z = ((x.^2+y.^2)).^2-4.*(x.^2-y.^2); contour(x,y,z,30,'linewidth',2); axis('equal','square'); set(gca,'xcolor',[.5 .5 .5],'ycolor',[.5 .5 .5],'Fontsize',10); % Title =========================================================================== TS = ['$$','The~Lemniscate~of~Bernoulli:~~~(x^2+y^2)^2=a^2(x^2-y^2)','$$']; L = title(TS); set(L,'Interpreter','latex'); set(L,'FontWeight','b'); set(L,'Fontsize',18); set(L,'color','y'); end % Bernoulli Contour Gradiants ============================================================= function BernContourGrad(src, evnt) hold on v = -2.3403:.25:2.3403; [x,y] = meshgrid(v); z = ((x.^2+y.^2)).^2-4.*(x.^2-y.^2); [dx,dy] = gradient(z); hold on quiver(x,y,dx,dy,.75); axis('equal','square'); end % Bernoulli Contours 2 ==================================================================== function BernContour2(src, evnt) hold off set(TitleText,'visible','off'); [x,y] = meshgrid(-pi:.005:pi); z = (1./4).*((x.^2+y.^2)+(4.*y.^2./(x.^2+y.^2))); set(gca,'Fontsize',9); contour(x,y,z,.5,'linewidth',2,'color',[.01 .35 .38]); axis('square'); set(gca,'xcolor',[.5 .5 .5],'ycolor',[.5 .5 .5],'Fontsize',10); xl = xlabel('-\pi \leq {\it{x,y}} \leq \pi',... 'Color','y'); set(xl,'Fontname','Euclid','Fontsize',20); % Title ================================================================================= TS = ['$$','The~Lemniscate~of~Bernoulli:~~(x^2+y^2)^2+4y^2=~4c~(x^2+y^2),~~c=.5 ','$$']; L = title(TS); set(L,'Interpreter','latex'); set(L,'FontWeight','b'); set(L,'Fontsize',18); set(L,'color','y'); end % Bernoulli Contours =========================================================================== function BernContour3(src, evnt) hold off set(TitleText,'visible','off'); [x,y] = meshgrid(-2:.01:2); z = (x.^2-x.^4-y.^2).^(1/2);grid on contour(x,y,z,12); colormap('hot'); axis('equal','square'); set(gca,'xcolor',[.5 .5 .5],'ycolor',[.5 .5 .5],'Fontsize',10); xl = xlabel('-1 \leq {\itx} \leq 1 -2 \leq {\ity} \leq 2',... 'Color','y'); set(xl,'Fontname','Euclid','Fontsize',18); % Title ================================================================================= TS = ['$$','f(x,y)=~{\sqrt{x^2-x^4-y^2}}','$$']; L = title(TS); set(L,'Interpreter','latex'); set(L,'FontWeight','b'); set(L,'Fontsize',21); set(L,'color','y'); end % Gerono Parametric =============================================================================== function GeronoPar(src,evnt) hold off set(TitleText,'visible','off'); t = 0:.003:2*pi ; x = t; x1 = cos(t); y1 = cos(t).*sin(t); comet(x1,y1); h = plot(x1,y1);grid on xl = xlabel('0 \leq {\itt} \leq 2\pi','Color','y'); set(xl,'Fontname','Euclid','Fontsize',18); set(gca,'xcolor',[.5 .5 .5],'ycolor',[.5 .5 .5],'Fontsize',10); axis equal set(h,'Color',[.23 .64 .68]); grid on set(h,'Linewidth',3); set(gca,'Fontsize',11); % Title =================================================================================== TS1 = sym(sin(t)+cos(t)); TS2 = sym(sin(t).^2); TS = ['$$','The~Lemniscate~of~Gerono:~~x=cos(t)~~~~y=cos(t)sin(t)','$$']; L = title(TS); set(L,'Interpreter','latex'); set(L,'FontWeight','b'); set(L,'Fontsize',18); set(L,'color','y'); end % Gerono Parametric 2 ========================================================================== function GeronoPar2(src, evnt) set(TitleText,'visible','off'); n = 4; t = linspace(0,2*pi,2000); a = 1; x = a.*cos(t); y = a.*cos(t).*sin(t); p = plot(x,y,'linewidth',2); grid off set(gca,'xcolor',[.5 .5 .5],'ycolor',[.5 .5 .5],'Fontsize',10); axis equal hold on for a = 1:n x = a.*cos(t); y = a.*cos(t).*sin(t); f1 = plot(x,y); set(f1,'Color',[.13 .55 .46],'Linewidth',2) end c = xlabel('0 \leq \theta \leq 2\pi'); set(c,'FontName','Euclid'); set(c,'FontWeight','b'); set(c,'Fontsize',18); set(c,'color','y'); % Title % =========================================================================================== TS = ['$$','The~Lemniscate~of~Gerono:x=a~cos(\theta)~~y=a~cos(\theta)sin(\theta)~~~a = 1,2,3,4','$$']; L = title(TS); set(L,'interpreter','latex'); set(L,'FontName','Euclid'); set(L,'FontWeight','b'); set(L,'Fontsize',18); set(L,'color','y'); end % Gerono Polar ================================================================================================== function GeronoPol(src,evnt) hold off set(TitleText,'visible','off'); t = 0:.001:2*pi ; r = (sec(t).^4.*cos(2.*t)).^(1/2); x = r.*cos(t); y = r.*sin(t); plot(x,y,'color',[.782 .12 .22],'Linewidth',3); set(gca,'xcolor',[.5 .5 .5],'ycolor',[.5 .5 .5],'Fontsize',10); xl = xlabel('0 \leq \theta \leq 2\pi, a = 1'); set(xl,'Fontname','Euclid','Fontsize',18,'Color','y'); axis equal; TS = ['$$','The~Lemniscate~of~Gerono:~~r(\theta)=\pm \sqrt{a^2\frac{cos(2\theta)}{cos(\theta)^4}}','$$']; L = title(TS); set(L,'Interpreter','latex'); set(L,'FontWeight','b'); set(L,'Fontsize',19); set(L,'color','y'); end % Gerono Polar 2 =================================================================================================== function GeronoPol2(src,evnt) hold off set(TitleText,'visible','off'); t = 0:.01:2*pi ; x = t; a = 2; r = sqrt(cos(a.*t)); p = polar(t,r); set(p,'color',[.782 .12 .22],'Linewidth',2); set(gca,'Fontsize',9); set(gca,'xcolor',[.5 .5 .5],'ycolor',[.5 .5 .5],'Fontsize',10); xl = xlabel('0 \leq \theta \leq 2\pi','Color','y'); set(xl,'Fontname','Euclid','Fontsize',18); TS = ['$$','r(\theta)=\sqrt{cos(2\theta)}','$$']; L = title(TS); set(L,'Interpreter','latex'); set(L,'FontWeight','b'); set(L,'Fontsize',19); set(L,'color','y'); end % Gerono Contours ================================================================== function GeronoLevel(src, evnt) hold off set(TitleText,'visible','off'); [x,y] = meshgrid(-3.31:.01:3.31); z = x.^4-(4.*(x.^2-y.^2)); contour(x,y,z,30,'linewidth',2); axis('equal'); colormap('colorcube') set(gca,'xcolor',[.5 .5 .5],'ycolor',[.5 .5 .5],'Fontsize',10); xl = xlabel('-\pi \leq {\it{x,y}} \leq \pi',... 'Color','y'); set(xl,'Fontname','Bookman Old Style','Fontsize',18); % Title ==================================================================== TS = ['$$','The~Lemniscate~of~Gerono:~~x^4=a^2(x^2-y^2)','$$']; L = title(TS); set(L,'Interpreter','latex'); set(L,'FontWeight','b'); set(L,'Fontsize',18); set(L,'color','y'); end % Booth Contours ======================================================================= function Booth(src, evnt) hold off set(TitleText,'visible','off'); [x,y] = meshgrid(-pi:.01:pi); z = (1./4).*((x.^2+y.^2)+(4.*y.^2./(x.^2+y.^2))); set(gca,'Fontsize',9); contour(x,y,z,0:.5:10,'linewidth',2); axis('equal','square'); colormap('colorcube') set(gca,'xcolor',[.5 .5 .5],'ycolor',[.5 .5 .5],'Fontsize',10); xl = xlabel('-\pi \leq {\it{x,y}} \leq \pi',... 'Color','y'); set(xl,'Fontname','Euclid','Fontsize',22); % Title ========================================================================== TS = ['$$','The~Lemniscate~of~Booth:~~(x^2+y^2)^2+4y^2=~4c~(x^2+y^2)','$$']; L = title(TS); set(L,'Interpreter','latex'); set(L,'FontWeight','b'); set(L,'Fontsize',19); set(L,'color','y'); end % Booth Contour Gradiants =================================================================== function BoothContourGrad(src, evnt) hold on v = -pi:.25:pi; [x,y] = meshgrid(v); z = (1./4).*((x.^2+y.^2)+(4.*y.^2./(x.^2+y.^2))); [dx,dy] = gradient(z); hold on quiver(x,y,dx,dy,.75); axis('equal','square'); end % Cassinian Oval Parametric ==================================================================== function CassOval(src, evnt) hold off set(TitleText,'visible','off'); clc a = 1; b = 1; t = 0:.001:2*pi ; M = 2*a.^2*cos(2*t)+2*sqrt(-a.^4+b.^4+a.^4*cos(2*t).^2); x = sqrt((M./2).^2).*cos(t); y = sqrt((M./2).^2).*sin(t); comet(x,y); p = plot(x,y);grid off set(p,'color',[.22 .552 .23],'Linewidth',3); set(gca,'xcolor',[.5 .5 .5],'ycolor',[.5 .5 .5],'Fontsize',10); c = xlabel('The "Cassinian Oval" Lemniscate, a = b = 1'); set(c,'Fontname','Bookman Old Style','Fontsize',16,'color','y'); % Title ==================================================================================================================================================================== TS = ['$$','x = {\sqrt\frac{[2a^2cos(2t)+2{\sqrt{-a^4+b^4+a^4cos(2t)^2}~]^2}}4}~cos(t),~y = {\sqrt\frac{[2a^2cos(2t)+2{\sqrt{-a^4+b^4+a^4cos(2t)^2}~]^2}}4}~sin(t)','$$']; L = title(TS); set(L,'Interpreter','latex'); set(L,'FontWeight','b'); set(L,'Fontsize',12); set(L,'color','y'); end % Cassinian Oval Contours =================================================================== function CasContour(src, evnt) hold off set(TitleText,'visible','off'); a = 5; [x,y] = meshgrid( -7.2599:.01:7.2599); z = sqrt((x-a).^2+y.^2).*sqrt((x+a).^2+y.^2); [c,h] = contour(x,y,z,25,'linewidth',2); axis('equal','square'); colormap('colorcube') set(gca,'xcolor',[.5 .5 .5],'ycolor',[.5 .5 .5],'Fontsize',10); xl = xlabel('a = 5',... 'Color','y'); set(xl,'Fontname','Euclid','Fontsize',18); % Title =========================================================================== TS = ['$$','The~Cassinian~Oval:~~f(x,y)=\sqrt{(x-a)^2+y^2}~\sqrt{(x+a)^2+y^2}','$$']; L = title(TS); set(L,'Interpreter','latex'); set(L,'FontWeight','b'); set(L,'Fontsize',18); set(L,'color','y'); end % Cassinian Oval Contours 2 =================================================================== function CassOvalContour(src, evnt) set(TitleText,'visible','off'); a = 2; b = 2; [x,y] = meshgrid(linspace(-5,5,800)); colormap('colorcube');axis equal z = ((x-a).^2+y.^2).*((x+a).^2+y.^2)-b^4; contour(x,y,z,0:5:50,'linewidth',2); set(gca,'xcolor',[.5 .5 .5],'ycolor',[.5 .5 .5],'Fontsize',10); xl = xlabel('a = b = 2',... 'Color','y'); set(xl,'Fontname','Euclid','Fontsize',18); % Title ================================================================== TS = ['$$','The~Cassinian~Oval:~~((x-a)^2+y^2)~((x+a)^2+y^2)=b^4','$$']; L = title(TS); set(L,'Interpreter','latex'); set(L,'FontWeight','b'); set(L,'Fontsize',18); set(L,'color','y'); end % Inverse Lemniscate ================================================================== function InverseLem(src,evnt) hold off set(TitleText,'visible','off'); t = 0:.001:6*pi ; x = t; r = cos(2.*t).^5+sin(6*pi.*t).^12; x = r.*cos(t); y = r.*sin(t); comet(x,y) plot(x,y,'color',[.782 .12 .22],'Linewidth',1); set(gca,'xcolor',[.5 .5 .5],'ycolor',[.5 .5 .5],'Fontsize',10); axis('equal','square'); xl = xlabel('0 \leq \theta \leq 6\pi'); set(xl,'Fontname','Euclid','Fontsize',18,'Color','y'); TS = ['$$','The~"Inverse~Lemniscate"~~~r(\theta) = cos^{5}(2\theta)+sin^{12}(6\theta)','$$']; L = title(TS); set(L,'Interpreter','latex'); set(L,'FontWeight','b'); set(L,'Fontsize',19); set(L,'color','y'); end end