MATLAB: I need help for calculating mortgage for a homework problem

homeworkmortgagemortgage calculator

Here is the question:
If you take out a mortgage to pay for a $100,000.00 house, how much does it actually cost to make all the payments on the mortgage? Assume a 30-year mortgage at an annual interest rate of 3.92% and a monthly payment of $473.00. Use a while loop to calculate the following:
a. Amount of each monthly payment covering interest (going to change each month!)
b. Amount of each monthly payment covering principle (going to change each month!)
c. Create the following plots
i: Figure 1 – remaining principle as a function of time
ii. Figure 2 – principle and interest covered in individual payments (from a and b above) as a function of time (so two curves on one plot)
iii. Figure 3 – total principle paid off, total interest cost, and total mortgage cost as a function of time.
I need help on completing this matlab code for using a while loop. My constants so far are…
P = 100000; % Principal starting amount
M = 473; % monthly payments
i = 0.00326666; % monthly interest
Truthfully, you don't have to do the graphs for the problem, I can figure those out once the main code and while loop is completed.
Thanks in advance!!!

Best Answer

So I was able to figure out what I needed to do. This is my work...
P = 100000; % Principal starting amount
M = 473; % monthly payments
i = 0.00326666; % monthly interest
t = 360; % months for how long I pay the loan off
k = 1;
while k <= t
interest(k) = i*P(k)
payment(k) = M - interest(k)
P(k + 1) = P(k) - payment(k)
k = k + 1;
end
Now I just have to graph.