Summation function to calculate Mu
Show older comments

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 Comments
Walter Roberson
on 21 Dec 2021
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?
Alvin Ang
on 21 Dec 2021
I am experiencing the same issues too, could someone point out whether the code written above is correct?
Accepted Answer
More Answers (0)
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!