A Guide to MATLAB for Beginners and Experienced Users

We want to understand the relationships among the mortgage payment rate of a fixed rate mortgage, the principal (the amount borrowed), the annual interest rate, and the period of the loan. We are going to assume (as is usually the case in the United States) that payments are made monthly, even though the interest rate is given as an annual rate. Let's define
<b class="bold">peryear = 1/12; percent = 1/100;</b>
So the number of payments on a 30-year loan is
<b class="bold">30*12</b>ans = 360
and an annual percentage rate of 8% comes out to a monthly rate of
<b class="bold">8*percent*peryear</b>ans = 0.0067
Now consider what happens with each monthly payment. Some of the payment is applied to interest on the outstanding principal amount, P, and some of the payment is applied to reduce the principal owed. The total amount, R, of the monthly payment remains constant over the life of the loan. So if J denotes the monthly interest rate, we have R = J/ P + (amount applied to principal), and the new principal after the payment is applied is
where m = 1 + J. So a table of the principal still outstanding after n payments is tabulated as follows for a loan of initial amount A, for n from 0 to 6:
<b class="bold">symsmJPRAP=A;for n = 0:6, disp([n, P]), P = simplify(-R +...