Рет қаралды 12,174
Learn how to numerically find roots of complex equations in python.
Script can be found here: www.hageslab.com/Resources.ht...
Here we are using "Spyder" IDE with the numpy, scipy, and matplotlib libraries
Script:
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import fsolve
Arbitrary Example
def fxn1(x):
return x**2+3*x - np.exp(x**(1/2))
xlist = np.linspace(0,1,num=1000)
plt.figure(num=1,dpi=120)
plt.plot(xlist,fxn1(xlist),label="Fxn1")
plt.plot(xlist,xlist*0,"--",label="y=0")
plt.legend()
root = fsolve(fxn1,0.5)
def fxn2(Ts, Tinf, Ti, A, Rtot, h, eps, sigma=5.67e-8): # SI units
return (Tinf - Ti)/(A*Rtot) - (h+eps*sigma*(Ts+Tinf)*(Ts**2+Tinf**2))*(Tinf-Ts)
Tlist = np.linspace(283.15,308.15,num=1000)
plt.figure(num=2,dpi=120)
plt.plot(Tlist,fxn2(Tlist,283.15,308.15,1.8,0.25,2,.95),label="Fxn2") # SI units
plt.plot(Tlist,Tlist*0,"--",label="y=0")
plt.legend()
Ts = fsolve(fxn2,290,args=(283.15,308.15,1.8,.25,2,0.95)) # [K]
Ts_C = Tsf-273.15 # [C]