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

Printable View

- September 23rd 2008, 01:01 PMJuancd08Flop counting
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 - September 23rd 2008, 02:25 PMGrich
first, what language is it?

- September 23rd 2008, 02:51 PMCaptainBlack
- September 23rd 2008, 08:55 PMCaptainBlack
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