EE342.01: MATLAB M-FILE FOR PLOTTING A DISCRETE-TIME SIGNAL

MATLAB M-File payments.m:
%
%  Filename:  payments.m
%
%  Description:  This matlab m-file computes monthly loan payments
%                given the amount borrowed, the number of months
%                financed, and the annual interest rate.  It then
%                plots the principle and payments as a discrete-time
%                signal.
%

P  = input('Enter amount borrowed:  ');
N  = input('Enter number of months financed:  ');
iy = input('Enter the annual interest rate in percent:  ');

im = iy/(12*100);                      % compute monthly interest rate 
                                       % not in percent
                                       
A = P*((im*(1+im)^N)/((1+im)^N-1));    % compute payment amounts

n  = 0:N;                              % define time periods (months here)

CF = [P -A*ones(1,N)];                 % compute discrete-time signal
                                       % representing cash flow

stem(n,CF);                            % plot cash flow as a discrete-time
                                       % signal

xlabel('n');                           % label plots
ylabel('cash flow');
title('Plot of Loan Cash Flow');
Run payments.m by typing payments at the matlab prompt after saving it in a working directory:
>> payments

Enter amount borrowed:  1000

Enter number of months financed:  12

Enter the annual interest rate in percent:  16.9
MATLAB Plot Generated:

The plot was printed by typing 'print' at the matlab prompt when the plot was displayed in the graphics window.