1

I'm looking for a function that depends on B, C values. B is a real value, C is a % from 0 to 100.

I need the C value to apply a % if B is positive so A= $ B . \frac{C}{100}$ . If B=100 and C=99% -> A = 99 ... If B=100 and C=0% -> A = 0


The thing is that I need the function to also make C apply a % reduction if B is negative.

For example, if B=-100 and C=99% I get A= -99 ... but I need C to apply a 99% reduction so the result is A = -1.


The closest function I came up with (I confess I'm no expert) is A= $ \frac{|B| + B}{2} - B (1-\frac{C}{100}$). But the signs don't match at the end.

Does a function that meets those two conditions exist? Or I will need to separate it in B≥0 and B<0?

1 Answers1

1

A possible function that meets your requirements should be the following $$ A = \frac{|B|-B}{2|B|}\cdot \left(-B\cdot \left(1-\frac{C}{100}\right)\right) + \frac{|B|+B}{2|B|}\cdot \left(B\cdot \frac{C}{100}\right), $$ because if $B$ is negative, then $(|B|-B)/(2|B|) = 1$ and $(|B|+B)/(2|B|) = 0$ and if $B$ is positive it is the other way around.

Alternatively, with the indicator function you have exactly this separation into B positive and B negative in mathematical notation.

Nils
  • 106
  • Thank you for the quick answer! One little question Nils, I'm curious, you can create these type of complex functions with a pen and paper or do programs that could help us exist? Thanks again! – carlosbapt7 Mar 02 '22 at 09:19
  • I don't know of any program at the moment. But I could imagine that there is something like that (maybe Mathematica?). However, one would have to learn the syntax first and this I have as quite difficult in memory. Here your approach has brought me quite quickly on the idea. – Nils Mar 02 '22 at 09:32
  • +1 What is beautiful about this answer is the general principle: if you want a function $f$ that looks like function $g$ in case I and like function $h$ in case II you just invent a function $m$ that is 1 in case I and 0 in case II and a different function $n$ that is 0 in case I and 1 in case II and you take $f = mg + nh$. This idea is useful in a LOT of other situations as well! (BTW: in other situations you could simplify a bit further by taking $n = 1 - m$, but in this particular case I like the choice of $n$ in the answer better) – Vincent Mar 02 '22 at 10:19