Post Reply 
New Sum of Powers Log Function
04-02-2021, 01:29 AM (This post was last modified: 04-02-2021 10:27 AM by Albert Chan.)
Post: #21
RE: New Sum of Powers Log Function
(04-01-2021 11:55 PM)Namir Wrote:  I am looking to solve for x given all other parameters--n, s, scale.

I guess the only sure way is to actually do the sum.
Because of the power-law nature of functions, we should use log scale, like before.

I have no idea what should be the right guess for it, so I just start with g=1.
Note that guess is evaluated twice. This is a fluke of mpmath, to simplify code.
The branched solver(s) re-calculated from the same guess again.

Code:
from mpmath import *
def show(x): print float(x); return x

nbx_to_s = lambda n,b,x: 1+fsum(k**(x*b**(n-k)) for k in xrange(2,n+1))
nbs_to_x = lambda n,b,s,g=1.: findroot(lambda x: log(nbx_to_s(n,b,show(x))/s), g, tol=1e-4)

>>> n, b = 100, 0.8
>>> s = nbx_to_s(n, b, 1.6) # = 2238.0808062735837
>>> x = nbs_to_x(n, b, s)
1.0
1.0
1.25
1.69268857579
1.59352468855
1.5999199506
1.60000007609
1.6

>>> s = nbx_to_s(n, b, 16) # = 1.0000003500527855e+32
>>> x = nbs_to_x(n, b, s)
1.0
1.0
1.25
23.7615084486
15.9522719123
15.999999997
16.0
16.0
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
New Sum of Powers Log Function - Namir - 03-29-2021, 04:53 PM
RE: New Sum of Powers Log Function - C.Ret - 03-29-2021, 08:39 PM
RE: New Sum of Powers Log Function - Namir - 03-30-2021, 11:05 AM
RE: New Sum of Powers Log Function - Gene - 03-30-2021, 01:43 PM
RE: New Sum of Powers Log Function - C.Ret - 03-30-2021, 04:01 PM
RE: New Sum of Powers Log Function - Namir - 03-30-2021, 05:56 PM
RE: New Sum of Powers Log Function - Namir - 03-31-2021, 01:27 PM
RE: New Sum of Powers Log Function - Namir - 03-31-2021, 02:19 PM
RE: New Sum of Powers Log Function - Namir - 04-01-2021, 06:05 PM
RE: New Sum of Powers Log Function - Namir - 04-01-2021, 11:55 PM
RE: New Sum of Powers Log Function - Albert Chan - 04-02-2021 01:29 AM
RE: New Sum of Powers Log Function - Namir - 04-04-2021, 03:41 PM



User(s) browsing this thread: 1 Guest(s)