The method I'm currently using works just dandy but requires an upper bound of roughly 100-1000 elements in the series calculation to be approximately within 10 decimal places of accuracy. The question I have is would altering/changing the expression used for a converging series (i.e. rather than 2^k, say 10^k ?) give a "quicker" way of approaching the same output value but in shorter iterations and how?
The code in question:
def logN(val, base):
#logarithm of base 'N'
list_series = []
inc, integer, partial_sum = 0, 0, 0
bound = 1000
val = float(val)
while val >= base:
integer += 1
val /= base
partial = val
while inc < bound:
partial *= partial
if partial >= base:
list_series.append(1)
partial /= base
elif partial < base:
list_series.append(0)
inc += 1
for var in range(len(list_series)):
expr = ((list_series[var])/2.0)**(var+1)
partial_sum = expr + partial_sum
log_val = integer + partial_sum
return log_val

New Topic/Question
Reply




MultiQuote




|