MATLAB says “Hi”

June 17th, 2010 | Categories: general math, math software, mathematica, matlab | Tags:

One of the earliest posts I made on Walking Randomly (almost 3 years ago now – how time flies!) described the following equation and gave a plot of it in Mathematica.

\light f(x,y)=e^{-x^2-\frac{y^2}{2}} \cos (4 x)+e^{-3\left((x+0.5)^2+\frac{y^2}{2}\right)}

Some time later I followed this up with another blog post and a Wolfram Demonstration.

Well, over at Stack Overflow, some people have been rendering this cool equation using MATLAB. Here’s the first version

x = linspace(-3,3,50);
y = linspace(-5,5,50);
[X Y]=meshgrid(x,y);
Z = exp(-X.^2-Y.^2/2).*cos(4*X) + exp(-3*((X+0.5).^2+Y.^2/2));
Z(Z>0.001)=0.001;
Z(Z<-0.001)=-0.001;
surf(X,Y,Z);
colormap(flipud(cool))
view([1 -1.5 2])

and here’s the second.

[x y] = meshgrid( linspace(-3,3,50), linspace(-5,5,50) );
z = exp(-x.^2-0.5*y.^2).*cos(4*x) + exp(-3*((x+0.5).^2+0.5*y.^2));
idx = ( abs(z)>0.001 );
z(idx) = 0.001 * sign(z(idx)); 

figure('renderer','opengl')
patch(surf2patch(surf(x,y,z)), 'FaceColor','interp');
set(gca, 'Box','on', ...
    'XColor',[.3 .3 .3], 'YColor',[.3 .3 .3], 'ZColor',[.3 .3 .3], 'FontSize',8)
title('$e^{-x^2 - \frac{y^2}{2}}\cos(4x) + e^{-3((x+0.5)^2+\frac{y^2}{2})}$', ...
    'Interpreter','latex', 'FontSize',12) 

view(35,65)
colormap( [flipud(cool);cool] )
camlight headlight, lighting phong

Do you have any cool graphs to share?

  1. June 18th, 2010 at 03:28
    Reply | Quote | #1

    Wink:
    exp(-(x**2+y**2-32)**2) + exp(-(x+2)**4-(y+2)**4)+exp(-(3*x+6+0.5*y)**4-(y-2)**4) + exp(-(x**2+y**2-16)**2)*(atan(50*x-40)/pi+0.5) + exp(-(8*x**2+y**2-48)**2)*exp(-2*x**2)

    Picture at http://picasaweb.google.com/107831669558613198414/Miscellaneous#5483932687034621314

    A lot less fascinating than the above eqs. since this one’s rather long.

  2. June 18th, 2010 at 04:57
    Reply | Quote | #2

    Do you guess we can do a ‘HELLO WORLD’ ! ….. It may take a long time to develop such ‘potential theory’ type ‘HELLO WORLD’ functions ! …. still worth a try !

  3. June 18th, 2010 at 14:08
    Reply | Quote | #3

    @Arkapravo
    My guess is “HELLO WORLD” can be done. Starting with exp(-X.^2-Y.^2/2).*cos(8*X) you get 7 vertical type lines for the HELLO part – though getting vertical lines is more troublesome (without messing what you already have too much). Let me see what I can come up with.

  4. Joplin
    June 19th, 2010 at 20:37
    Reply | Quote | #4

    I believe the best but hard thing to do is to find the equation for each letter of the alphabet. Then we can write everything we want with simple translations.

  5. rp
    June 20th, 2010 at 04:36
    Reply | Quote | #5

    Here it is in Maple

    f := (x,y)->exp(-x^2-y^2/2)*cos(4*x)+exp(-3*((x+1/2)^2+y^2/2)):
    plot3d(f, -2.1..2.1, -5..5, view=[-2.1..2.1,-5..5,-1..0], orientation=[-90,0,0], axes=boxed, grid=[80,80]);

  6. August 15th, 2010 at 02:51
    Reply | Quote | #6

    I have posted my plot of “hi” in Matlab.It’s kind of like pudding. Welcome to my blog to take a look. Though my blog is in Chinese, I guess it doesn’t matter. http://www.elly66.com/maths/hi

  7. August 15th, 2010 at 09:30
    Reply | Quote | #7

    Hi Elly66

    Nice plot – thanks for sharing. Good luck with your blog.

    Mike

  8. Yoonus
    February 25th, 2011 at 17:30
    Reply | Quote | #8

    Nice work, thanks

  9. Eva
    June 29th, 2011 at 09:25
    Reply | Quote | #9

    The same thing with less code to write by using symbolic:
    Type
    > mupad
    in MATLAB, and in the mupad notebook, type
    f:=exp(-x^2-y^2/2)*cos(4*x) + exp(-3*((x+1/2)^2+y^2/2))
    plot(max(min(f,1/1000),-1/1000),#3D)

  10. Anonymous
    November 28th, 2016 at 02:30

    change the mesh40/(1+(x-4)^2)+5*sin(20*x/pi) please

1 trackbacks

  1. Say HI in MuPAD « Ngô Quốc Anh Pingback | 2013/01/28