Nov-21-2022, 05:17 PM
(This post was last modified: Nov-21-2022, 05:22 PM by Yoriz.
Edit Reason: Error code tags
)
Hi,
This is for a class project. The course is not a coding course, but we do use code to complete homework and projects (yes, it is as confusing as it sounds). Because of this, we are allowed to ask for outside help.
I am receiving an IndexError with the following code. I cannot figure out why the for loop is breaking. I've tried debugging multiple times but still cannot find which scalar variable the code is upset about. I call a function "values" within it - I do not believe that code is necessary for fixing this error.
I am trying to optimize "values" using the following arrays. Suggestions for a more efficient way of optimization would be helpful!
This is for a class project. The course is not a coding course, but we do use code to complete homework and projects (yes, it is as confusing as it sounds). Because of this, we are allowed to ask for outside help.
I am receiving an IndexError with the following code. I cannot figure out why the for loop is breaking. I've tried debugging multiple times but still cannot find which scalar variable the code is upset about. I call a function "values" within it - I do not believe that code is necessary for fixing this error.
I am trying to optimize "values" using the following arrays. Suggestions for a more efficient way of optimization would be helpful!
iteration = 40 Ltotal = np.linspace(1,20000,iteration) #m m = np.linspace(1,40,iteration) #number of passes ktube = np.array([400,48,160,16]) #copper,mild steel, aluminum, stainless steel Cptube = np.array([376.8,510.8,921.1,460.5]) ptube = np.array([894,785,270,800] ) tfin = np.linspace(0.1/1000,1/1000,iteration) #m tspace = np.linspace(1/1000,1/100,iteration) #m ODtube = np.linspace(0.0001,1,iteration) #m unitcost = np.array([7.50,0.34,1.87,1.98]) #$/kg for j in range(len(ktube)): for i in range(iteration): Qtotal,effectiveness,U,Ltotal,Twaterout,Tairout,cost = values(Ltotal[i],m[i],ktube[j],Cptube[j],ptube[j],tfin[i],tspace[i],ODtube[i],unitcost[j]) if 82000<=Qtotal<=87000: if j == 0: print('copper,Q = {}'.format(Qtotal)) if j==1: print('mild steel, Q = {}'.format(Qtotal)) if j==2: print('aluminum, Q = '.format(Qtotal)) else: print('stainless steel, Q = {}'.format(Qtotal)) else: print('option {} doesnt work Q = {}'.format(i,Qtotal)) i+=1Here is the error:
Error: Qtotal,effectiveness,U,Ltotal,Twaterout,Tairout,cost = values(Ltotal[i],m[i],ktube[j],Cptube[j],ptube[j],tfin[i],tspace[i],ODtube[i],unitc2\designreport2.py", line 179, in <module>ost[j]) l[i],m[i],ktube[j],Cptube[j],ptube[j],tfin[i],tspace[i],ODtube[i],unitcost[j])
IndexError: invalid index to scalar variable.