1
$\begingroup$

I'm fairly new to Mathematica. Im trying to plot a function but i cannot seem to get it right.

The function is: $f:\mathbb{R} \to \mathbb{R},f(x)=inf\{\vert x-k\vert \vert k\in \mathbb{Z}\}$

I tried defining it seperatly using the Min[] function for the infimum and Abs[] for the absolute value. I read about using something called ImplicitRegion[] but i do not understand how i would use it such that i can tell that $z \in \mathbb{Z}$.

It would be much appreciated if you could tell me how i can plot such a function.

Thank you for helping me out.

$\endgroup$
1
  • 2
    $\begingroup$ Please include the Mathematica code you have tried, the problems you encountered, and what your function is meant to provide. $\endgroup$
    – bbgodfrey
    Commented Oct 25, 2021 at 21:39

1 Answer 1

1
$\begingroup$

Edit

I think you want to plot the function which only at countable number of points are non-differentiable. Such function is a periodic function.

We can deduce this result all by Mathematica.

Simplify[Min[Abs[x - β], Abs[x - (i - 1)], Abs[x - i], 
  Abs[x - (i + 1)], 
  Abs[x - α]], {i <= x <= i + 1, α >= i + 1, β <= 
   i - 1}]

Min[1 + i - x, -i + x]

It means that for $i\leq x \leq i+1$, $$\inf_\limits{i\in \mathbb{Z}}| x-i|=\min\{1+i+x,-i+x\}$$

So we can define the function If[i <= x <= i + 1, Min[1 + i - x, -i + x]] for a fixed i

Manipulate[
 Plot[If[i <= x <= i + 1, Min[1 + i - x, -i + x]], {x, -6, 6}, 
  AspectRatio -> Automatic, Axes -> {True, False}], {i, -5, 5, 1}]
Show[Table[
  Plot[If[i <= x <= i + 1, Min[1 + i - x, -i + x]], {x, -6, 6}, 
   AspectRatio -> Automatic, Axes -> {True, False}], {i, -6, 5, 1}]]

enter image description here

Original

Manipulate[
 Plot[Min[Table[Abs[x - i], {i, -n, n}]], {x, -n, n}, 
  AspectRatio -> Automatic], {n, 1, 10, 1}]

enter image description here

$\endgroup$
2
  • $\begingroup$ This was exactly what i was looking for. Thank you for the nice explanation. What does the Table[] function do? $\endgroup$ Commented Oct 26, 2021 at 8:03
  • $\begingroup$ @AndreasFelder Table list all the cases for i in the range. $\endgroup$
    – cvgmt
    Commented Oct 26, 2021 at 8:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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