0

Okay I basically want to solve a set of under-determined equations. I've around 289 variables and 288 equations.

I followed the following link to create my solver program to solver the under-determined equations.

Since I've 289 variables and nearly as many equations, manually writing the equations wasn't possible, I introduced a loop which saves equations and Sym variables in arrays and returns that which is passed to solve() function.

Code :

def getEqn(A, B):
    for i in range(len(A)):
        A[i] = Symbol('A['+str(i)+']')

    equations = [None]*(len(predictions)-1)
    for i in range(len(equations)-1):
        equations[i] = Eq(A[i]-A[i+1], B[i])

    return equations, A
def solver(predictions):
    lenPredictions = len(predictions)
    A = [None]*lenPredictions
    for i in range(lenPredictions):
        A[i] = Symbol('A['+str(i)+']')
    equations, variables = getEqn(A, predictions)
    for i in range(lenPredictions-1):
        res = solve(equations, variables)
    return res
def main():
    res = solver(predictions)

When I try running the following code, I get following error: enter image description here

Note : The whole program is running fine without any error. Its only these following functions which is throwing error. I'm completely new to Python & Sympy also. Any guidance would be really helpful as I'm unable to know where I'm missing something.

Community
  • 1
  • 1
Debasish Kanhar
  • 1,123
  • 2
  • 15
  • 27

1 Answers1

1

in getEqn() you have ...

equations = [None]*(len(predictions)-1)

and then ...

for i in range(len(equations)-1):
    equations[i] = Eq(A[i]-A[i+1], B[i])

That means your last equation won't be getting a value but will still be None, because of your -1 in the range.

I think you want ...

equations = [None]*(len(predictions))
for i in range(len(equations)):
jcfollower
  • 3,103
  • 19
  • 25
  • Thanks for the reply. Yes the issue was list index size and is resolved now. Bdw another doubt, Dont know if its in scope or not of the question, I realized sympy's solve function is slow and other alternative is sage's solver. Can anyone guide me with relevant links to use sage? – Debasish Kanhar Jul 31 '15 at 12:03