togFox wrote: ↑Wed Jul 21, 2021 4:55 am
The formula you see is the MS Excel trend line (ignore the error - I couldn't remove that one) but it really means nothing to me.
Why not?
Code: Select all
local function payout(x)
return -3e-6*x^4+0.0003*x^3+0.0107*x^2-0.0669*x+0.4196
end
print(payout(0)) -- 0.4196
print(payout(10)) -- 1.0906
print(payout(20)) -- 5.2816
print(payout(30)) -- 13.7126
print(payout(40)) -- 26.3836
print(payout(50)) -- 42.5746
print(payout(60)) -- 60.8456
print(payout(70)) -- 79.0366
print(payout(80)) -- 94.2676
print(payout(90)) -- 102.9386
print(payout(100)) -- 100.7296
The problem is that it's just an approximate fit of degree 4, so it's not exact; it goes over 100 at some points, but it's what can be done fitting the given points to a 4th degree polynomial. To exactly pass through all the points, you would need a polynomial of a bigger order, up to 10.
By relaxing the constraint that the curve must approximate the points but preserving your other constraints, a 4th degree curve will do.
To keep things simple, let's normalize to 0..1 and apply the factor of 100 later.
You want a polynomial for which:
1. y = 0 when x = 0
2. y = 1 when x = 1
3. y = 0.65 when x = 0.65
4. The derivative at 0 is 0 (so it starts horizontal)
5. The derivative at 1 is 0 (so it ends horizontal)
That's five constraints, meaning we need a quartic, because all constraints are independent. Two of the constraints give immediate values for the terms of degrees 0 and 1: they must both be zero because of constraints 1 and 4. So we're after a, b and c for this curve:
y = a*x^4+b*x^3+c*x^2
where:
a + b + c = 1 (per constraint 2)
a*0.17850625 + b*0.274625 + c*0.4225 = 0.65 (per constraint 3)
4*a + 3*b + 2*c = 0 (per constraint 5)
*fires Derive*
Solution: a = -120/91, b = 58/91, c = 153/91
So:
Code: Select all
local function payout(x)
return ((-120/91*x+58/91)*x+153/91)*x*x
end
print(payout(0/100)*100) -- 0
print(payout(10/100)*100) -- 1.7318681318681
print(payout(20/100)*100) -- 7.0241758241758
print(payout(30/100)*100) -- 15.784615384615
print(payout(40/100)*100) -- 27.604395604396
print(payout(50/100)*100) -- 41.758241758242
print(payout(60/100)*100) -- 57.204395604396
print(payout(65/100)*100) -- 65
print(payout(70/100)*100) -- 72.584615384615
print(payout(80/100)*100) -- 86.224175824176
print(payout(90/100)*100) -- 96.131868131868
print(payout(100/100)*100) -- 100
That's four multiplications, two sums... and zero trigonometric functions
Changing the threshold to 2/3 = 0.666666... instead of 0.65, the solution is even simpler: a = -1.5, b = 1, c = 1.5, which gives the following:
Code: Select all
local function payout(x)
return ((-1.5*x+1)*x+1.5)*x*x
end
print(payout(0/100)*100) -- 0
print(payout(10/100)*100) -- 1.585
print(payout(20/100)*100) -- 6.56
print(payout(30/100)*100) -- 14.985
print(payout(40/100)*100) -- 26.56
print(payout(50/100)*100) -- 40.625
print(payout(60/100)*100) -- 56.16
print(payout(66.6666/100)*100) -- 66.666562962941
print(payout(70/100)*100) -- 71.785
print(payout(80/100)*100) -- 85.76
print(payout(90/100)*100) -- 95.985
print(payout(100/100)*100) -- 100
Edit: Pics, or it didn't happen.