Batman equation in MATLAB

46 次查看(过去 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 个评论
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 中查找有关 Calculus 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by