3
$\begingroup$

Given an order set of some number, $S=\{1.3, 1.7, 1.9, 2.8\}$, I would like to know how can I mathematically define a function that round a value to the nearest number in the set $S$.

For example, if I give the value 1.72, I'll receive back the number 1.7.

  • 1
    What rule should be followed about numbers exactly between elements of $S$?2012-06-26
  • 0
    Just random numbers.2012-06-26
  • 1
    'Random' is a somewhat technical term.2012-06-26
  • 0
    OK. Let me make $S$ a little bit different: $S=\{(X_{min}+i\cdot\Delta)|i=0,1,\dots,\frac{X_{max}-X_{min}}{\Delta}\}$.2012-06-26
  • 0
    @PauloFracasso: The actual set is immaterial. In your original $S$, there are $2^3=8$ different functions that satisfy the desired property, determined by which of each pair of consecutive numbers will be favored over the other when rounding from their midpoint. (In general, if $|S|=n+1$, there will be $2^n$ such functions.) Two of these are simple to describe (always round up, or always round down). For more detail (and the precise definitions), see my comment on Marvis's answer, and Marvis's edited answer.2012-06-26

1 Answers 1

2

One possible candidate is $$f(x) = \min \{\text{arginf}_{y \in S} \vert x-y\vert\}$$

  • 0
    I don't believe this works. For one thing, this will be a set-valued function, which is probably undesirable. If we decide that it's okay to just "drop" the set brackets, though, then for example, in the $S$ given, we would have $\text{arginf}_{y\in S}|1.5-y|=\{1.3,1.7\}$, so $f(1.5)$ is undefined. We need some convention for choosing the lesser or greater of the (at most) $2$ elements of $\text{arginf}_{y\in S}|x-y|$ for any given $x$. I suggest $f(x)=\max\text{arginf}_{y\in S}|x-y|$.2012-06-26
  • 0
    @CameronBuie Thanks. Happy now :)?2012-06-26
  • 0
    Absolutely! Even though it isn't what *I* suggested. ;-)2012-06-26