Creating a Matlab Contour Plot with Iterative Growth - Help Request

In summary, the conversation is about trying to plot a contour graph for the function f(x,y) = (1/(x^2+y^2)) * e^(x-(sqrt(x^2+y^2))), with a constant value of k = .001 that doubles in size for about 8 iterations. The proposed code uses surfc, but contour3 is suggested as a better option, along with adding the variable k into the code. A sample code is provided for reference.
  • #1
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
  • #2
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: 552
  • #3
Hey thanks! I really appreciate it!
 

1. What is a Matlab contour plot?

A Matlab contour plot is a graphical representation of the variation of a function or data set over a two-dimensional plane. It uses contour lines to connect points with the same value, creating a visualization of the shape and patterns of the data.

2. How do I create a contour plot in Matlab?

To create a contour plot in Matlab, you can use the "contour" function. This function takes in a matrix of data values and automatically generates the contour lines and labels. You can also customize the appearance of the plot by adjusting parameters such as line color and number of contour levels.

3. What is iterative growth in Matlab?

Iterative growth in Matlab is a method of generating data points by repeatedly applying a specific algorithm or function. It is often used for tasks such as solving equations, optimizing parameters, or creating complex visualizations.

4. How can I use iterative growth to create a contour plot in Matlab?

To create a contour plot with iterative growth in Matlab, you can use a loop to repeatedly apply a function to generate data points. These points can then be plotted using the "contour" function. By adjusting the parameters and logic of the loop, you can create a variety of contour plots with different patterns and levels of detail.

5. What are the benefits of using iterative growth for creating contour plots?

Using iterative growth for creating contour plots in Matlab allows for more control and customization over the data points and contour lines. It also allows for the creation of more complex and dynamic plots, as the data can be generated and updated in real-time. Additionally, iterative growth can be used to create contour plots for data sets that may be difficult to visualize with traditional methods.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
996
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
569
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
938
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
3K
Back
Top