Drawing ellipsoid with tanh

103 Views Asked by At

The function $f(x,y)=\tanh(R-\sqrt{x^2+y^2})$ for a given $R>0$ draws a circle with radius R with maximum and minimum of +1 and -1. This I can see when I plot

f[x_, y_] := Tanh[5 - Sqrt[x^2 + y^2]]; ContourPlot[f[x, y], {x, -10, 10}, {y, -10, 10}]

If I want to do the same, but draw an ellipsoid with major and minor axis a and b, then how would I go about doing that?

1

There are 1 best solutions below

0
On BEST ANSWER

You can change the definition of your function $f$ to

$\quad \quad f(x,y)=\tanh(\sqrt{(a\, b)^2}-\sqrt{(b\, x)^2 + (a\, y)^2}\,)$

To visualize the resulting elliptical contours of $f$ in Mathematica, you can use the following code:

With[{a = 2, b = 3},
  Module[{f, c},
    c = Max[a, b] + 1; 
    f[x_, y_] := Tanh[Sqrt[(a b)^2] - Sqrt[(b x)^2 + (a y)^2]];
    ContourPlot[f[x, y], {x, - c, c}, {y, -c, c},
      GridLines -> {{-a, a}, {-b, b}}, 
      GridLinesStyle -> Directive[White, Dashed],
      Method -> {"GridLinesInFront" -> True}]]]

plot