Discretizing a mathematical equation

193 Views Asked by At

enter image description here

This is a 3D map that maps every $(x,y,z)\to (x',y',z')$ uniquely. If i want to implement it's discrete counterpart on matlab platform, i do the following $$\text{if} (i<=\dfrac{n}{2} \wedge j\leq \dfrac{n}{2})$$ \begin{eqnarray*} x'=2\cdot (i-1)+1\\ y'=2\cdot (j-1)+1\\ z'= \lfloor 0.25\cdot(k-\mod(k-1,2))\rfloor+1; \end{eqnarray*} The input to discretized equatin are integers and the output should also be integers that is why i have used the floor function and since the function is part of some algorithm that involves indexing that starts from $(1,1)$ ex Matlab that is why the $mod$ function is used. But this is clearly not a unique mapping because $(1,1,1)\to (1,1,1), (1,1,2)\to (1,1,1), (1,1,3)\to (1,1,1), (1,1,4)\to (1,1,1)$. So there has to be some minor adjustments or major ajdustments in the discretizing part that retains the uniqueness of the equation. Can somebody suugest ?

Edit: After the answer: I have added the code where $n=36$, but still it is not giving the unique mapping.

1

There are 1 best solutions below

9
On BEST ANSWER

This solution assumes $n$ is a multiple of $4$. Let $\def\1{{\bf 1}}\1[S]$ be a function which is equal to $1$ if the statement $S$ is true, and zero otherwise. This is a bijective mapping from the set of ordered tuples $(x,y,z)$ where each $x,y,z\in \{1,2,\dots,n\}$ to itself. $$ \begin{align} x'&=\text{mod}(2(x-1),n)+1+\1[\text{mod}(z,4)= 2\text{ or }\text{mod}(z,4)=0] \\ y'&=\text{mod}(2(y-1),n)+1+\1[\text{mod}(z,4)= 3\text{ or }\text{mod}(z,4)=0] \\ z'&=\lceil z/4\rceil + (n/4)\Big(\1[n/2<x] + 2\cdot \1[n/2<y]\Big) \end{align} $$

Brief explanation:

The $\text{mod}(2(x-1),n)+1$ part simultaneously captures the $2x$ and $2x-1$ parts of the original, similarly for the $y$.

The original problem works for continuous space, where stretching and compressing is bijective. In the discrete space, when you stretch by a factor of $2$ you leave gaps, and when you compress you get collisions. We simultaneously fix both of these problems with the $\1[n/4< z\le n/2\;\;\text{ or }\;\;3n/4< z\le n]$ and $\1[n/2 <z \le n]$ parts. Essentially, when you try to compress the $z$ part by $4$, you need to instead divide the column into four parts and move some of these parts slightly out of the way.

The expression for $z$ just captures the $z'=z/4 +\{0,1/4,1/2\text{ or }3/4\}$ all in one go.