我有一个问题(可能很傻),我无法回答 .

考虑三个矩阵A,B和M.它们都是NxN矩阵,我也知道A和B是对称的(它们是协方差矩阵) .

我需要使用python从下面的等式 B = M A M^ 中找到矩阵 M . 换句话说,我如何求解隐式矩阵方程 using python

这是我对fsolve的尝试:

import scipy
import scipy.optimize
f = lambda M: (np.mat(B)-(np.mat(M)*np.mat(A)*np.mat(M.T)))
M0 = scipy.optimize.fsolve(f, np.identity(57))

我给出了初始猜测的单位矩阵 .

Problem:

/Users/Simone/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/matrixlib/defmatrix.pyc in __mul__(self, other)
    339         if isinstance(other, (N.ndarray, list, tuple)) :
    340             # This promotes 1-D vectors to row vectors
--> 341             return N.dot(self, asmatrix(other))
    342         if isscalar(other) or not hasattr(other, '__rmul__') :
    343             return N.dot(self, other)

ValueError: matrices are not aligned

我也以不同的方式尝试过:

f = lambda X: ((B) - np.dot(X,np.dot(A,X.T)))  
X0 = scipy.optimize.fsolve(f, np.identity(57))

同样,“矩阵不对齐” . 这有点不可能,因为我都是nxn平方矩阵,我所做的任何操作都没有改变尺寸 . 我当然检查过

B.shape, 
A.shape, 
np.identity.(57).shape 
((B) - np.dot(X,np.dot(A,X.T))).shape

它们都是一样的!

谢谢你,西蒙娜