% Matlab script to calculate the monthly payment table
P = 100000; % initial principal
r = (.04:0.00125:.06); % rate vector
i = r./12; % monthly rate vector
n = [5,10,20]; % term vector
% calculate interest for 5,10 and 20 years term
interest_n5 = (1+i).^(n(1).*12);
interest_n10 = (1+i).^(n(2).*12);
interest_n20 = (1+i).^(n(3).*12);
% calculate A = Principal * interest
MonthlyPaymentTable = ((P .* i)') .* ones(length(i),length(n));
% calculate the monthly amount for the 3 interest rates
MonthlyPaymentTable(:,1) = MonthlyPaymentTable(:,1) .* (interest_n5')./(interest_n5' - 1 );
MonthlyPaymentTable(:,2) = MonthlyPaymentTable(:,2) .* (interest_n10')./(interest_n10' - 1 );
MonthlyPaymentTable(:,3) = MonthlyPaymentTable(:,3) .* (interest_n20')./(interest_n20' - 1 );
% display the output month
disp(MonthlyPaymentTable);
%end of script
评论0