MATLAB: Summation in matlab with for loop

for loopMATLABsummation

how can i write the code for the following equation using for loop and summation. here the bold and the underlined part of the equation has to be summed up with change in the i values and the end -i will be the highest constant of n.
W = (kappa*T_in)/(kappa-1)*(((P(i+1)/P(i))^((kappa-1)/kappa))-i);

Best Answer

Is it a running sum? In this case something like this, then the i'th entry in runningsum will be the sum of all previous iteration plus the current iteration.
n=100; %lets say you run 100 runs
runningsum=zeros(n,1);
for i=1:n
W(i) = (kappa*T_in)/(kappa-1)*(((P(i+1)/P(i))^((kappa-1)/kappa))-i);
runningsum(i)=sum(runningsum)+((P(i+1)/P(i))^((kappa-1)/kappa));
end