matrix multiply by array xi=xj

조회 수: 4 (최근 30일)
Nur Amalina
Nur Amalina 2020년 2월 12일
편집: Nur Amalina 2020년 2월 12일
Hi, All!
say, i have a matrix:
eij= [0 1 0 1;1 0 1 1;0 1 0 1;1 1 1 0];
x1=1; x2=2; x3=3; x4=4;
how can i make array xj and xi for this function
for i=1:1:4 and j=1:1:4
xi = xj
Ai =
i hope the answer would be like this:
A1= 0(1 - 1) + 1(2 - 1) + 0(3 - 1) + 1(4 - 1)=4
A2= ...; A3=..., A4=...
i am trying to use repmat function but i am stuck. maybe anyone has better solution?

채택된 답변

KSSV
KSSV 2020년 2월 12일
편집: KSSV 2020년 2월 12일
e = [0 1 0 1;1 0 1 1;0 1 0 1;1 1 1 0];
x = [1 2 3 4] ;
A = zeros(size(e)) ;
for i = 1:4
for j = 1:4
A(i,j) = e(i,j)*(x(i)-x(j)) ;
end
end
A = sum(A,2)
  댓글 수: 1
Nur Amalina
Nur Amalina 2020년 2월 12일
편집: Nur Amalina 2020년 2월 12일
got it. thank you!

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

추가 답변 (1개)

Bhaskar R
Bhaskar R 2020년 2월 12일
x = 1:4;
eij= [0 1 0 1;1 0 1 1;0 1 0 1;1 1 1 0];
tmp =0;
for i = 1:4
for j = 1:4
tmp =tmp + eij(i, j)*(x(j)-x(i));
end
A(i) = tmp;
end

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by