ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 14 Mar 2018 02:12:23 +0100local variable 'Integer' referenced before assignmenthttps://ask.sagemath.org/question/41524/local-variable-integer-referenced-before-assignment/ I'll be honest I have no idea why this error is popping up, and it's really weird! I'm writing code that will generate a closed form solution to the partial sums of integer powers up to n, and this is what I have
def sum_first_n_p_powers(p):
length = p+1
vector = zero_vector(length)
matrix_list = []
for x in xrange(0,length):
copy = vector[:]
for y in xrange(0,length):
copy[y] = binomial(length-y,x-y+1)
matrix_list.append(copy)
M = Matrix(matrix_list)
solution_vector = zero_vector(length)
solution_vector[0] = 1
coeffs = M.solve_right(solution_vector)
n = var('n')
0 = polynomial
for x in xrange(0,len(coeffs)):
polynomial = polynomial + coeffs[x]*n^(length-x)
return polynomial
And when I try to run it I get the most unusual error, it just says to me
UnboundLocalError: local variable 'Integer' referenced before assignment.
I have never run into this before and have no idea what's wrong with the line. Thanks in advance!
JRHalesWed, 14 Mar 2018 02:12:23 +0100https://ask.sagemath.org/question/41524/