function v = npv(cf,r)
## Function v = npv(cf,r) returns the Net Present Value (npv) of the 
## cash flow cf.  The cash flow cf is received at the end of each 
## period.  The  rate of return over the period is r.  The parameter r 
## is scalar.  The cash flow cf is a (column) vector.

T = length(cf);                 # The number of periods.
pv = zeros(T,1);                # Initialize present values (pv) at zero.
for t=1:T                            
  pv(t) = cf(t) / (1+r)^t;      # Set the pv's.
endfor 
v = sum(pv);                    # npv is the sum of pv's.
endfunction
