Creating a Matlab Contour Plot with Iterative Growth - Help Request

Click For Summary
SUMMARY

This discussion focuses on creating a contour plot in MATLAB for the function f(x,y) = (1/(x^2+y^2)) * exp(x - sqrt(x^2+y^2)), with the goal of visualizing the function at various levels of k, starting from k = 0.001 and doubling for eight iterations. The initial attempt used the surfc function, but the recommended approach is to utilize contour3 for better visualization of contour lines. The final solution involves iterating through values of k while plotting the contours, providing a more accurate representation of the function's behavior.

PREREQUISITES
  • Understanding of MATLAB syntax and functions
  • Familiarity with contour plotting techniques
  • Basic knowledge of mathematical functions and their graphical representations
  • Experience with meshgrid and surface plotting in MATLAB
NEXT STEPS
  • Learn how to use MATLAB's contour3 function effectively
  • Explore MATLAB's meshgrid function for creating 2D grids
  • Investigate the use of exponential functions in contour plots
  • Study iterative algorithms for dynamic plotting in MATLAB
USEFUL FOR

Mathematics students, data visualization specialists, and MATLAB users looking to enhance their skills in contour plotting and function visualization.

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: 621
Hey thanks! I really appreciate it!
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K