Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

An recursive algorithm would be quite inefficient for this problem as yout would have to recalculate all c_k coefficients in each step.

The following few lines should work for your problem (if I hopefully didn't make any mistakes with the formulas):

def c(k,A):
    c_arr=[-A.trace()]
    for j in range(k-1):
        c_arr=c_incr(c_arr,A)
        print c_arr
    return c_arr[k-1]

def c_incr(c_arr, A):
    k=len(c_arr)+1
    c_new=(A^k).trace()
    for c_k in c_arr:
        k-=1
        c_new+=c_k*(A^k).trace()
    c_new=-1/(len(c_arr)+1)*c_new
    c_arr.append(c_new)
    return c_arr