无法在 Matlab 中映射矩阵

Unable to map a matrix in Matlab

我有这个二维马尔可夫链的 3x3 方程组。我想将这个矩阵的系数映射为看起来像这个也具有这些零系数的 9x9 矩阵,但我不知道如何进行。有帮助吗?

[ 5*P11 - 2*P12 - 2*P21, 7*P12 - 5*P11 - 4*P13 - 2*P22,          9*P13 - 5*P12 - 2*P23]
[ 7*P21 - 2*P22 - 4*P31, 9*P22 - 5*P21 - 4*P23 - 4*P32, 11*P23 - 5*P22 - 5*P13 - 4*P33]
[         9*P31 - 2*P32,        11*P32 - 5*P31 - 4*P33,          8*P33 - 5*P32 - 5*P23]

Coefficient Matrix

您可以使用 coeffs 来获取系数。

syms P11 P12 P13 P21 P22 P23 P31 P32 P33
%your data
T=[ 5*P11 - 2*P12 - 2*P21, 7*P12 - 5*P11 - 4*P13 - 2*P22,          9*P13 - 5*P12 - 2*P23;...
    7*P21 - 2*P22 - 4*P31, 9*P22 - 5*P21 - 4*P23 - 4*P32, 11*P23 - 5*P22 - 5*P13 - 4*P33;...
    9*P31 - 2*P32,        11*P32 - 5*P31 - 4*P33,          8*P33 - 5*P32 - 5*P23];
%get a list of all variables. Optional, sort here if you expect another ordering.
allvars=symvar(T);

%initialize empty matix
C=zeros(numel(T),numel(allvars));
%build up coefficient matrix
for ix=1:numel(T)
    [a,b]=coeffs(T(ix));
    C(ix,ismember(allvars,b))=a;
end

哪个returns

>> C

C =

     5    -2     0    -2     0     0     0     0     0
     0     0     0     7    -2     0    -4     0     0
     0     0     0     0     0     0     9    -2     0
    -5     7    -4     0    -2     0     0     0     0
     0     0     0    -5     9    -4     0    -4     0
     0     0     0     0     0     0    -5    11    -4
     0    -5     9     0     0    -2     0     0     0
     0     0    -5     0    -5    11     0     0    -4
     0     0     0     0     0    -5     0    -5     8