Function to find if B is an echelon or row equivalent of A

2 visualizzazioni (ultimi 30 giorni)
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

Risposte (4)

Aurelien Queffurust
Aurelien Queffurust il 27 Dic 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

Andrei Bobrov
Andrei Bobrov il 27 Dic 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
  1 Commento
Husy
Husy il 29 Dic 2011
Andrei, Thanks for the response. I get the following error
>> tstg(A,B)
??? Error using ==> det
Matrix must be square.
Error in ==> @(A,B)abs(mod(det([A(1:end-1,:);B]),det(A)))<1e6*eps

Accedi per commentare.


Husy
Husy il 27 Dic 2011
Aurelien, Thanks for response. Your answer is for the question "Does B contain a row that is equal to a row of A". My question is row equivalance, not equal. By row equivalance, I mean that the row in B, is a product of gaussian elimination done on corresponding row in matrix A. For example
>>A = [1 2 3; 4 5 6; 7 8 9];
>>B = [1 2 3;1 -1 -3;7 8 9];
In this example BRow2=ARow2 - 3 *ARow1 So Matrix A and B are row equivalant, since B is a product of gaussian elimintaion done on matrix A

Andrew Newell
Andrew Newell il 30 Dic 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 Commenti
Husy
Husy il 30 Dic 2011
Andrew,
I believe this is the answer I need, but since I am new to MATLAB (But I know algorithms), I am not able to make this work.
I pasted this code exactly then got an error.
Then I googled and found smthng, I saved this as areRowEquivalent.m file in my work path.
But now how should I use this function?
I tried some workarounds but got error about tol, what is tol used for here?
Thanks
Andrew Newell
Andrew Newell il 30 Dic 2011
Husy, I have edited my response to provide more information.

Accedi per commentare.

Categorie

Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by