필터 지우기
필터 지우기

how to multiply matrix with vector n times?

조회 수: 1 (최근 30일)
janny
janny 2014년 11월 11일
댓글: janny 2014년 11월 12일
hi guys i have this code:
M =[0 1 0 0 0 0 0 0;0 0 1 0 0 0 0 0;0 0 0 1 0 0 0 0;0 0 0 0 1 0 0 0; 0 0 0 0 0 1 0 0;0 0 0 0 0 0 1 0;0 0 0 0 0 0 0 1;1 1 0 0 0 0 0 0];
A = [ 1 0 0 0 0 0 0 0];
C =mod((A*M'),2) % multiplication by module 2
i want to repeat the C =mod((A*M'),2) many times until one of the results repeated. how to do this?
  댓글 수: 1
Roger Stafford
Roger Stafford 2014년 11월 11일
When you say "repeated" do you mean successive vectors, C, are the same, or do you mean that one of the C's along the line is the same as some earlier C so that a cycle is created? The first meaning is easier to accomplish and the second sounds more likely.

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 2014년 11월 11일
I assume you mean you want to repeat
A = mod(A*M', 2);
Otherwise, if A and M never changes C = mod(A*M', 2) will always give the same result!
Assuming you want to stop when any of the A that's been generated reappers again, build a matrix of A (concatenate rows) and use ismember(..., 'rows') to find if your new A is present in the matrix:
M =[0 1 0 0 0 0 0 0;0 0 1 0 0 0 0 0;0 0 0 1 0 0 0 0;0 0 0 0 1 0 0 0; 0 0 0 0 0 1 0 0;0 0 0 0 0 0 1 0;0 0 0 0 0 0 0 1;1 1 0 0 0 0 0 0];
A = [ 1 0 0 0 0 0 0 0];
AA = A;
A = mod(A*M', 2)
while ~any(ismember(A, AA, 'rows'))
AA = [AA; A];
A = mod(A*M', 2);
end
  댓글 수: 6
Guillaume
Guillaume 2014년 11월 12일
No. Try to understand what it does.
You have to replace the original
while ~any(ismember(A, AA, 'rows'))
by the four lines I've written, in the same order (well, you can swap the first two).
janny
janny 2014년 11월 12일
thanks man,, it works fine...
AA = A; A = mod((A*M'), 2) step = 0; while ~any(ismember(A, AA, 'rows'))&& step < maxstep AA = [AA; A]; A = mod((A*M'),2);
maxstep = 10;
step = step + 1;
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Elementary Math에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by