%CH02    Program for Chapter 2
%
% Illustrates compound interest

clf
dzero = 5;
r = 0.15;           % Compound interest rate
T = 5;              % 5 year period
m = 60;             % 60 months

for i = 1:m         % let i months elapse
    tval(i) = i/12; %time in years
    d(i) = dzero*(1+r*tval(i)/i)^i; %compound i times
end

trange = [0,tval];
drange = [dzero,d];

plot(trange,drange,'r*')
hold on
tcts = linspace(0,T,100);
dcts = dzero*exp(r*tcts);
plot(tcts,dcts,'b-')
grid on
xlabel('t')
ylabel('D(t)')
title('Compound versus Continuous Interest')
legend('Compound','Continuous',2)
