sum of a product with i differnt to j

조회 수: 9 (최근 30일)
MichMichel
MichMichel 2019년 2월 7일
댓글: Matt J 2019년 2월 7일
Hi All,
I want to calculate a sum of a product as following:
I think my problem is quite relative to this topic: Double sum of a product, but in my case I have j ~= i.
I think something like that should work:
t = 1:100;
n = 10;
a = randn(n,1);
P = [];
for i = 1:n
F = [];
for j = 1:n
if j~=i
f = (a(j)-a(i))^n*t;
F = [F,f'];
end
end
p = prod(F,2);
P = [P,p];
end
res = sum(P,2);
But I feel that this solution is not good and something easier should exist?
Thanks a lot,
M.

채택된 답변

Matt J
Matt J 2019년 2월 7일
편집: Matt J 2019년 2월 7일
Something like this, perhaps,
A=a(:)-a(:).';
A(1:n+1:n^2)=1; %nullify i==j
f=sum(prod(A,2).^n)*t;
  댓글 수: 2
MichMichel
MichMichel 2019년 2월 7일
Great thanks a lot it is working well.
Matt J
Matt J 2019년 2월 7일
You're welcome, but please Accept-click the answer to certify that it addressed your question.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by