Python中矩阵的数值范围

计算科学 线性代数 Python 特征值
2021-12-01 22:43:16

在线性代数和凸分析的数学领域中,复数的数值范围或值域

n×n矩阵A是集合

W(A)={xAxxxxCn, x0}

在哪里x表示向量的共轭转置x.

在工程中,数值范围被用作 A 的特征值的粗略估计。最近,数值范围的推广被用于研究量子计算。

一个相关的概念是数值半径,它是数值范围内数字的最大绝对值,即

r(A)=sup{|λ|:λW(A)}=supx=1|Ax,x|.

我想在 Python 中实现矩阵的数值范围。我找到了以下代码,但包含一个mlab.find不再存在的功能命令。我还找到了如何替换它,但输出不是所需的。有什么帮助吗?

import numpy as np
import matplotlib.pyplot as plt


def find(condition):
    res,  =  np.nonzero(np.ravel(condition))
    return res


def numerical_range(A, resolution=0.01):
    A = np.asmatrix(A)
    th = np.arange(0, 2*np.pi + resolution, resolution)
    k = 0
    w = []
    for j in th:
        Ath = np.exp(-1j*j)*A
        Hth = (Ath + Ath.H)/2
        e,r = np.linalg.eigh(Hth)
        r = np.matrix(r)
        e = np.real(e)
        m = e.max()
        s = find(e == m)
        if np.size(s) == 1:
            w.append(np.matrix.item(r[:,s].H*A*r[:,s]))
        else:
            Kth = 1j*(Hth - Ath)
            pKp = r[:,s].H*Kth*r[:,s]
            ee,rr = np.linalg.eigh(pKp)
            rr = np.matrix(rr)
            ee = np.real(ee)
            mm = ee.min()
            sm = find(ee == mm)
            temp = rr[:,sm[0]].H*r[:,s].H*A*r[:,s]*rr[:,sm[0]]
            w.append(temp[0,0])
            k += 1
            mM = ee.max()
            sM = find(ee == mM)
            temp = rr[:,sM[0]].H*r[:,s].H*A*r[:,s]*rr[:,sM[0]]
            w.append(temp[0,0])
        k += 1
    plt.plot(w)
    return None


A = np.matrix([[.6,.5], [.6,.5]])
numerical_range(A, resolution=0.01)
plt.show()
```
0个回答
没有发现任何回复~