# Matlab contour plot

Tags:
1. Jun 4, 2014

### joshmccraney

hey pf!

i am trying to plot a contour (topographic) graph the following $f(x,y) = \frac{1}{x^2+y^2} e^{x-(x^2+y^2)^{.5}}$ where $f(x,y) = k$ where $k = .001$ and doubles in size for about 8 iterations. my attempt is here:

x=-3:0.25:3;
y=-3:0.25:3; z=.25:.25:1;
[X,Y]=meshgrid(x,y);
Z=1./(X.^2+Y.^2).*exp(X-(X.^2+Y.^2));
surfc(X,Y,Z); xlabel('x'); ylabel('y'); zlabel('z')

thanks!

2. Jun 5, 2014

### kreil

A solid first shot. I would probably use contour3 instead of surfc (unless you need the surface more than the contour lines). Also, you don't use k at all in your code even though you're trying to solve f(x,y) = k for several values of k.

Try this out:
Code (Text):

k = 1e-3;
figure;
hold on
[X,Y]=meshgrid(-3:0.1:3);
for n = 1:8
k = k*2^(n-1);
Z = 1./(X.^2+Y.^2).*exp(X-sqrt(X.^2+Y.^2))-k;
contour3(X,Y,Z)
end

You get a plot like the one attached. This might need more tweaking but should be closer to what you're looking for.

File size:
2.6 KB
Views:
98
3. Jun 6, 2014

### joshmccraney

Hey thanks!! I really appreciate it!