How do I convert a T dependent Mexican hat plot to a surface plot.
Show older comments
I have created this code to create a gif of a temperature dependent potential.
clear all
clc
clf
lam=0.5;
phi=linspace(-7,7,1000);
eta=3;
init=7;
filename = 'Nachos.gif';
for n = init:-init/100:-init %Allows me to cycle through values of T,
%from the initial value to zero and back.
T=sqrt(n^2);
V=0.25*lam.*(phi.^2-eta^2).^2+0.5*lam*T^2.*phi.^2; %T dependant potential
plot(phi,V)
axis([-8 8 0 15])
drawnow %Adds current plot as a frame in the gif.
frame = getframe(1);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if n == init;
imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','WriteMode','append');
end
end
I would like to create the equivalent for the 3D surface plot :

But can't seem to get it to work, would anybody be able to help?
Answers (1)
Star Strider
on 27 Feb 2016
This will give you what appears to be the surface plot your animated plot traces:
lam=0.5;
phi=linspace(-7,7,1000);
eta=3;
init=7;
fin=0.1;
n=1;
n = init:-14/100:-init;
[T,P] = meshgrid(n, phi);
Vfcn = @(phi,T) 0.25*lam.*(phi.^2-eta^2).^2+0.5*lam*T.^2.*phi.^2;
V = Vfcn(P,T);
figure(1)
meshc(T, P, V)
grid on
axis([-8 8 ylim 0 15])
It’s not the plot you posted as what you want, but it does reproduce the plot in your animation. I’ll let you sort that. You might want to consider using cart2pol or pol2cart since I’m not certain what you’re doing.
2 Comments
Stephen Cripps
on 27 Feb 2016
Star Strider
on 27 Feb 2016
My code does create a 3D version of your plot. If you want it to be like the one you pictured, you have to define it in terms of the matrices the meshgrid function produces. I can’t follow what you’re doing so I came up with a simple example:
[X,Y] = meshgrid(-5:0.1:+5);
Z = -(X.^2 + Y.^2).*exp(-0.3*(X.^2 + Y.^2));
figure(3)
mesh(X, Y, Z)
grid on

Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!