0

Suppose $x \in \mathbb{R}$, and $y \in [a, b]$, where $a, b \in \mathbb{R}$. I want to minimize the difference between $x$ and $y$ but am not sure how to write it in mathematical notation.

For example, if $x = 10$, and $y \in [11, 35]$, then the minimum difference between $x$ and $y$ is 1.

The way that I came up with is: $min\{|x - y|\}$. Is this correct?

Adrian
  • 1,976
  • 1
    Not quite sure what you are asking. If $a≤x≤b$ the answer is $0$, right? Otherwise if $x<a$ then the answer is $(a-x)$ and if $x>b$ the answer is $(x-b)$. Or have I misunderstood the question ? – lulu Apr 15 '23 at 01:08
  • 2
    See "distance from a point to a set" in metric topology: $d(x,[a,b]) := \inf{d(x,y)\text{ }|\text{ }y\in [a,b]}$. – Kevin Apr 15 '23 at 01:15
  • Note that $\min {\vert y-x\vert } = \vert y-x \vert$ since it's a singleton. – CyclotomicField Apr 15 '23 at 01:27
  • $$\begin{cases} 0 &: x \in [a, b]\ a - x &: x < a\ x - b &: x > b \end{cases}$$ – Graviton Apr 15 '23 at 03:02

2 Answers2

0

Add a specification to your set to identify the possible values of $y$:

$$ \min\{ |x - y|\ |\ y \in [a, b]\}. $$

But as in Kevin's comment above, you may want to replace the minimum by the infimum. In the case you are describing, they are equivalent, but if you want to find the distance from a point to an open interval, say, the minimum distance may be undefined. For example, $\min\{ |10 - y|\ |\ y \in (11, 35)\}$ is undefined, while $\inf\{ |10 - y|\ |\ y \in (11, 35)\} = 1$.

0

For any interval which has a real midpoint $m$ and a non-negative length $l$, $$\left(\frac{2m\ -\ l\ -\ 2x}{2}\right)\ H\left(\frac{2m\ -\ l\ -\ 2x}{2}\right)\ +\ \left(\frac{2x\ -\ 2m\ -\ l}{2}\right)\ H\left(\frac{2x\ -\ 2m\ -\ l}{2}\right)$$ where $H()$ is the Heaviside function should return this distance as a function of $x$.

user10478
  • 1,904
  • 1
  • 15
  • 28