У меня есть этот код, который должен быть построен отлично. Я новичок в python. Ошибка указана выше. Любая помощь будет оценена по достоинству.Локальная переменная, на которую ссылаются перед присваиванием ошибки python
#Variable Initialization
#%pylab inline
# (a) Curie Temperature for h = 15 W/m^2
# (b) Value of h for cure temp = 50 deg C
import math
import numpy
from numpy import roots
import matplotlib
from matplotlib import pyplot
Tsurr = 30+273; #[K] - Temperature of surrounding
Tf = 20+273; #[K] - Temperature of Fluid Flow
e=.5; # Emissivity of Surface
a = .8; # Absorptivity of Surface
G = 2000; #[W/m^2] - Irradiation falling on surface
h=15; #[W/m^2.k] - Thermal Convectivity from plate to air
stfncnstt=5.67*math.pow(10,(-8)); # [W/m^2.K^4] - Stefan Boltzmann Constant
T=375; #[K] Value initially assumed for trial-error approach
#Using Eq 1.3a & 1.7 and trial-and error approach of Newton Raphson
#calculations and results
while(1>0):
f=((a*G)-(h*(T-Tf)+e*stfncnstt*(T*T*T*T - Tsurr*Tsurr*Tsurr*Tsurr)));
fd=(-h*T-4*e*stfncnstt*T*T*T);
Tn=T-f/fd;
if(((a*G)-(h*(Tn-Tf)+e*stfncnstt*(Tn*Tn*Tn*Tn - Tsurr*Tsurr*Tsurr*Tsurr)))<.01):
break;
T=Tn;
print '%s %.2f %s' %("\n (a) Cure Temperature of Plate =",T-273.,"degC\n");
#solution (b)
Treq=50+273;
#def T(h):
# t=375;
# while(1>0):
# f=((a*G)-(h*(t-Tf)+e*stfncnstt*(t*t*t*t - Tsurr*Tsurr*Tsurr*Tsurr)));
# fd=(-h*t-4*e*stfncnstt*t*t*t);
# Tn=t-f/fd;
# if((a*G)-(h*(Tn-Tf)+e*stfncnstt*(Tn*Tn*Tn*Tn - Tsurr*Tsurr*Tsurr*Tsurr))<.01):
# break;
# tnew=Tn;
# return tnew;
rot=numpy.zeros(4);
rt=0;
def T(h):
coeff = ([-e*stfncnstt, 0,0, -h, a*G+h*Tf+e*stfncnstt*Tsurr*Tsurr*Tsurr*Tsurr]);
rot=numpy.roots(coeff);
for i in range (0,3):
if rot[i]<250 and rot[i]>0:
rt=rot[i];
return rt;
Error at this part. The function is not working.! What can be the error. Please suggest.
h = range(0,100)
tn=range(0,100)
for i in range (0,100):
tn[i] = T(i) -273;
Ti=50+273;
hnew=((a*G)-(e*stfncnstt*(Ti*Ti*Ti*Ti - Tsurr*Tsurr*Tsurr*Tsurr)))/(Ti-Tf);
pyplot.plot(h,tn);
pyplot.xlabel("h (W m^2/K)");
pyplot.ylabel("T (C)");
pyplot.show();
print '%s %.2f %s' %("\n (b) Air flow must provide a convection of =",hnew," W/m^2.K");
#print '%s' %("\n The code for the graph requires more than 10 min to run. ")
#print '%s' %("\n To run it, please remove comments. It is perfectly correct. The reason it takes such a long time")
#print '%s' %("\n is that it needs to calculate using Newton raphson method at 100 points. Each point itself takes a minute.")
#END
Спасибо за ваш ответ. Это было очень полезно. Однако в том же вопросе функция дает 4 корня, из которых некоторые являются сложными, как идентифицировать между ними реальный корень. – Skyuppercut