Function to find if B is an echelon or row equivalent of A
2 views (last 30 days)
Show older comments
Hello, Im new to MATLAB and would like to know which function should I use if matrix B is row-equivalent of matrix A, and the function that calculates if matrix B is one of the valid echelon forms of matrix A
Thanks
0 Comments
Answers (4)
Aurelien Queffurust
on 27 Dec 2011
Let's say B has the same second row of A :
>>A = [1 2 3; 4 5 6; 7 8 9];
>>B = [ 4 5 6;10 11 12];
You could use ismember to have this equivalent :
>> ismember(A,B)
ans =
0 0 0
1 1 1
0 0 0
0 Comments
Andrei Bobrov
on 27 Dec 2011
tstg - function of test of gaussian elimination products
tstg = @(A,B)abs(mod(det([A(1:end-1,:);B]),det(A))) < 1e6*eps;
eg:
>> A= randi(78,3)
A =
70 11 66
75 12 20
43 21 64
>> B = randi(78,1,3)
B =
19 73 28
>> tstg(A,B)
ans =
0
>> B = A(1,:)*2 + A(3,:)
B =
183 43 196
>> tstg(A,B)
ans =
1
ADD [09:23(UTC+4) 30.12.2011]
e.g.
A = randi(8,9,5);
B = A(1,:)*.4+A(end,:)*8;
K = nchoosek(1:size(A,1),size(A,2)-1);
out = [];
flag = false;
for i1 = 1:size(B,1)
b = B(i1,:);
for j1 = 1:size(K,1)
if abs(det([A(K(j1,:),:);b])) < 1e3*eps
flag = true;
out = [out; j1 i1];
end
end
end
Andrew Newell
on 30 Dec 2011
function TF = areRowEquivalent(A,B,tol)
TF = norm(rref(A)-rref(B)) < tol;
EDIT: Take the two lines and save them in a file called areRowEquivalent.m. Here is an example of its use. The function returns a logical value (true/false), and I have added some code to interpret it in words.
A = [1 2 3; 4 5 6; 7 8 9];
B = [1 2 3;1 -1 -3;7 8 9];
tol = 1e-6;
TF = areRowEquivalent(A,B,tol);
if TF
disp(['Row equivalent to a tolerance of ',num2str(tol),'.'])
else
disp(['Not row equivalent to a tolerance of ',num2str(tol),'.'])
end
2 Comments
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!