views:

287

answers:

2

I wished to plot this 'Hi', which may be 'Hello World' graphical equivalent in MATLAB. Haven't been able to do it. Any suggestions are welcome.

+7  A: 

Here is a code for the plot using the formula on the linked page and specified axis limits. You can play with colormap, view direction and other properties to get closer.

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])

alt text

yuk
@yuk : That is WOW ! .... you seem some MATLAB Guru !
Arkapravo
+6  A: 

It seems @yuk beat me to it, still this is my version:

[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

screenshot

Amro
Looks really cool! +1
yuk
@Amro : Great job, looks awesome ! If only I could choose 2 Answers ! :)
Arkapravo

related questions