Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB Cody Coursework An amortization table shows how a loan debt is paid off i

ID: 3723936 • Letter: M

Question

MATLAB

Cody Coursework

An amortization table shows how a loan debt is paid off in monthly payments over the term of a the loan. For each monthly payment, the amount paid toward interest and the amount paid toward principal varies as the principal reduces over time. The table calculation breaks down each payment into the interest and principal reduction and also indicates the outstanding principal balance. This is repeated for the duration of the loan term until the principal value is zero.

An example amortization table for a $5000 loan with a two year term and an annual interest rate of 5.25% is shown below:

This table can be generated as follows:

1. For a term loan with initial principal (total loan amount) value of P, the monthly payment can be computed with the formula:

Where i is the monthly interest rate (decimal value), computed from an annual rate r as i = r/12, and n is the number of months in the term of the loan.

2. For each month, the interest that accumulates must be paid in full before any portion of the payment is applied toward the principal balance. The interest due is calculated using the monthly interest rate i as

3. The remaining portion of the monthly payment is applied to reduce the principal balance.

4. Steps 2 and 3 are repeated each month for the duration of the term of the loan. The outstanding principal balance is $0.00 after the last payment is applied, as shown in the table above.

Write a function that accepts the following three scalar inputs (in order):

The loan principal

The annual interest rate

The loan term

Your function should use the values of these three input arguments to compute and output the monthly payment and generate data for an amortization table that is output in three column vectors. The function outputs should be (in order):

A scalar variable with the monthly payment amount

A column vector of the monthly interest

A column vector of the amount applied toward principal each month

A column vector of the outstanding loan balance at the end of each month

Note: all four outputs should be default double precision numeric data type. Do not format as currency.

#FUNC

Month Interest Principal Balance $21.87 $ 198.04 4801.96 $21.01$ 198.914603.05 $ 20.14$ 199.78 4403.27 $ 19.26 200.65 4202.62 $18.39 201.53 4001.09 $17.50 202.41 3798.67 $16.62 203.30 3595.38 $15.73 204.19 3391.19 $14.84 205.08 3186.11 $13.94 205.98 2980.13 $13.04 206.88 2773.25 $12.13 207.78 2565.47 $11.22 208.69 2356.77 $ 10.31 209.61 2147.17 $ 9.39 210.52 1936.64 $8.47 211.44 1725.20 $7.55 212.37 1512.83 $ 6.62 213.30 1299.53 $ 5.69 214.23 1085.30 $4.75$ 215.17 870.13 $3.81 216.11 654.02 $2.86 217.06436.96 $1.91 218.01 218.96 $0.96 218.96$ 0.00 12 13 15 16 17 18 19 21 23

Explanation / Answer

% Matlab function to calculates and returns the monthly payment, interest, principal and
% balance for a given loan amount, annual interest and annual term


function [monthlyPayment, monthlyInterest,monthlyPrincipal, loanBalance] = loanAmortizationTable(principal,interest,term)
interest_monthly = interest/1200; % convert annual interest to monthly interest
term_monthly = term*12; % convert time in years to months
monthlyInterest = zeros(term_monthly,1);
monthlyPrincipal = zeros(term_monthly,1);
loanBalance = zeros(term_monthly,1);
  
% calculate monthly payment
monthlyPayment = principal*((interest_monthly*((1+interest_monthly)^term_monthly))/(((1+interest_monthly)^term_monthly)-1));
% loop to calculate the interest, principal and balance after
% each month
for i=1:term_monthly
if i==1
monthlyInterest(i) = interest_monthly * principal;
monthlyPrincipal(i) = monthlyPayment - monthlyInterest(i);
loanBalance(i) = principal - monthlyPrincipal(i);
else
monthlyInterest(i) = interest_monthly * loanBalance(i-1);
monthlyPrincipal(i) = monthlyPayment - monthlyInterest(i);
loanBalance(i) = loanBalance(i-1) - monthlyPrincipal(i);
end
end
  
end

% end of function