% interest_plot.m
%
%  Compute the sequence of values corresponding to the amount in a bank
%  account at an annual interest rate of r, starting at $1000 in 2017.
%  Save data in a list so it can be plotted.
%
rate = input ( 'Enter interest rate as a decimal, such as 0.04: ' );
year_end = input ( 'Enter the year after 2017 when we will stop: ' );

value_list = [];

for year = 2017 : year_end

  if ( year == 2017 )
    value = 1000.0;
  else
    value_old = value;
    value = ( 1.0 + rate ) * value_old;
  end
  fprintf ( '%d: $%.2f\n', year, value );

  value_list = [ value_list, value ];

end

plot ( year_start:year_end, value_list );
title ( 'Interest rate plot' )
grid;
xlabel ( '<-- Year -->' );
ylabel ( '<-- Big Bucks -->' );

