tags:

views:

258

answers:

4

I am looking for a way to convert any number to a percentage in the following way:

  1. 1.00 is 50%
  2. numbers below 1.00 approach 0% logarithmically
  3. numbers above 1.00 approach 100% logarithmically.

    x > 0. So y needs to approach 0 as x becomes infinitely small on the positive side.

I'm sure this is simple to do, but I can't recall how to do it.

+12  A: 

try 1 / (1 + e^(1-x))

it's the logistic function shifted by 1 unit

graph

If you want it to approach faster, you can change e to something higher

Edit:

to have f(0) = 0 you could use 1 - 2^(-x)

graph

cobbal
+1 for providing a graph
mizipzor
Oops -one important point I missed: x > 0.So y needs to approach 0 as x becomes infinitely small on the positive side.
Brent
Well, given that we've misunderstood you, can you draw a graph of what you want and add it to the question?
Jed Smith
Yes, I will add a graph
Brent
@cobbal: what software are you using? neat graphs!
Jason S
default Grapher.app that comes with Mac OS X
cobbal
+2  A: 

how about y = f(t) = 1 - exp(-t/tau) ?

For t near 0, y is approximately t/tau. For t approaching infinity, y asymptotically approaches 1.

As for the f(1)=0.5 approach, this can be used to solve for tau = 1/log(2).

Jason S
+3  A: 

When you say logarithmically, do you mean asymptotically? If so, then "y needs to approach 0 as x becomes infinitely small on the positive side" just means f(0)=0 if f is continuous. In that case x/(x+1) will work: http://www.wolframalpha.com/input/?i=x%2F%28x%2B1%29

Stanislav
assuming the desired behavior for y=f(x) is (a) f(0)=0, (b) f(1)=0.5, and (c) lim x->infinity f(x) = 1, I nominate this answer as the best simple answer. I was trying to think of a function involving just add/subtract/multiply/divide that would work but had a brain cramp.
Jason S
+2  A: 

From what you're describing, I'm hearing the graph of x cubed -- very basic, and should be efficient in most languages.

Graph

This was graphed with y=(x-1)^3+1 (transforms to make (1,1) the origin). You can, of course, make the results a percentage by simply scaling by 50.

You are, ultimately, trying to have an efficient solution to give you a rough percentage behavior in a programming language and not Mathematica, right?

Jed Smith
This is what I was looking for. Thank you!
Brent
@Brent: this makes no sense. please reword your question to accurately say what it is you want. The above graph approaches 1 at x=1. You mention in your question you want y to approach 1 as x approaches infinity, and you want y = 0.5 when x = 1.
Jason S
Actually, you are right I spoke too soon. This was not what I was looking for, since Y gets greater than 100
Brent
@Jason: No, he said he wanted a percentage. I'm giving him the curve, it's up to him what units he wants it in. The formula that yields the curve is just that, a formula that yields a curve. He'll have to scale the results, move the origin, etc -- and these are all algebraic transforms. The input does not have to exactly match the desired output in this case -- he's programming (at least I gathered so from "algorithmically"), not handing in a proof. I got him started, that's all.
Jed Smith
@Brent: What the heck do you mean `y` gets greater than 100? I've given you a curve, it's up to you to scale and manipulate to your desired results. You have not expressed your ranges nor constraints in any sensible fashion, and we're working with the data we are given. Scale the expression and **don't** try to copy and paste it without working with it. I gave you a curve, not a solution.
Jed Smith
@Jed: the "this makes no sense" was referring to Brent's comment, not your answer. Didn't mean to criticize your answer.
Jason S
@Jason: Didn't think you were, just getting frustrated because I don't think OP is sure what he's doing and we're all wasting time.
Jed Smith