Solve for A matrix in Ax = 0

Hi,
I want to solve for a n x n matrix A when I know the n x 1 vector x and the system of linear equations is Ax = 0. The linear constraints I have on solving it is that each column should sum to 0 and I also know the diagonal elements of the A matrix. The matrix A is also tridiagonal, so the only non-zero elements are the ones on the main diagonal and the diagonals above and below it.
I can solve it by hand but unsure about how to do it using MATLAB. I assumed lsqlin would be able to do it but it seems like it only solves for the x vector.
Any ideas will be greatly appreciated. Thanks in advance.

1 Comment

You have 2*n equations for 2*(n-1) degrees of freedom. So usually, your problem will not have a solution.

Sign in to comment.

 Accepted Answer

Matt J
Matt J on 22 Feb 2024
Edited: Matt J on 22 Feb 2024
n=numel(x);
mask=tril(triu(ones(n),-1),+1); %tridiagonal mask
A=optimvar('A',[n,n]);
prob = eqnproblem;
prob.Equations.eqn1=sum(A,1)==0; %known column sums
prob.Equations.eqn2=diag(A)==Adiag; %known diagonal values
prob.Equations.eqn3=A.*mask==A; %tridiagonal conition
prob.Equations.eqn4=A*x==0; %A*x==0
[sol,fval,exitflag] = solve(prob);

4 Comments

Matt J
Matt J on 22 Feb 2024
Edited: Matt J on 22 Feb 2024
In light of the fact that you have more equations than unknowns, you would probably need to seek a least squares solution. It is not clear which of your equations you want to relax from equality to least-squares agreement. If I assume that A*x=0 is that equation, then the code would get modified to,
n=numel(x);
mask=tril(triu(ones(n),-1),+1); %tridiagonal mask
lb=-inf(n);
lb(~mask)=0;
lb(1:n+1:end)=Adiag; %known diagonal
ub=-lb;
ub(1:n+1:end)=Adiag;
A=optimvar('A',[n,n], 'Lower', lb,'Upper',-lb);
prob = optimproblem;
prob.Constraints.eqn1=sum(A,1)==0; %known column sums
prob.Objective=sum((A*x).^2); %A*x==0
[sol,fval,exitflag] = solve(prob);
prob.Equations.eqn1=sum(A,1)==0; %known column sums
instead of
prob.Equations.eqn1=sum(A,1)==1; %known column sums
?
Yep, you're right.
Thanks all, for the explanations and the solutions. I'm sure I'm framing the question wrong but I can't figure out what. I believe I'll be able to solve it from here by putting in a little work. Much appreciated.

Sign in to comment.

More Answers (0)

Products

Release

R2023a

Asked:

on 22 Feb 2024

Commented:

on 22 Feb 2024

Community Treasure Hunt

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

Start Hunting!