# Function of a curve from a graph

**URL:** <https://boards.straightdope.com/t/function-of-a-curve-from-a-graph/490564>\
**Category:** Factual Questions\
**Created:** [March 24, 2009, 8:44am UTC](https://boards.straightdope.com/t/function-of-a-curve-from-a-graph/490564 "2009-03-24T08:44:15Z")\
**Posts on this page:** 13\
**Page:** 2

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [April 5, 2009, 2:42pm UTC](https://boards.straightdope.com/t/function-of-a-curve-from-a-graph/490564/21 "2009-04-05T14:42:12Z")

</div>

> [@zut](#):
>
> Be aware, though, thet the tails on a bell curve are infinitely long, so you’ll have to chop off things less than 0 and greater than 100.

As long as your standard deviation is small relative to 50, this will never be an issue.

---

<div class="post-metadata">

**Author:** ![zut](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/zut/32/2875_2.png) [@zut](https://boards.straightdope.com/u/zut)\
**Post date:** [April 5, 2009, 3:21pm UTC](https://boards.straightdope.com/t/function-of-a-curve-from-a-graph/490564/22 "2009-04-05T15:21:19Z")

</div>

I’m assuming **CC** wants to construct a function that has some reasonable chance of returning results in the 1-10 range; if that’s the case, then he’s likely to get results below zero, also. If he just wants to focus on a tight range around, sy, 50, then agreed.

---

<div class="post-metadata">

**Author:** ![Crowbar\_of\_Irony\_3](https://avatars.discourse-cdn.com/v4/letter/c/f08c70/32.png) [@Crowbar\_of\_Irony\_3](https://boards.straightdope.com/u/Crowbar_of_Irony_3)\
**Post date:** [April 5, 2009, 4:04pm UTC](https://boards.straightdope.com/t/function-of-a-curve-from-a-graph/490564/23 "2009-04-05T16:04:57Z")

</div>

> [@zut](#):
>
> Excel has an actual normal distribution curve you could use. From [here](http://www.exceluser.com/explore/statsnormal.htm), you can use
> 
> =NORMINV(RAND(), mean, standard\_dev)
> 
> with a mean of 50 and a standard deviation of whatever you feel is appropriate. Be aware, though, thet the tails on a bell curve are infinitely long, so you’ll have to chop off things less than 0 and greater than 100. ETA: I doubt the imprecision discussed on that page concerns you.)
> 
> If you want something quick and dirtyto increase probability in one area, just create a random number from, sat, 0 to 110 and remap the numbers 100-110 to the range 40-50 with an IF statement (i.e., IF(A1\>100,A1-60,A1))

Thanks for the tip-off on Excel.

What if I need to code in C# or say, another language?

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [April 5, 2009, 5:51pm UTC](https://boards.straightdope.com/t/function-of-a-curve-from-a-graph/490564/24 "2009-04-05T17:51:47Z")

</div>

> [@CrazyChop](#):
>
> Thanks for the tip-off on Excel.
> 
> What if I need to code in C# or say, another language?

Find somebody else’s code and use it. Numerical programming is hard even for people who know the math underlying a given problem. If you have the capability to link against C++ libraries or make calls into a .dll, you should use [the Boost libraries](http://www.boost.org/).

---

<div class="post-metadata">

**Author:** ![Crowbar\_of\_Irony\_3](https://avatars.discourse-cdn.com/v4/letter/c/f08c70/32.png) [@Crowbar\_of\_Irony\_3](https://boards.straightdope.com/u/Crowbar_of_Irony_3)\
**Post date:** [April 7, 2009, 5:38pm UTC](https://boards.straightdope.com/t/function-of-a-curve-from-a-graph/490564/25 "2009-04-07T17:38:04Z")

</div>

Sorry to come back with another question on diminishing/increasing return. Let suppose I have a range of values x0 to x1, and y0 to y1, and I want a function such that

f(x0) = y0 and f(x1) = y1, but everything else in between is on a diminishing/increasing curve. Is there anyway to do that?

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [April 7, 2009, 8:49pm UTC](https://boards.straightdope.com/t/function-of-a-curve-from-a-graph/490564/26 "2009-04-07T20:49:20Z")

</div>

> [@CrazyChop](#):
>
> Sorry to come back with another question on diminishing/increasing return. Let suppose I have a range of values x0 to x1, and y0 to y1, and I want a function such that
> 
> f(x0) = y0 and f(x1) = y1, but everything else in between is on a diminishing/increasing curve. Is there anyway to do that?

f(x) = a\*log(x) + b should work.

---

<div class="post-metadata">

**Author:** ![Crowbar\_of\_Irony\_3](https://avatars.discourse-cdn.com/v4/letter/c/f08c70/32.png) [@Crowbar\_of\_Irony\_3](https://boards.straightdope.com/u/Crowbar_of_Irony_3)\
**Post date:** [April 8, 2009, 1:39am UTC](https://boards.straightdope.com/t/function-of-a-curve-from-a-graph/490564/27 "2009-04-08T01:39:02Z")

</div>

> [@ultrafilter](#):
>
> f(x) = a\*log(x) + b should work.

Thanks once more. Is it possible to specify the steepness of the curve?

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [April 8, 2009, 1:48am UTC](https://boards.straightdope.com/t/function-of-a-curve-from-a-graph/490564/28 "2009-04-08T01:48:11Z")

</div>

> [@CrazyChop](#):
>
> Thanks once more. Is it possible to specify the steepness of the curve?

You need the function to satisfy y0 = a_log(x0) + b and y1 = a_log(x1) + b, so other than picking those two points, no, you don’t have any additional control. You could use square roots in place of logs if that works better for you.

---

<div class="post-metadata">

**Author:** ![Crowbar\_of\_Irony\_3](https://avatars.discourse-cdn.com/v4/letter/c/f08c70/32.png) [@Crowbar\_of\_Irony\_3](https://boards.straightdope.com/u/Crowbar_of_Irony_3)\
**Post date:** [April 8, 2009, 2:29am UTC](https://boards.straightdope.com/t/function-of-a-curve-from-a-graph/490564/29 "2009-04-08T02:29:49Z")

</div>

Thanks for the explanation, wish I see the use of those log() and expo() functions back when I studying them during school.

---

<div class="post-metadata">

**Author:** ![Crowbar\_of\_Irony\_3](https://avatars.discourse-cdn.com/v4/letter/c/f08c70/32.png) [@Crowbar\_of\_Irony\_3](https://boards.straightdope.com/u/Crowbar_of_Irony_3)\
**Post date:** [April 8, 2009, 3:56am UTC](https://boards.straightdope.com/t/function-of-a-curve-from-a-graph/490564/30 "2009-04-08T03:56:23Z")

</div>

> [@Bolt\_the\_Nut](#):
>
> It sounds like a power or exponential function is what you need. Try fitting those to your data in Excel. In case you are interested, both of the following functions will fit the two data points you mentioned, and give you an increasing slope (i.e. an upward curving line):
> 
> y = 0.4765 \* x + 1.3219  
> y = 4 \* e^(0.0916 \* x)
> 
> where, in both cases, y = effect and x = skill value
> 
> Happy gaming! 🙂

If I am looking for a diminishing return graph, how would I change the formula?

---

<div class="post-metadata">

**Author:** ![Crowbar\_of\_Irony\_3](https://avatars.discourse-cdn.com/v4/letter/c/f08c70/32.png) [@Crowbar\_of\_Irony\_3](https://boards.straightdope.com/u/Crowbar_of_Irony_3)\
**Post date:** [April 8, 2009, 4:14am UTC](https://boards.straightdope.com/t/function-of-a-curve-from-a-graph/490564/31 "2009-04-08T04:14:58Z")

</div>

> [@zut](#):
>
> Often, I think, the simplest function would be the easiest to use.
> 
> For example, try this:
> 
> y = A + B\*x^C
> 
> Where A would be the base effect (which might often be zero), B is the scaling, and C is the shape of the curve. C between 0 and 1 will give you diminishing returns, C = 1 is a linear function, and C over 1 will give increasing returns. Tweak C one way or another until the curve looks right to you.

I have tried this out and it works great, just one issue - it doesn’t work for negative numbers (I think x^C when x \< 0 triggers an overflow and it becomes a massive negative number)

---

<div class="post-metadata">

**Author:** ![Indistinguishable](https://avatars.discourse-cdn.com/v4/letter/i/90ced4/32.png) [@Indistinguishable](https://boards.straightdope.com/u/Indistinguishable)\
**Post date:** [April 8, 2009, 4:26am UTC](https://boards.straightdope.com/t/function-of-a-curve-from-a-graph/490564/32 "2009-04-08T04:26:57Z")

</div>

The problem is that, e.g., x^(0.5) can’t be a real number when x \< 0 (since it’s the square root of a negative number).

---

<div class="post-metadata">

**Author:** ![zut](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/zut/32/2875_2.png) [@zut](https://boards.straightdope.com/u/zut)\
**Post date:** [April 8, 2009, 3:30pm UTC](https://boards.straightdope.com/t/function-of-a-curve-from-a-graph/490564/33 "2009-04-08T15:30:50Z")

</div>

> [@CrazyChop](#):
>
> I have tried this out and it works great, just one issue - it doesn’t work for negative numbers (I think x^C when x \< 0 triggers an overflow and it becomes a massive negative number)

Oh. Didn’t realize you needed to handle negative numbers (I was thinking you were starting with “skill values” which would always be positive). You can always add an offset:

y = A + B\*(x+D)^C

where D would be the absolute value of your most negative “x”.

[Previous page](https://boards.straightdope.com/t/function-of-a-curve-from-a-graph/490564.md?page=1)
