
Hi Stefan
As per my understanding, you would like to generate the sum of a series of log functions l(x). To achieve the desired resut, the expressions generated for each element in the array g need to be summed manually without using symsum. Here's how it can be done in MATLAB.
syms x
n = 5;
g = 0:4;
total_sum = 0;
% Each element of g is looped through, and the expressions are summed
for i = 1:length(g)
l = g(i)*log(x) + (n-g(i))*log(1-x);
total_sum = total_sum + l;
end
disp(total_sum);
In MATLAB, vectorization can often lead to more efficient computations by eliminating explicit loops. In this case, the vectorization can be performed as follows.
l_vector = g .* log(x) + (n - g) .* log(1 - x);
total_sum = sum(l_vector);
disp(total_sum);
For more information regarding vectoriztion, kindly refer the following documentation -
I hope this resolves the issue.