MATLAB Creating a Matlab Contour Plot with Iterative Growth - Help Request

AI Thread Summary
The discussion revolves around plotting a contour graph for the function f(x,y) = (1/(x^2+y^2)) * e^(x - sqrt(x^2+y^2)), specifically for the case where f(x,y) equals k, starting with k = 0.001 and doubling it over eight iterations. The original attempt used the surfc function, but suggestions were made to use contour3 instead for better visualization of contour lines. Additionally, it was pointed out that the initial code did not incorporate the variable k, which is essential for solving the equation f(x,y) = k. A revised code snippet was provided, which includes a loop to adjust k for each iteration and uses contour3 to generate the desired plots. The response emphasized that while the provided solution might require further adjustments, it would yield a closer representation of the intended contour graph.
member 428835
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')

can someone please help me out?

thanks!
 
Physics news on Phys.org
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:
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.
 

Attachments

  • contour.png
    contour.png
    2.9 KB · Views: 599
Hey thanks! I really appreciate it!
 

Similar threads

Replies
8
Views
2K
Replies
1
Views
3K
Replies
2
Views
3K
Replies
4
Views
3K
Replies
5
Views
2K
Back
Top