Topic: function to compute number of turning points of a mathematical functio

this is my attempt but it's failing me sad

def turningpoints(u):
    '''Calculates the number of turning points of the wavefunction'''
    t1=0 #t1 keeps a running total of turning points
    for i in range(len(u)-1):
        if (u[i,1]<1e-1 and abs(u[i,1])<abs(u[i+1,1]) and abs(u[i,1])<abs(u[i-1,1])):
        t1+=1
        i+=1

u is a 2d array, one column is the values of the function and the second column (hence u[i,1]) is the values of the derivative. The array has been made using odeint in scipy.

I know mathematically a turning point is where the derivative is 0, but as it only looks at a certain number of points of the function it's very unlikely any values of the derivative in the array are exactly 0.

In this picture my code segment tells me the green line has 2 turning points rather than the correct one, I can't see why http://imgur.com/dYn5w

if anybody knows a solution any help would be greatly appreciated smile

Last edited by ThePianoDentist (January 13, 2012 14:31)

Thumbs up