How to compare each individual column vectors of a matrix to a set of vectors

1 view (last 30 days)
What i basically need is to find if the system of equations that i have, already has a identity matrix or atleast part of it. i.e. if i have a matrix
1 2 1 0;
2 3 0 1;
3 4 0 0;
Though there is no 3x3 identity matrix in the above matrix it still contains 2/3 vectors that make one.
So how to code this?
Really appreciate the help. I am completely new to matlab.
Regards
  7 Comments
Yuvaraj Pazhamalai
Yuvaraj Pazhamalai on 28 Nov 2015
Thanks for the reply. Appreciate the help. I agree that the basis doesn't have to be an identity matrix. Let me put it this way, i just need to find out if an unit vector is already there in the linear problem in it's standard form.

Sign in to comment.

Accepted Answer

the cyclist
the cyclist on 28 Nov 2015
Here is my best guess at some core code that might do what you want.
A = [1 2 1 0;
2 3 0 1;
3 4 0 0];
[m,n] = size(A);
for m1 = 1:m-1
for m2 = m1+1:m
for n1 = 1:n-1
for n2 = n1+1:n
T = A(m1:m2,n1:n2);
[tm,tn] = size(T);
if tm==tn && isequal(T,eye(tm))
sprintf('Identity matrix at A(%d:%d,%d:%d)',m1,m2,n1,n2)
end
end
end
end
end
It is a very straightforward implementation, and I do not take advantage of even simple methods to make it more efficient. (For example, the loops run over non-square submatrices of A.) But I hope you get the idea, and perhaps can tailor it to what you need.

More Answers (0)

Categories

Find more on Operating on Diagonal Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!