mercredi 18 février 2015

optimize.newton issue [on hold]


This is my first time using the optimize.newton function. I am defining a couple of functions (LHS, RHS) along with their integral (result_LHS, result_RHS). I am using the result_LHS and result_RHS functions as to define a new function (called function) for which I want to find the zero (T_a).



alb = 0.2 #constant albedo
F = 866 #J/s*m**2
R = 287 #J/K*kg
U = 5 #m/s
C_p = 1000 #J/K*kg
C_d = 0.0015
p1 = 10**4
p2 = 10**5
p3 = 10**6 #Pa
sig = 5.67*10**-8 #J/s*m**2*K**4 #Stefan-Boltzmann cst
def rho(T_a):
return p1/(R*T_a) #FIRST USING P = 10**4 Pa
def a(T_a):
return rho(T_a)*C_p*C_d*U



x0=230

def LHS(theta):
return (1-alb)*F*np.sin(theta)*np.cos(theta)

def result_LHS(theta):
return integrate.quad(lambda theta: LHS(theta), 0, pi/2)

def T_g(theta, T_a):
return np.roots(array([(sig),0,0,(a(T_a)),((-a(T_a)*T_a)-LHS(theta))]))[3]

def RHS(theta,T_a):
return sig*T_g(theta,T_a)**4*np.cos(theta)

def result_RHS(theta,T_a):
return integrate.quad(lambda theta: RHS(theta,T_a), -pi/2, pi/2)

def function(theta,T_a):
return 1-((result_LHS(theta)/result_RHS(theta,T_a)))

T_a_0 = scipy.optimize.newton(function,x0,fprime=None,args=(theta,),tol=(10**-5))
print T_a_0


Here is what it outputs:



Traceback (most recent call last):
File "/Users/jadecheclair/Documents/PHY479Y/T_gvstheta.py", line 167, in <module>
T_a_0 = scipy.optimize.newton(function,x0,fprime=None,args=(theta,),tol=(10**-5))
NameError: name 'theta' is not defined


I was thinking I might need to define my theta, which would be theta=np.arange(-pi/2, pi/2, pi/20). But since I am using it as a variable of integration in "result_LHS" and "result_RHS" integration functions, I think it should remain a variable. Then how come python doesn't accept the fact that theta is a variable and needs to define it?


I would greatly appreciate any kind of help!





Aucun commentaire:

Enregistrer un commentaire