i'm trying to make an interpolation code that returns the temperature at a given height
def Fdrag(y):
alt = [a1, a2, a3,....,an]
temp = [t1, t2, t3,...., tn]
for i in range(len(alt)):
if alt[i] < y < alt[i+1]:
temp = temp[i] + (y - y[i])*(temp[i+1]-temp[i])/(alt[i+1] - alt[i])
return temp
i keep getting this error:
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
Fdrag(10)
File "C:/Users//Desktop/interp_test.py", line 6, in Fdrag
temp = temp[i] + (y - y[i])*(temp[i+1]-temp[i])/(alt[i+1] - alt[i])
TypeError: 'int' object is not subscriptable
See Question&Answers more detail:os