BigBadMe
BigBadMe

Reputation: 1842

Curve fitting between two numbers

I was wondering if someone could tell me how to curve fit between two values with the curve being that of x^3 where 0> x <1 so that the values of y increase gradually and then increase exponentially as approaching 1.

For example, I have a low figure of 100 and high figure of 1000, I would like to map this to a curve of x^3, and be able to select 6 values equally spaced: [100, y1, y2, y3, y4, 1000]

Thanks in advance.

Upvotes: 0

Views: 147

Answers (1)

dspr
dspr

Reputation: 2423

Do you mean something like this ?

def curved(n, start, rnge, exp):
   r = ((n - start) / rnge) ** exp
   return start + r * rnge

for n in [100, 280, 460, 640, 820, 1000]:
  print(curved(n, 100, 900, 3)) #=> 100.0, 107.2, 157.6, 294.4, 560.8, 1000.0

Upvotes: 1

Related Questions