I need to know how many flops does this code have and where
function s=kahan(x)
n=length(x); sm=0; dif=0;
for k=1:n;
y=x(k)-dif;
temp=sm;
sm=temp+y;
dif=(sm-temp) - y;
end
There are 3 fp assignments before the loop, and an, then for each itteration of the loop there are 4 assignments and 4 additions, plus whatever overhead there is for the loop increment and test.
So the flpop count is approximatly 4n possibly as much as 5n.
Of course this function does nothing as the return value is never assigned.
RonL