2

Given two real numbers $x$ and $y$ (with $x, y \neq 0$), is there a function that returns only the result of the divisions $x/y$ and $y/x$ which is $\geq 1$?

$$f(x, y) = x/y \geq 1 \text{ if } x \geq y$$ and $$f(x, y) = y/x \geq 1 \text{ if } y \geq x$$

A practical application of this could be to calculate the voltage standing wave ratio VSWR from two impedances $Z_1$ and $Z_2$: the VSWR is always $\geq 1$, and is just the ratio of the larger to the smaller impedance.

What I am looking for is in effect the multiplication equivalent of the absolute function, which returns values $\geq 0$ for subtractions. It sounds to me like that probably exists, but I couldn't find it anywhere.

DK2AX
  • 135
  • 1
    Can $x$ or $y$ be negative? If not, I would probably write $\max{x/y,y/x}$. Of course it is known how to write $\max$ in terms of absolute value, but why would you do that? Isn't the "max" formulation easier, and doesn't it exist in almost all computer languages? – GEdgar Oct 25 '18 at 14:29
  • @GEdgar Good point! I was actually only thinking of positive numbers, but it should also work for negative real numbers. In that case the condition should be $|f(x, y)| \geq 1$. – DK2AX Oct 25 '18 at 14:33
  • @GEdgar Sure it is easier. I was just curious if another function exists that directly takes $x$ and $y$ and returns a value in the same way as $\max(x/y, y/x)$. – DK2AX Oct 25 '18 at 14:41

2 Answers2

2

You can define such a function $f:\mathbb{R}^2\backslash(0,0)\rightarrow \mathbb{R}$ using the Heaviside function

$$f(x,y)=\frac{x}{y}\cdot H\left(\frac{x}{y}-1\right)+\frac{y}{x}\cdot H\left(\frac{y}{x}-1\right).$$

A problem occurs here if $y=x$, in which case you want $f(x,x)=1$. If you choose to use the Heaviside function which is such that $\displaystyle H(0)=\frac12$ this problem is sorted.

JP McCarthy
  • 8,420
2

If you do not want to use heaviside or piecewise functions, you could alternatively use

$$\left(\frac{x}{y}\right)^{\dfrac{x-y}{\sqrt{(x-y)^2}}}$$

However, this also runs into problems if $x=y$.

Blavius
  • 246