Matrix entries using a single function

36 Views Asked by At

Is it possible to write the following matrix as a single function, without any explicit if condition mathematically?

For, $$1 \leq i,j\leq n,$$ $$A(i,j)=\begin{cases} 2 ~~\text{if}~~ i \neq j \\ 1 ~~\text{if}~~i=j \end{cases} $$

Mathematically it should be written as $$A(i,j) = f(i,j)$$

It can be combination of minimum, maximum, floor, ceil, trigonometric functions.

2

There are 2 best solutions below

0
On BEST ANSWER

Without trigonometric functions: $$ A(i,j)=1+\frac{|i-j|}{\max(1,|i-j|)}. $$ Since the absolute value is not among the allowed functions, you can replace $|i-j|$ by $$ |i-j|=\max(i-j,j-i), $$ so $$ A(i,j)=1+\frac{\max(i-j,j-i)}{\max(1,i-j,j-i)}. $$

0
On

As $0$ is the only integer that is a "multiple" of $\pi$, this should work. $$ A(i,j)=2-\lfloor|\cos(i-j)|\rfloor $$

If the absolute value is not allowed: $$ 2-\lfloor\max(0,\cos(i-j))\rfloor $$ should work.