Код: Выделить всё
from scipy.constants import c, m_e, e
me_ev = m_e*c**2/e # mass m_e in [eV]
l_bohr = 5.2918e-11 # Bohr radius [m]
convert_length = 5067730.179 # convert [m] to [1/eV] in natural units
l_ev = l_bohr * convert_length
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
from scipy.optimize import root_scalar
# TISE
def eqn (x, y, energy):
me_ev = m_e*c**2/e
f_0 = y[1] # dphi/dx
f_1 = -2 * me_ev * energy * y[0] # d2phi/dx2, y[0] = phi
return np.array([f_0, f_1])
# using solve_ivp and the initial coonditions phi(0)=0 and dphi(0)/dx=1 to find phi(L)
def solve(energy, func):
#constants
l_bohr = 5.2918e-11 # Bohr radius [m]
convert_length = 5067730.179 # convert [m] to [1/eV] in natural units
l_ev = l_bohr * convert_length
# x goes form [0,L]
x = np.linspace(0., l_ev, 1000)
# initial conditions
phi0 = 0.0
dphi0dx = 1.0
init = np.array([phi0, dphi0dx])
answer = solve_ivp(func, (0., l_ev), init, t_eval=x, args=(energy,))
phiL = answer.y[0][-1]
return phiL
Код: Выделить всё
# calculating ground state energy:
# use fsolve to put different energies into solve(energy, func) such that phiL is minimized:
ground_energy = fsolve(solve, 134.0, args=(eqn,))
print(ground_energy)
установка элемента массива с последовательностью. Запрошенный массив имеет неоднородную форму после 1 измерения. Обнаруженная форма была (2,) + неоднородная часть.
Кто-нибудь знает, как это исправить?
Функцияsolve возвращает phi(L) так что я могу оптимизировать энергию так, чтобы phi(L)=0. Здесь я сталкиваюсь с проблемами. Я пытаюсь использовать fsolve.
Подробнее здесь: https://stackoverflow.com/questions/793 ... oot-finder
Мобильная версия