4
$\begingroup$

Consider the map $f:\mathbb R^2\to \mathbb R$ defined as $$ f(x,y)=\begin{cases} \|(x,y)\|^2\sin(1/\|(x,y)\|) & (x,y)\neq0 \\ 0 & (x,y) =0\\ \end{cases}$$ I am trying to get a plot like this: enter image description here

This is the code I wrote

    f[x1_, x2_] := 
 Piecewise[{{(Norm[x1, x2])^2 Sin[1/(Norm[x1, x2])], 
    x1 != 0 && x2 != 0}}];
 Plot3D[f[x1, x2], {x1, -5, 5}, {x2, -5, 5}]

But it didn't work.

I am wondering how I can plot and differentiate this map.

Thanks in advance!

$\endgroup$
1
  • $\begingroup$ As the error message quite precisely states, you should use Norm[{x1, x2}] instead of Norm[x1, x2]. $\endgroup$ Commented Jan 9, 2022 at 8:33

2 Answers 2

6
$\begingroup$
f[0, 0] = 0;
f[x_, y_] = Norm[{x, y}]^2 Sin[1/Norm[{x, y}]];
Plot3D[f[x1, x2], {x1, -5, 5}, {x2, -5, 5}]

enter image description here

Your region from -5 to 5 is too large to see the wiggles. Therefore, choose a smaller region:

Plot3D[f[x1, x2], {x1, -.3, .3}, {x2, -.3, .3}]

enter image description here

$\endgroup$
6
$\begingroup$
Clear["Global`*"]

In addition to the corrections that Daniel Huber made, you should change the condition on the Piecewise to zero out the central region, not just the point {0, 0}

f[x1_, x2_] = Piecewise[{{Norm[{x1, x2}]^2 *
      Sin[1/Norm[{x1, x2}]], Norm[{x1, x2}] > 0.045}}];

Plot3D[f[x1, x2],
 {x1, -.1, .1}, {x2, -.1, .1},
 PlotPoints -> 50,
 MaxRecursion -> 3,
 Ticks -> None,
 AxesOrigin -> {0, 0, 0},
 AxesStyle -> AbsoluteThickness[1],
 Boxed -> False,
 BoxRatios -> {1, 1, 1/8},
 RegionFunction ->
  (Abs[#1] > 0.008 || Abs[#2] > 0.008 &)]

enter image description here

EDIT: The derivative of Abs is undefined. However, assuming x is real, then Abs[x] = Sqrt[x^2]

D[f[x1, x2] /. Abs[x_] :> Sqrt[x^2], {{x1, x2}}] // 
  Simplify // TraditionalForm

enter image description here

$\endgroup$
2
  • $\begingroup$ Hi, can you explain more why should I zero out the central region instead just a a single point. Mathematically the equation is 0 only when $(x,y)=(0,0)$. $\endgroup$
    – laikaka
    Commented Jan 1, 2022 at 16:21
  • $\begingroup$ As the Norm becomes smaller, Sin[1/Norm[{x1, x2}]] ripples faster and the function has an arbitrarily large number of ripples. Whereas, the image that you said that you wanted to duplicate was very smooth in the inner region. You can change the threshold to whatever you like. $\endgroup$
    – Bob Hanlon
    Commented Jan 1, 2022 at 16:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.