From 5b9a2d726767264e65283d205155ab5aa3a8d3c5 Mon Sep 17 00:00:00 2001 From: guanjihuan Date: Fri, 22 Nov 2024 12:53:49 +0800 Subject: [PATCH] 0.1.126 --- PyPI/setup.cfg | 2 +- PyPI/src/guan.egg-info/PKG-INFO | 2 +- .../band_structures_and_wave_functions.py | 37 ++++++++++++++++++- PyPI/src/guan/others.py | 5 +++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/PyPI/setup.cfg b/PyPI/setup.cfg index 1f16b1a..fa5075d 100644 --- a/PyPI/setup.cfg +++ b/PyPI/setup.cfg @@ -1,7 +1,7 @@ [metadata] # replace with your username: name = guan -version = 0.1.125 +version = 0.1.126 author = guanjihuan author_email = guanjihuan@163.com description = An open source python package diff --git a/PyPI/src/guan.egg-info/PKG-INFO b/PyPI/src/guan.egg-info/PKG-INFO index 71467f8..84100b1 100644 --- a/PyPI/src/guan.egg-info/PKG-INFO +++ b/PyPI/src/guan.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: guan -Version: 0.1.125 +Version: 0.1.126 Summary: An open source python package Home-page: https://py.guanjihuan.com Author: guanjihuan diff --git a/PyPI/src/guan/band_structures_and_wave_functions.py b/PyPI/src/guan/band_structures_and_wave_functions.py index 4607dd5..56bfffc 100644 --- a/PyPI/src/guan/band_structures_and_wave_functions.py +++ b/PyPI/src/guan/band_structures_and_wave_functions.py @@ -65,12 +65,47 @@ def calculate_eigenvalue_with_two_parameters(x_array, y_array, hamiltonian_funct i0 += 1 return eigenvalue_array -# 计算哈密顿量的本征矢 +# 计算哈密顿量的本征矢(厄密矩阵) def calculate_eigenvector(hamiltonian): import numpy as np eigenvalue, eigenvector = np.linalg.eigh(hamiltonian) return eigenvector +# 施密特正交化 +def schmidt_orthogonalization(eigenvector): + import numpy as np + num = eigenvector.shape[1] + for i in range(num): + for i0 in range(i): + eigenvector[:, i] = eigenvector[:, i] - eigenvector[:, i0]*np.dot(eigenvector[:, i].transpose().conj(), eigenvector[:, i0])/(np.dot(eigenvector[:, i0].transpose().conj(),eigenvector[:, i0])) + eigenvector[:, i] = eigenvector[:, i]/np.linalg.norm(eigenvector[:, i]) + return eigenvector + +# 通过QR分解正交化 +def orthogonalization_with_qr(eigenvector): + import numpy as np + Q, R = np.linalg.qr(eigenvector) + return Q + +# 通过SVD正交化 +def orthogonalization_with_svd(eigenvector): + import numpy as np + U, sigma, VT = np.linalg.svd(eigenvector) + return U + +# 通过scipy.linalg.orth正交化 +def orthogonalization_with_scipy_linalg_orth(eigenvector): + import scipy + Q = scipy.linalg.orth(eigenvector) + return Q + +# 验证是否正交 +def verify_orthogonality(eigenvector): + import numpy as np + identity = np.eye(eigenvector.shape[1]) + product = np.dot(eigenvector.transpose().conj(), eigenvector) + return np.allclose(product, identity) + # 通过二分查找的方法获取和相邻波函数一样规范的波函数 def find_vector_with_the_same_gauge_with_binary_search(vector_target, vector_ref, show_error=1, show_times=0, show_phase=0, n_test=1000, precision=1e-6): import numpy as np diff --git a/PyPI/src/guan/others.py b/PyPI/src/guan/others.py index 1a7db39..45b66df 100644 --- a/PyPI/src/guan/others.py +++ b/PyPI/src/guan/others.py @@ -481,6 +481,11 @@ def convert_wordpress_xml_to_markdown(xml_file='./a.xml', convert_content=1, rep with open(cleaned_filename, 'w', encoding='utf-8') as md_file: md_file.write(markdown_content) +# 凯利公式 +def kelly_formula(p, b, a=1): + f=(p/a)-((1-p)/b) + return f + # 获取所有股票 def all_stocks(): import numpy as np