While I was creating a basic for-loop in Python within a function in order to work with a dynamic variable length (z) I've just come across the following error:
Rs = []
z = []
N = 120
m = 1
for i in range(1, N):
Rs[i] = z[m]
m = m + 1
Rs[i] = z[m] IndexError: list index out of range
For the sake of clarity, I will explain better what I'm trying to do. I would like to solve an equation system which is composed by a dynamical number of unknowns. I've started to use the "static" method and It works perfectly. Basically, the code is more or less as follows:
from scipy.optimize import fsolve
def fixEqSyst(z):
v1 = z[0]
v2 = z[1]
v3 = z[2]
v4 = z[3]
f=np.zeros(4)
f[0] = 2*v1-3*v2+7*v3**2
f[1] = v1+3*v2**2-9*v3
f[2] = -3v1**2+12*v2+7*v3
f[3] = 4*v1+5*V2*v3
return f
z = fsolve(fixEqSyst, [0, 0, 0, 0])
Basing on the fact that now I will face with a dynamic number of unknowns and functions, is there any alternative solution than of what I've already put in place? (with a for-loop strategy)