Need workaround to treat float values as tuples when updating "list" of float values

174 views Asked by At

I am finding errors with the last line of the for loop where I am trying to update the curve value to a list containing the curve value iterations. I get errors like "can only concatenate tuple (not "float) to tuple" and "tuple object has no attribute 'append'". Does anyone know a way to do this? Thank you...

import matplotlib.pyplot as plt

thetaR = 0.078
thetaS = 0.43
alpha = 0.0036
psiRange = (range(0,1000))
#psi = 1
#psi = (0,1000)
n = 1.56
curveList = ()
for psi in psiRange:
    curve = (thetaR) + ((thetaS - thetaR)/((1 + (alpha*psi**n))**(1-1/n)))
    #curveList.append(curve)
    curveList += curve

plt.plot(curveList)
plt.axis(0,1,0,100)
plt.show()
1

There are 1 answers

2
xnx On BEST ANSWER

You can't append to a tuple at all (tuples are immutable), and extending to a list with + requires another list.

Make curveList a list by declaring it with:

curveList = []

and use:

curveList.append(curve)

to add an element to the end of it. Or (less good because of the intermediate list object created):

curveList += [curve]