dimension error with * operator

조회 수: 14 (최근 30일)
Douglas Brenner
Douglas Brenner 2018년 9월 28일
댓글: OCDER 2018년 9월 28일
This line of code: asynch = C1(:)*N(:)*C(:)'/(delta-2) throws an error: Error using * Inner matrix dimensions must agree. That would seem to be right C1 is a 1X100 double and N is a 100x100 double. So I changed the code to T = transpose(C1); asynch = C1(:)*N(:)*T(:)'/(delta-2). This makes T a 100X1 double and the code should run but I get the same error. What's wrong. Thanks
  댓글 수: 1
OCDER
OCDER 2018년 9월 28일
synch = C1(:)*C1(:)'/(delta-2)
^
This works because of the transpose operator.
C1(:) = Nx1 vector
C1(:)' = 1xN vector
so C1(:)*C1(:)' works as a (Mx1) * (1xM) = MxM vector (inner dimension agrees)
In your case, you have a matrix N that is 100x100.
N = 100x100 matrix
N(:) = 10000x1 vector
C(:)*N(:) will NOT WORK because it's a (Mx1) * (10000x1) = ????

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

답변 (3개)

OCDER
OCDER 2018년 9월 28일
Although N is a 100x100 matrix, when you do N(:), you make it into a 10000x1 vector. Get rid of the "(:)" when you want to proper matrix math.

Pratik Bajaria
Pratik Bajaria 2018년 9월 28일
Hello,
Try .* operator. It is the normal matrix multiplication, the one you are trying is doing a Hadamard multiplication.
Regards, Pratik

Douglas Brenner
Douglas Brenner 2018년 9월 28일
The paper from which I got the code uses * and that works in this line: synch = C1(:)*C1(:)'/(delta-2). Not only do I not get an error but I get what I think is the right answer. For asynch = C1(:)*N(:)*C(:)'/(delta-2), I think the problem is that N is 2D and C1 is one D but I got that code from the paper too.

카테고리

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

제품


릴리스

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by