Post Reply 
New Sum of Powers Log Function
03-31-2021, 02:19 PM
Post: #14
RE: New Sum of Powers Log Function
Albert,

Going back to an earlier post in this thread. Here is my Python copy of your code that uses the findroot() function:

Code:
from mpmath import *
import numpy as np

def roughx(n,s):
    return findroot(lambda X: ((n + .5) ** X - 0.5 ** X) / (s * X) - 1, np.log(s)/np.log(n)) - 1

def RHS(p,n):
    return ((n+1)**(p+1)-1)/(p+1) - ((n+1)**p-1)/2 + p*((n+1)**(p-1)-1)/12

def solvex(n,s):
    return findroot(lambda p: RHS(p,n)/s-1, np.log(s)/np.log(n)-1)

n=100
SX = (100,0),(150,0.110121),(250,0.245589),(500,0.424944),(750,0.527995)
SX += (1000,0.600423),(1100,0.624305),(1200,0.646061),(1300,0.666037)
for s,x in SX: print('%g\t%f\t%f\t%f' % (s,x, solvex(n,s), roughx(n,s)))

The output is:

Code:
100    0.000000    0.000000    0.000000
150    0.110121    0.110121    0.110134
250    0.245589    0.245589    0.245605
500    0.424944    0.424944    0.424956
750    0.527995    0.527995    0.528004
1000    0.600423    0.600423    0.600430
1100    0.624305    0.624305    0.624311
1200    0.646061    0.646061    0.646067
1300    0.666037    0.666037    0.666042

Here is a Matlab script that implements the Matlab version of the above three Python functions:

Code:
clc
close
clear

n=100; s=1500;
fprintf("SopLog(%i,%i) = %f12\n", n, s, soplog(n,s));
fprintf("Solvex(%i,%i) = %f12\n", n, s, solvex(n,s));
fprintf("Roughx(%i,%i) = %f12\n", n, s, roughx(n,s));

n=100; s=5000;
fprintf("SopLog(%i,%i) = %f12\n", n, s, soplog(n,s));
fprintf("Solvex(%i,%i) = %f12\n", n, s, solvex(n,s));
fprintf("Roughx(%i,%i) = %f12\n", n, s, roughx(n,s));

n=1000; s=5000;
fprintf("SopLog(%i,%i) = %f12\n", n, s, soplog(n,s));
fprintf("Solvex(%i,%i) = %f12\n", n, s, solvex(n,s));
fprintf("Roughx(%i,%i) = %f12\n", n, s, roughx(n,s));

function x = roughx(n,s)
  x = fsolve(@(x) ((n + .5)^x - 0.5^x) / (s * x) - 1, log(s)/log(n)) - 1;
end

function x =RHS(p,n)
  x= ((n+1)^(p+1)-1)/(p+1) - ((n+1)^p-1)/2 + p*((n+1)^(p-1)-1)/12;
end

function x = solvex(n,s)
  x = fsolve(@(p) RHS(p,n)/s-1, log(s)/log(n)-1);
end

The output is:

Code:
SopLog(100,1500) = 0.70166112
Solvex(100,1500) = 0.70166112
Roughx(100,1500) = 0.70166612

SopLog(100,5000) = 0.99757912
Solvex(100,5000) = 0.99757912
Roughx(100,5000) = 0.99757912

SopLog(1000,5000) = 0.26718812
Solvex(1000,5000) = 0.26718812
Roughx(1000,5000) = 0.26718812

The arbitrarily selected values of N and S show that the Solvex() and Roughx() give the same digits. While both functions use Matlab's fsolve the do not require loops to perform any summation. Of course the same is true for the Python version.

The end of the study that I posted on my web site I discuss some variants of the SopLog function. These variants deal with scaling up/down the powers of the next integers, so the powers to which the integers are raise vary from term to term.

Another variation of the SopLog function is to specify the number of integers AND the integer-increment for the next term. And of course you can combine this variant with the scaled up/down powers.

Namir
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 - Namir - 04-04-2021, 03:41 PM



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