0

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
tsull
  • 1
  • 2

1 Answers1

0

You said y[i]:

        temp = temp[i] + (y - y[i])*(temp[i+1]-temp[i])/(alt[i+1] - alt[i])

but I think you meant alt[i]:

        temp = temp[i] + (y - alt[i])*(temp[i+1]-temp[i])/(alt[i+1] - alt[i])
rob mayoff
  • 375,296
  • 67
  • 796
  • 848