n: n dimension of the equation
D: nxn-dimension Matrix
L: nxn-dimension Matrix
X: n-dimension Vector
S: n-dimension Vector
Hi, I wanted to create a summation function shown in the picture, it seems its hard to implement symsum() function in matlab. So I create a 2 summation function Mu (First summation in the picture) and sumLs (Second summation in the picture). I wanted to ask is there any other way to do this, Is my summation code correct, Sorry I cannot point out the mistake of my function as it involve matrix and vectors calculation. Thanks for any help
To calculate Mu, I call Mu function, In the Mu function, i call sumLs function
function Mu = Muf(n, D, S, X, L)
sumLs = sumLsf(i, L, S);
tempMu = 0;
for i=1:n
tempMu = tempMu + D(i,i)*(norm(X(i) - S(i) - sumLs))^2;
end
end
function sumLs = sumLsf(i)
global L;
global S;
tempSum = 0;
for j = 1:i-1
tempSum = tempSum + L(i,j) * S(j);
end
sumLs = tempSum;
end

댓글 수: 3

Walter Roberson
Walter Roberson 2021년 12월 21일
You should avoid using global.
Question: where does the variable Si come from inside Muf, and why do you global S in Muf when you do not use that variable?
Caleb Goh
Caleb Goh 2021년 12월 21일
편집: Caleb Goh 2021년 12월 21일
I made a mistake in function Muf i have edit Si to S thanks for pointing out, I edited to pass arguments to the functions instead of accessing global variables
Alvin Ang
Alvin Ang 2021년 12월 21일
I am experiencing the same issues too, could someone point out whether the code written above is correct?

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

 채택된 답변

Voss
Voss 2021년 12월 21일
편집: Voss 2021년 12월 21일

1 개 추천

The sum over j depends on i, so you must call sumLsf each time through the i loop
function Mu = Muf(n, D, S, X, L)
Mu = 0;
for i = 1:n
sumLs = sumLsf(i, L, S);
Mu = Mu + D(i,i)*(norm(X(i) - S(i) - sumLs))^2;
end
end
function sumLs = sumLsf(i, L, S)
sumLs = 0;
for j = 1:i-1
sumLs = sumLs + L(i,j) * S(j);
end
end

댓글 수: 1

Caleb Goh
Caleb Goh 2021년 12월 22일
Thank you for correcting my mistake, but I implement on my sphere decoder it didn't work as expected maybe its my other code gave that error. I'll try to solve it

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

질문:

2021년 12월 21일

댓글:

2021년 12월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by