I'm trying to find a method to turn a value (that can reach a maximum of N) into a percentage. But I don't want it to be linear, I need it to be non-linear like the in this graph:
Asked
Active
Viewed 45 times
0
-
Do you really mean logarithmic or do you just mean nonlinear? – Amaan M Feb 20 '21 at 21:09
-
Oh sorry I meant non-linear. – HDNW Feb 20 '21 at 21:10
-
There are a lot of options, depending on how you want the curve to be shaped. If you're fine with a quadratic, something like $y = 100-\frac{100}{N^2}(x-N)^2$ would work. See this graph. – Amaan M Feb 20 '21 at 21:14
-
Thanks that was quick :) . It's for a programming method so the best is the one that requires least amount of calculations – HDNW Feb 20 '21 at 21:19
-
Could also go with $y = 100\sqrt{\frac{x}{N}}$, here's a graph of that. Fewer calculations, curvature's a bit different. – Amaan M Feb 20 '21 at 21:23
-
I was specifically looking for a method that's the most linear in the early part of the graph, so I think the first one is best – HDNW Feb 20 '21 at 21:26
-
Actually no I think the second one works best. Thanks :) – HDNW Feb 20 '21 at 21:28
-
You're welcome! – Amaan M Feb 20 '21 at 21:28
2 Answers
1
Generally, any function that fits the following qualifications will be somewhat similar to the graph:
- Increasing from $x = 0$ to $x = N$
- Concave from $x = 0$ to $x = N$
- $f(0) = 0$ and $f(N) = 100$
To keep things simple, we can use a function that is twice-differentiable. Then, we need $f'(x) > 0$ for $x\in (0,N)$, and $f''(x) < 0$ for $x\in (0,N)$.
There are a lot of options out there for functions that fit these requirements, but two easy ones to implement are
- $f(x) = 100-\frac{100}{N^2}(x-N)^2$
- $f(x) = 100\sqrt{\frac{x}{N}}$
Amaan M
- 2,790
-
@OP The gamma correction for color adjustment is a typical non linear function, i.e. $\left(\frac xN\right)^\gamma$. Here we just flip it and scale it so that $f(0)=0$ and $f(N)=100$, so it become $100\left(1-\big(1-\frac xN\big)^\gamma\right)$. https://www.desmos.com/calculator/787gqjm0ov – zwim Feb 20 '21 at 21:43
0
Set $$f(x)=\frac{200 x}{N}-\frac{100 x^2}{N^2}$$ where $N$ is the maximum $x$ value.
For instance, if you want $N=150$ you set $$f(x)=\frac{4 x}{3}-\frac{x^2}{225}$$ and get a curve like the following
Raffaele
- 26,371
