Each iteration of the for loop in the above code creates a new symbolic function "ss" which creates three different expressions. Also, in each iteration of the loop, since the value of “p” is constant, “J” is substituted by the same value.
You may use the following code instead to implement the summation
clear;
syms L(k)
P = repmat([10 20 30],1,3);
ss(k) = sum(P.*subs(L(k),k,1:9));
Hope this helps!!