# Batman equation in MATLAB

34 Ansichten (letzte 30 Tage)
Friedrich am 5 Aug. 2011
Kommentiert: Sama Elsayed am 13 Dez. 2019
Hi folks,
I am looking for a smart way to implement the Batman equation in MATLAB:
I came up with this:
syms x y
eq1 = ((x/7)^2*sqrt(abs(abs(x)-3)/(abs(x)-3))+(y/3)^2*sqrt(abs(y+3/7*sqrt(33))/(y+3/7*sqrt(33)))-1);
eq2 = (abs(x/2)-((3*sqrt(33)-7)/112)*x^2-3+sqrt(1-(abs(abs(x)-2)-1)^2)-y);
eq3 = (9*sqrt(abs((abs(x)-1)*(abs(x)-.75))/((1-abs(x))*(abs(x)-.75)))-8*abs(x)-y);
eq4 = (3*abs(x)+.75*sqrt(abs((abs(x)-.75)*(abs(x)-.5))/((.75-abs(x))*(abs(x)-.5)))-y);
eq5 = (2.25*sqrt(abs((x-.5)*(x+.5))/((.5-x)*(.5+x)))-y);
eq6 = (6*sqrt(10)/7+(1.5-.5*abs(x))*sqrt(abs(abs(x)-1)/(abs(x)-1))-(6*sqrt(10)/14)*sqrt(4-(abs(x)-1)^2)-y);
axes('Xlim', [-7.25 7.25], 'Ylim', [-5 5]);
hold on
ezplot(eq1,[-8 8 -3*sqrt(33)/7 6-4*sqrt(33)/7]);
ezplot(eq2,[-4 4]);
ezplot(eq3,[-1 -0.75 -5 5]);
ezplot(eq3,[0.75 1 -5 5]);
ezplot(eq4,[-0.75 0.75 2.25 5]);
ezplot(eq5,[-0.5 0.5 -5 5]);
ezplot(eq6,[-3 -1 -5 5]);
ezplot(eq6,[1 3 -5 5]);
colormap([0 0 1])
title('Batman');
xlabel('');
ylabel('');
hold off
Any other ideas are welcome.
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Oleg Komarov am 5 Aug. 2011
I've submitted just less than a week ago the BATMAN equation to Martin Sona's question but he apparently deleted it (so much of my time...but cache is good)

Melden Sie sich an, um zu kommentieren.

### Antworten (3)

Oleg Komarov am 5 Aug. 2011
Bearbeitet: Walter Roberson am 12 Jan. 2017
% Grey axes
axes('Xlim' ,[-7 7] , 'Xtick' ,-7:7,...
'Ylim' ,[-5 5] , 'Ytick' ,-5:5,...
'YtickL','' , 'XtickL','' ,...
'Ygrid' ,'on' , 'Xgrid' ,'on',...
'Xcolor',[.8 .8 .8], 'Ycolor',[.8 .8 .8]);
hold on
% Outer wings
f1 = '(x/7)^2 * sqrt(abs(abs(x)-3)/(abs(x)-3)) + (y/3)^2 * sqrt(abs(y + 3/7*sqrt(33))/(y + 3/7*sqrt(33))) - 1';
ezplot(f1,[-8 8 -3*sqrt(33)/7 6-4*sqrt(33)/7]);
% Bottom
f2 = 'abs(x/2)-(3*sqrt(33)-7) * x^2/112 - 3 + sqrt(1-(abs(abs(x)-2)-1)^2) - y';
ezplot(f2,[-4 4]);
% Outer ears
f3 = '9 * sqrt(abs((1-abs(x))*(abs(x)-0.75)) / ((1-abs(x))*(abs(x)-0.75))) - 8*abs(x) - y';
ezplot(f3,[-1 -0.75 -5 5]);
ezplot(f3,[ 0.75 1 -5 5]);
% Inner ears
f4 = '3*abs(x) + 0.75*sqrt(abs((0.75-abs(x))*(abs(x)-.5)) / ((.75-abs(x))*(abs(x)-.5))) - y';
ezplot(f4,[-0.75 0.75 2.25 5]);
% Connect inner ears (flat line)
f5 = '2.25*sqrt(abs(((0.5-x)*(0.5+x))/((0.5-x)*(0.5+x)))) - y';
ezplot(f5,[-0.5 0.5 -5 5]);
% Inner wings
f6 = '6*sqrt(10)/7 + (1.5-0.5*abs(x)) * sqrt(abs(abs(x)-1) / (abs(x)-1)) - 6*sqrt(10)/14 * sqrt(4-(abs(x)-1)^2) - y';
ezplot(f6,[-3 -1 -5 5]);
ezplot(f6,[ 1 3 -5 5]);
% Change line color and width
set(get(gca,'children'),'Color','b','Linew',2)
% Title and labels
title('Batman'); xlabel(''); ylabel('')
% Superimpose black axes with xy-ticklabels
xlbl(1:15,1:2) = ' '; xlbl([1,8,15],:) = ['-7';' 0';' 7'];
ylbl(1:11,1:2) = ' '; ylbl([1,6,11],:) = ['-5';' 0';' 5'];
axes('Xlim' ,[-7 7], 'Xtick' ,-7:7,...
'Ylim' ,[-5 5], 'Ytick' ,-5:5,...
'YtickL',ylbl , 'XtickL',xlbl,...
'Box' ,'on' , 'Color' ,'none');
*EDIT*
The link shows that all the f# are multiplied and plotted but it doesn't work because ezplot somehow plots the real part of the imaginary numbers(?).
With the piecewise implementation only the core functions should be used (but I left the extended version so that others can copy):
f1 = '(x/7)^2 + (y/3)^2 - 1';
f2 = 'abs(x/2)-(3*sqrt(33)-7) * x^2/112 - 3 + sqrt(1-(abs(abs(x)-2)-1)^2) - y';
f3 = '9 - 8*abs(x) - y';
f4 = '3*abs(x) + 0.75 - y';
f5 = '2.25 + 0*x - y';
f6 = '6*sqrt(10)/7 + (1.5-0.5*abs(x)) - 6*sqrt(10)/14 * sqrt(4-(abs(x)-1)^2) - y';
The result:
##### 3 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
Oleg Komarov am 5 Aug. 2011
There's a post on fex which is a collection of repositories.
Walter Roberson am 5 Aug. 2011

Melden Sie sich an, um zu kommentieren.

Sally Al Khamees am 21 Feb. 2017
Starting MATLAB R2016b, you may use fimplicit function to plot the equations.Note that I used the Symbolic Math Toolbox to create the symbolic variables x and y.
syms x y
eq1 = ((x/7)^2*sqrt(abs(abs(x)-3)/(abs(x)-3))+(y/3)^2*sqrt(abs(y+3/7*sqrt(33))/(y+3/7*sqrt(33)))-1);
eq2 = (abs(x/2)-((3*sqrt(33)-7)/112)*x^2-3+sqrt(1-(abs(abs(x)-2)-1)^2)-y);
eq3 = (9*sqrt(abs((abs(x)-1)*(abs(x)-.75))/((1-abs(x))*(abs(x)-.75)))-8*abs(x)-y);
eq4 = (3*abs(x)+.75*sqrt(abs((abs(x)-.75)*(abs(x)-.5))/((.75-abs(x))*(abs(x)-.5)))-y);
eq5 = (2.25*sqrt(abs((x-.5)*(x+.5))/((.5-x)*(.5+x)))-y);
eq6 = (6*sqrt(10)/7+(1.5-.5*abs(x))*sqrt(abs(abs(x)-1)/(abs(x)-1))-(6*sqrt(10)/14)*sqrt(4-(abs(x)-1)^2)-y);
fimplicit([eq1, eq2, eq3, eq4, eq5, eq6],'Color','black','Linew',2)
xlim( [-7.25 7.25])
ylim([-5 5])
grid
##### 2 KommentareKeine anzeigenKeine ausblenden
Jonas57 am 14 Okt. 2017
Very Nice! :D
Sama Elsayed am 13 Dez. 2019
how can I make the batman sign a moving plot? like make it plot instead of just popping up when code is evaluted?

Melden Sie sich an, um zu kommentieren.

Jan am 21 Feb. 2017
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Assumptions finden Sie in Help Center und File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by