python - Range Function For Floats In Small Intervals -


i want find derivative of function (x)(x - 1) using definition of derivative. want increments 1e-2. simulates limit going zero. saw on range floats use user-defined functions create range functions take float variables.

def frange(x, y, jump):     while x < y:         yield x         x += jump      def drange(start, stop, step):      r = start      while r < stop:         yield r         r += step  = frange(1e-14,1e-2,2)  k in i:     set  = []     x = 1     dvt = ((x + k ) * (x + k - 1) - x*(x - 1))/k      set.append(dvt)     print(set) 

when run program

[0.9992007221626509] 

what going on not getting more 1 derivative added list?

set saying

x += jump 

this sets value of x 2 + 1e-14 greater 1e-2

as read code, seems may mean

myjump = pow(10, jump) #outside loop  x *= myjump # inside loop 

this multiply each loop through 100 in example , process 1e-14, 1e-12, 1e-10 ... 1e-2

alternatively, if meant add it, should have said

x += myjump # inside loop 

or need test jump fraction small enough processed.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -