1

I have been having trouble plotting the following in MatLab:

$$f(x,y) = \frac{x}{x^2 + y^2}$$

I seem to have no trouble plotting similar functions (using a meshgrid). In fact, if I just try plotting $z = x^2 + y^2$, I don't run into any issues. Why is that that when I try to put an x in the numerator that things fall apart? I have also tried plotting with GeoGebra, but have had no luck.

Is there a way to plot this in MatLab? I am learning how to calculate tangent planes, and I would like to see visual representations of my work to confirm that I am arriving at correct conclusions.

1 Answers1

2

Using the following commands we will get the required plot:

  1. Initializing - $x = -20:1:20; \ y = -20:1:20$.
  2. Creating grid - $[X,Y] \ = \ \text{meshgrid}(x,y);$
  3. Ploting - $\text{mesh}(X./(X.^2+Y.^2))$

The result $\frac{x}{x^2+y^2}$

Galc127
  • 4,451
  • This works because the plotting ignores Nan (poor Nan). – copper.hat Feb 20 '16 at 17:27
  • @copper.hat, this is true, thanks for noticing. I think that this is what the OP asked for. – Galc127 Feb 20 '16 at 17:28
  • This is great, thanks!

    Interesting point though. In MatLab, if I use plot3(1, 2, 0.2, 'marker', 'o') the little circle is not actually on the surface. However, if I plot the same point in GeoGebra, it sits on the surface.

    Any idea why?

    –  Feb 20 '16 at 17:32