我想使用fsolve
查找我知道q(q_1000)值的函数z(q)
的2个值
我的代码:
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import fsolve
k_b = 1.38064852e-23
n_0 = 2e+25
m = 4.8e-26
g = 9.81
T = 300
I_inf = 400
sigma = 4e-22
kappa = 0.2
H = (k_b*T)/(m*g)
val = 100
z_min = 1e+5
z_max = 4e+5
z = np.linspace(z_min, z_max, val)
# ______________________________ Functions ___________________________________________
n = lambda z : n_0*np.exp(-z/H)
I = lambda z : I_inf*(np.exp(-(sigma*n(z)*H)))
q = lambda z : kappa*sigma*n(z)*I(z)
q_max = q(z).argmax() # q_max
q_1000 = q(z)[q_max]/1000 # q_max / 1000
result1 = fsolve(q,q_1000) # start at z = q_1000
plt.xscale('log')
plt.yscale('log')
plt.title('z(q)')
plt.axis([1e-11, 1e-1, 1e+5, 4e+5])
plt.plot(q(z)[q_max], z[q_max],'x', label="z*=q_max", color="red")
plt.plot (q(z),z,'k-')
plt.plot(result1,q_1000,'ro')
plt.legend()
plt.xlabel('q')
plt.ylabel('z')
plt.show()
print(q(z)[q_max])
print(q_1000)
print(result1)
那是我的结果