solve linear equation system with partially unknown coefficient matrix

6 views (last 30 days)
Hello everybody,
I have a question concerning solving linear equation systems with matlab. Concidering I have an equation system: A*x=y.
x and y are column vectors, where all entrys are known. The data for x und y are measured values.
A is a square matrix, which is diagonal symmetric: . Also the matrix is linearly independent. I know, that some coefficients have to be 0.
Is there any way to solve this equation system in Matlab to get the missing coefficients of A?
In this example there are 8 unknown coefficients, but only 4 rows.
I have to say, that for x and y there are different measurements available, so I could expand these vectors to matrices:
I thought about a solution approach like least absolute deviation, but I don't know, how to consider in matlab the conditions:
  • zero elements
  • symmetric matrix
Is there any way to solve this problem? At the moment I'm not sure, if this is possible at all?
Thank you for your help!
  2 Comments
John D'Errico
John D'Errico on 23 Oct 2020
Edited: John D'Errico on 23 Oct 2020
Knowing that some coefficients must be zero is not what linearly independent means or implies.
Regardless, the solution posed by Bruno, which uses kron to essentially unroll the elements of A is the approach I would use. I believe I could also have solved the problem using symbolic algebra, to create a linear system in those unknowns. The result would be converted to a system of linear equations, solved using linear algebra. But used properly, kron is a better solution, because it never requires you to go into the symbolic domain - that would be much slower.
J_Automotive
J_Automotive on 25 Oct 2020
Hello John,
the information that it has to be linearly independent can be shown by using the real system, it's not an information, which you can get out of my example.
The solution from Bruno seems to work quick and fine, so I also prefer this one. For me it's also important that the solution approach works with the main functions of matlab, because I don't have access to many Toolboxes.

Sign in to comment.

Accepted Answer

Bruno Luong
Bruno Luong on 23 Oct 2020
Edited: Bruno Luong on 23 Oct 2020
Just using linear algebra, no extra tollbox is needed, of course n==1 is underdetermined problem
% Generate random matrix
n = 10;
L = rand(4);
A = L+L.';
A(3,1)=0;
A(4,2)=0;
A(2,4)=0;
A(1,3)=0;
A
% And X/Y data compatible with equation
X = rand(4,n)
Y = A*X;
clear A
% Engine
% Enforce symmetric
ij = nchoosek(1:4,2);
i = ij(:,1);
j = ij(:,2);
ku = sub2ind([4 4],i,j);
kl = sub2ind([4 4],j,i);
p = size(ij,1);
R = (1:p)';
M = kron(X.',eye(4));
sz = [p size(M,2)];
C = accumarray([R ku(:)],1,sz) + accumarray([R kl(:)],-1,sz);
% Enforce A(3,1) & ... A(4,2) == 0
K = sub2ind([4 4],[3, 4], ...
[1, 2]);
sz = [2 size(M,2)];
C0 = accumarray([(1:2)', K(:)],1, sz);
C = [C; C0];
p = size(C,1);
% Solve least squares with linear constraints
z = [M'*M, C';
C, zeros(p)] \ [M'*Y(:); zeros(p,1)];
A = reshape(z(1:16),4,4)
  5 Comments
J_Automotive
J_Automotive on 25 Oct 2020
Hello Bruno, i checked your solution, but i have difficulties to understand it completely.
Would it be possible to consider one more condition, which would be every element has to negative, so only have to be positive values?
Thank you
Bruno Luong
Bruno Luong on 26 Oct 2020
Edited: Bruno Luong on 26 Oct 2020
Least_squares with extra constraints
A(i,j) <= 0 for i~=j
A(i,i)>=0
% Generate random matrix
n = 10;
L = rand(4);
A = L+L.';
A = A.*(2*eye(4)-1);
A(3,1)=0;
A(4,2)=0;
A(2,4)=0;
A(1,3)=0;
A
% And X/Y data compatible with equation
X = rand(4,n)
Y = A*X;
% Y = Y+0.1*randn(size(Y));
clear A
% Engine
M = kron(X.',eye(4));
[I,J] = ndgrid(1:4);
I = I(:);
J = J(:);
b = I<=J & ~ismember([I,J], [1 3; ...
2 4], 'rows');
I = I(b);
J = J(b);
ku = sub2ind([4 4],I,J);
kl = sub2ind([4 4],J,I);
p = size(I,1);
R = (1:p)';
sz = [size(M,2) p];
isd = I==J;
P = accumarray([ku, R; ...
kl, R; ...
ku, R], [isd-1; isd-1; isd], sz);
z = lsqnonneg(M*P, Y(:));
A = reshape(P*z,4,4)
(Note: This is the last time I answered to a modified question.)

Sign in to comment.

More Answers (1)

Ameer Hamza
Ameer Hamza on 23 Oct 2020
One approach is to find a least square solution using fmincon()
x = rand(4, 1);
y = rand(4, 1);
A = @(a) [a(1) a(2) 0 a(3);
a(2) a(4) a(5) 0;
0 a(5) a(6) a(7);
a(3) 0 a(7) a(8)];
objFun = @(a) sum((A(a)*x-y).^2, 'all');
sol = fmincon(objFun, rand(8,1))
  2 Comments
J_Automotive
J_Automotive on 23 Oct 2020
Thank you for your fast reply.
I have to check if I have an Optimization Toolbox License available.
After checking the result I will answer, whether this was useful.
Best regards
J
J_Automotive
J_Automotive on 25 Oct 2020
Hello Ameer,
sorry, I don't have a license for the Optimiztion Toolbox, so I wasn't able to check your solution.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!