Find the Maximum for Floor function

524 Views Asked by At

What will be the maximum of this function

$$ F(x) = x \big\lfloor \frac{N-x}c \big\rfloor$$

where $c$ and $N$ are constant and $x$ is variable, $ 1 \le x \le N$.

How to solve for floor function?

2

There are 2 best solutions below

0
On

One can for a moment forget about the floor function.

Let us assume without loss of generality that $N, c > 0$, and $x \in \mathcal{R}$. Different cases require I believe a very simple adaption.

One can for a moment forget about the floor function.

Then the maximum of $\bar{F} (x) = x \frac{N-x}{c} $ is attained for $x = \frac{N}{2}$, which can be found by equating the first derivative to zero.

If $\frac{N/2}{c}$ is an integer, then the maximum of your function $F(x)$ is also attained for $x = \frac{N}{2}$.

If $\frac{N/2}{c}$ is not an integer, the function F will be linear and increasing over the interval $[ k ,j]$, where $k,j$ stand for $\lfloor \frac{N/2}{c} \rfloor$ and $\lceil \frac{N/2}{c} \rceil$.

This is because the second term in $F(x)$, containing the floor function, will be constant as long as the argument is not an integer.

Then, the supremum will be attained for $x = \lceil \frac{N/2}{c} \rceil$. Now one can consider the further constraint $1 \leq x \leq n$: if $ \lceil \frac{N/2}{c} \rceil < n$, no changes. If $ \lceil \frac{N/2}{c} \rceil < n$, then the supremum is attained by $x=n$.

0
On

I have been assuming that $N=n$, by negligence of the OP. (Otherwise that makes the problem abnormally complicated.)

The function $F$ is piecewise linear, with decreasing slopes. The jumps occur when $$x=n-kc$$ for integer $k$.

We must respect the constraint $0\le x\le n$, so that

$$0\le k\le\frac nc$$

As the line segments are open on the right, there will actually be no maximum but only a supremum, which is the largest of

$$(n-kc)k.$$

This value occurs at $$k=\left\lfloor\frac n{2c}\right\rfloor=\left\lceil\frac n{2c}\right\rceil,$$ giving the maximal value

$$\left(n-\left\lfloor\frac n{2c}\right\rfloor c\right)\left\lfloor\frac n{2c}\right\rfloor.$$