Batman equation in MATLAB

조회 수: 109 (최근 30일)
Friedrich
Friedrich 2011년 8월 5일
댓글: Sama Elsayed 2019년 12월 13일
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
Oleg Komarov
Oleg Komarov 2011년 8월 5일
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)

댓글을 달려면 로그인하십시오.

답변 (3개)

Oleg Komarov
Oleg Komarov 2011년 8월 5일
편집: Walter Roberson 2017년 1월 12일
% 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
Oleg Komarov
Oleg Komarov 2011년 8월 5일
Upload it somewhere and then post the link included in <<http://...>>
There's a post on fex which is a collection of repositories.
Walter Roberson
Walter Roberson 2011년 8월 5일
The post listing a partial list of repositories is http://www.mathworks.com/matlabcentral/answers/7924-where-can-i-upload-images-and-files-for-use-on-matlab-answers

댓글을 달려면 로그인하십시오.


Sally Al Khamees
Sally Al Khamees 2017년 2월 21일
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.
You can read more about fimplicit here https://www.mathworks.com/help/matlab/ref/fimplicit.html
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
Jonas57
Jonas57 2017년 10월 14일
Very Nice! :D
Sama Elsayed
Sama Elsayed 2019년 12월 13일
how can I make the batman sign a moving plot? like make it plot instead of just popping up when code is evaluted?

댓글을 달려면 로그인하십시오.


Jan
Jan 2017년 2월 21일

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by