Hi
I am a novice python coder and I would like to hear your opinions and suggestions about my function.
# Preset data list
afp = [0.0, 0.0, 45.0, -0.5, 65.0, -0.1, 70.0, -0.6, 90.0, 0.1, 105.0, 0.9, 110.0, 0.12, 135.0, 0.6, 180.0, 0.0]
def i_c(val,d, ia = 0.0): # linear interpolation for the Cl values. Max 9 sets/pairs.
vali = val + ia # add a incident of attack to the val value if needed
if vali <= d[2]: # a normal opeation range
return d[1] + ((vali - d[0])*(d[3]-d[1])) / (d[2]-d[0])
if (vali > d[2]) is True and (vali <= d[4]) is True:
return d[3] + ((vali - d[2])*(d[5]-d[3])) / (d[4]-d[2])
if (vali > d[4]) is True and (vali <= d[6]) is True:
return d[5] + ((vali - d[4])*(d[7]-d[5])) / (d[6]-d[4])
if (vali > d[6]) is True and (vali <= d[8]) is True:
return d[7] + ((vali - d[6])*(d[9]-d[7])) / (d[8]-d[6])
if (vali > d[8]) is True and (vali <= d[10]) is True:
return d[9] + ((vali - d[8])*(d[11]-d[9])) / (d[10]-d[8])
if (vali > d[10]) is True and (vali <= d[12]) is True:
return d[11] + ((vali - d[10])*(d[13]-d[11])) / (d[12]-d[10])
if (vali > d[12]) is True and (vali <= d[14]) is True:
return d[13] + ((vali - d[12])*(d[15]-d[13])) / (d[14]-d[12])
if (vali > d[14]) is True and (vali <= d[16]) is True:
return d[15] + ((vali - d[14])*(d[17]-d[15])) / (d[16]-d[14])
if (vali > d[16]) is True and (vali <= d[18]) is True:
return d[17] + ((vali - d[16])*(d[19]-d[17])) / (d[18]-d[16])
aoa = -1.9 # angle of attack in degrees
aoa = aoa + 90.0
print i_c(aoa, afp)
The function is interpolating the coefficient of lift (cl) value, based to the given angle of attack (aoa) degree value.
The afp-list contains a nine key figure pairs (aoa, cl).
The function is searching through the afp-list aoa values with ‘if’ to find a right aoa key figure and then interpolate the cl-value.
How I can improve the code speed? The nominal aoa-range is 0-10 degrees.
Thanks