MATLAB: Summation inside a “for loop”

summation command

Hi I have a 100×100 matrix, A. I am doing the following:
q=0:0.1:50;sym k;
for j=1:length(q)
B1(j)=sum(exp(q(j)*A(k,1)), k=1..100);
end
for j=1:length(q)
B2(j)=sum(exp(q(j)*A(k,2)), k=1..100);
end
..................................
..................................
for j=1:length(q)
B100(j)=sum(exp(q(j)*A(k,100)), k=1..100);
end
The problem is perhaps with the command but I tried with both sum/symsum and some other variations. But always matlab gives one or the other error.
It would be very helpful if someone could suggest some "correct" command. Thanks a ton.

Best Answer

I would expect this to work:
B = zeros(length(q), size(A,2));
for j = 1:length(q)
B(j,:) = sum( exp(q(j)*A) );
end
Related Question