如何解决Python / Matlab中的矩阵方程?

时间:2017-08-23 00:05:09

标签: python matlab

我打算编写一个Python / Matlab代码来解决https://math.stackexchange.com/questions/2402866/how-to-obtain-an-solution-of-the-following-matrix-equation-system

中的矩阵方程系统

有没有以Python或Matlab的矩阵形式编写方程式来解决? 感谢。

1 个答案:

答案 0 :(得分:1)

将问题视为最小搜索问题(使用240个参数):

clear
L=[3,2.8,2.25,1.5,1,1,1,1,0.48,0.48,0.48,0,0,0,0];
a0=rand(1,15)-0.5;
t0=rand(1,15*15);
v0=[a0,t0];

fun=@(v)Fun(v,L);
options = optimoptions('fmincon','Display','iter','Algorithm','sqp',...
'MaxFunctionEvaluations',1e8,'MaxIterations',1e4);
[v,fval,exitflag,output]=fmincon(fun,v0,[],[],[],[], -1+0*v0, 1+0*v0,[],options);
A=diag(v(1:5))+squareform(v(6:15));
eta=reshape(v(15+1:15+15*15),15,15);

function err=Fun(v,L)
    A=diag(v(1:5))+squareform(v(6:15));
    M=eye(15)+kron(1-eye(3),A);
    eta=reshape(v(15+1:15+15*15),15,15);
    res1=M-eta*diag(L)*eta'; %first eq
    err1=sum(res1(:).^2);
    res2=eta-eta'; %orthogonality
    err2=sum(res2(:).^2);

    err3=0;
    for k=1:4
        for i=1:2
            etaik=eta(1+(i-1)*5:i*5, k);
            for j=i:3
                etajk=eta(1+(j-1)*5:j*5, k);
                res3=etaik'*A*etajk - (L(k)-1)/6;
                err3=err3+sum(res3(:).^2);
            end
        end
    end
    err=err1+err2+err3;
end

解决方案:

A =
       0.2717     -0.07536     0.079584    -0.016013      0.45538
     -0.07536      0.58885      0.17244      0.46076    -0.036574
     0.079584      0.17244      0.93162     -0.18853    -0.011267
    -0.016013      0.46076     -0.18853      0.47542      0.10454
      0.45538    -0.036574    -0.011267      0.10454      0.70009

Eta是15x15 ......

fval =
   0.00067

从此处继续并添加更多约束。

相关问题