我正在尝试求解一个由两个耦合的自洽方程组成的系统,即y= f(x,y)
和x= g(x,y)
。我已经使用scipy.optimize.fsolve和scipy.optimize.root解决了问题,但是根据我使用的猜测,解决方案(附带的图)会完全改变。
我的代码如下
from numpy import *
from math import *
from sympy import *
import scipy.integrate as integrate
from scipy import optimize
from scipy.misc import derivative
import matplotlib.pyplot as plt
import random
import warnings
warnings.filterwarnings('ignore', 'The iteration is not making good progress')
import time
start_time = time.time()
J = 0
U = 0.6
T = 0.0000007
t = 0
mu= 0
pi = 3.14159265358979323846
gamma_1 = 0.03
xc_derivative = [ U, U, U]
####### model for v_Hxc function #################### checked -> it's OK
def v_Hxc_ext (k, gamma, N):
alpha = xc_derivative[k-1] / (xc_derivative[k-1]+5.68*gamma)
gammaoverU = gamma / xc_derivative[k-1]
sigma = 0.811*gammaoverU-0.390*pow(gammaoverU,2)-0.168*pow(gammaoverU,3)
N_shifted = N-k+1
if N_shifted < 0: v_ext = 0
elif 0 <= N_shifted <= 2:
v_Hartree = xc_derivative[k-1]*(N_shifted)*0.5
v_ext = v_Hartree+alpha*xc_derivative[k-1]*0.5*(1-N_shifted-(2/pi)*atan((1-N_shifted)/sigma))
elif N_shifted > 2 :
v_ext = xc_derivative[k-1]
return v_ext
def v_bar_Hxc_eq (gamma,N):
v_eq = 0
for k in range(1,4):
v_eq = v_eq + v_Hxc_ext(k, gamma, N)
return v_eq
########################################################################
####### method to solve coupled gate potentials (different in each dot) #########
def equations (x):
n1 = x[0]
n2 = x[1]
KS_energy_1 = v -t + v_bar_Hxc_eq ( gamma, n1 + n2)
KS_energy_2 = v -t + v_bar_Hxc_eq ( gamma, n1 + n2)
z1= ((gamma_1L+gamma_1R)/gamma_1)*((-2/pi)*atan((2*KS_energy_1)/(gamma_1))+1) - n1
z2= ((gamma_2L+gamma_2R)/gamma_2)*((-2/pi)*atan((2*KS_energy_2)/(gamma_2))+1) - n2
return [z1,z2]
list_Conductance = [[0 for col in range(5001)] for row in range(4)]
delta_v = 0.05
aux = 0
for param_gamma in [1, 0.6, 0.3, 0.00000001]:
gamma_2 = param_gamma*gamma_1
gamma = gamma_1 + gamma_2
gamma_1L = gamma_1R = 0.5*gamma_1
gamma_2L = gamma_2R = 0.5*gamma_2
list_v = []
gamma_L = gamma_1L + gamma_2L
gamma_R = gamma_1R + gamma_2R
sumdeltaxc = xc_derivative[0] +xc_derivative[1] + xc_derivative[2]
v = -1.9
list_v = []
aux2 = 0
while v <= 0.3:
list_v.append(v)
print ('v= '+str(v))
n1, n2 = optimize.fsolve(equations,[1,1])
KS_energy_1 = v -t + v_bar_Hxc_eq (gamma, n1+n2)
KS_energy_2 = v -t + v_bar_Hxc_eq (gamma, n1+n2)
Conductance_KS = (gamma_1L*gamma_1R)/(pow(mu-KS_energy_1,2)+pow(gamma_1/2,2)) + (gamma_2L*gamma_2R)/(pow(mu-KS_energy_2,2)+pow(gamma_2/2,2))
list_Conductance[aux][aux2] = Conductance_KS
v += delta_v
aux2 += 1
if len(list_v) != len(list_Conductance[aux]):
while len(list_v) < len(list_Conductance[aux]):
del list_Conductance[aux][-1]
while len(list_v) > len(list_Conductance[aux]):
del list_v[-1]
plt.plot(list_v, list_Conductance[aux], label = '$\\gamma_{2}='+str(param_gamma)+'\\gamma_{1}$')
aux += 1
plt.legend(loc = 0, prop={'size': 17})
plt.tick_params(labelsize=17)
plt.xlabel('$v$', fontsize=20)
plt.ylabel('$G$', fontsize=20)
该问题的解决方案应该独立于初始猜测而相同,但是我得到的一些输出是(对于(0,0),(1,1)(2,2)作为初始猜测)< / p>
我尝试更改函数调用的次数,但没有任何改变。我做错了什么?谢谢