I am trying to model a differential equation including , where C is a 4 by 4 matrix, i are rows, and j are vectors. The sigma notation is crucial towards using the interaction coefficient with the proper elements in the matrix. I don't at all know what I'm doing, and have been using symsum so far but have gotten absolutely nowhere. How do I code this without getting "Subscript indices must either be real positive integers or logicals errors"?

 채택된 답변

Star Strider
Star Strider 2019년 7월 13일

0 개 추천

Taking a wild guess:
x = rand(1,4); % Create Vector
C = rand(4); % Create Matrix
for i = 1:4
for j = 1:4
E(i,j) = C(i,j)*x(i)*x(j); % Multiplications
end
end
S = sum(E(:)); % Summation
There are likely more efficient ways to do this, however I am choosing to keep this as transparent as possible. Note that symsum is not intended to do this type of summation.

댓글 수: 2

Anna Singley
Anna Singley 2019년 7월 13일
Thanks so much! Even though this may not work perfectly, it's an improvement over brute-force typing out all possible permuatations.
Star Strider
Star Strider 2019년 7월 13일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

질문:

2019년 7월 12일

댓글:

2019년 7월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by