function z=invest(x,r) % Example loop program to debug from Palm Chapter 4. % This program is designed to calculate the value of a series % of annual investments % inputs: x = a vector of annual investment values (dollars) % r = annual interest rate (%) % output: z = balance at the time of the last investment (dollars) z=0; y=1 + 0.01*r; for k=1:length(y) z=z*y+x(k); end