如何使用python将具有周期性边界条件的2D势能函数最小化?

问题描述

现在,我正在尝试在具有周期性边界条件和两个电荷q1和q2的情况下最小化2D中的静电势能函数。由于条件的缘故,这两个装药应在对角线上的某个点处相互远离L / sqrt(2),其中L是盒子的长度。到目前为止,我有以下代码

onPageLoad

代码将一维PE功能最小化,其中一个电荷仍保持在原点,另一电荷被允许沿着长度为L的“导线”移动。它仍然具有周期性边界条件。它可以在90%的时间内工作,并且最终得出的分隔距离大约等于L / sqrt(2)。但是,它仍然没有提供与该距离相对应的坐标。另外,如果我尝试通过使用以下代码将其转换为2D:

import matplotlib.pyplot as plt
from scipy.optimize import minimize

def PE_func(x):
    L,q1,q2,x1,y1=13,1,0
    #this starts the periodic boundary conditions
    if x[0]>L:
        x[0]=x[0]-L
    if x[0]<0:
        x[0]=x[0]+L
    if x[1]>L:
        x[1]=x[1]-L
    if x[1]<0:
        x[1]=x[1]+L
    delta_X=np.abs(x1-x[0])
    delta_Y=np.abs(y1-x[1])
    if (delta_X > L/np.sqrt(2)):
        delta_X=L-delta_X
    if (delta_Y > L/np.sqrt(2)):
        delta_Y=L-delta_Y
    #this ends the periodic boundary conditions
    r=np.sqrt((delta_X**2)+(delta_Y**2))
    PE=(9e9*q1*q2)/r
    print(f'The distance between the particles is {r} m.')
    return PE

#coords=[X1,X2]
coords=[np.random.randint(0,13),0]
print(f'Initial coordinates are {coords}.')

result=minimize(PE_func,coords,tol=1e-6)
print(f'Final coordinates are {result.x}.')

它不起作用,每次给出不同的结果。任何帮助将不胜感激

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)