Searching for formula: equals zero, if all variables are the same

44 Views Asked by At

I need a formula for an optimization problem. given e.g. the variables x y z. I need a formula which return "0" (zero) if all variables are exactly the same. E.g. x=5, y=5, z=5. Might be quiet simply. I don´t know... Thx in advance...

3

There are 3 best solutions below

0
On BEST ANSWER

How about $x^2+y^2+z^2-xy-yz-zx$? This is a scaled version of $(x-y)^2+(y-z)^2+(z-x)^2$ which is zero iff $x=y=z$.

1
On

If you have variables $x_1,\ldots,x_n$, you can take $$\sum_{i<j}(x_i-x_j)^2.$$ Notice that all terms are $\ge0$, and they are all zero if and only if all variables are equal.

0
On

Or $(x-y)^2 + (y-z)^2$ suffices since $x=y \space \& \space y=z \space \Rightarrow \space x=z$.