How to implement an equation containing nested Summations

조회 수: 1 (최근 30일)
Sarath S
Sarath S 2019년 11월 26일
댓글: Sarath S 2019년 11월 27일
I am trying to write a matlab code to evaluate an error function given as:
Capture.PNG
I tried the following line of matlab code but there seems to be some problem with it.
E=0;
for i = 1:n-1
for j = i+1:n
for k = 1:n-1
for l = k+1:n
E =E + ((t(i,j)*(D(k) - D(l)) - t(k,l)*(D(i)-D(j))))^2;
end
end
end
end
I am not sure whether I have used the for loops correctly. Please advice. Thanks.
  댓글 수: 2
David Goodmanson
David Goodmanson 2019년 11월 27일
Hi Sarath, it looks all right. There is an unneeded set of outermost parentheses which should not matter.
Sarath S
Sarath S 2019년 11월 27일
Thank you for the verification. I think the problem was with one of my variables. It's working much better now.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by