In matlab create a while loop for the following: Suppose that the Jones family b
ID: 2081668 • Letter: I
Question
In matlab create a while loop for the following:
Suppose that the Jones family borrows $420,000 to buy a house. The bank charges 6% annual interest on the unpaid balance, compounded monthly. If the Jones's pay $3000 at the end of each month, how long will it take them to pay of the loan, and what will the amount of their last payment be? Their last payment will just cover the unpaid balance so will likely be less than $3000. (B) If, in entering a while loop to solve this problem you accidentally typed 4200000 (rather than 420000); i.e., you added an extra zero to the loan amount. Explain what would happen. If you don't know what would happen, try it out.Explanation / Answer
Copy the following code to a new script in MATLAB.
close all; clear all; clc;
p = 420000; % initial amount
a = p; % a is the unpaid balance
inta = 0; % int is the interest on unpaid balance
i = 0;
while (a>=3000);
inta = a*((1+6/100)^(1/12)) - a;
a = a+inta-3000; % unpaid balance at the end of each month
i=i+1;
end
fprintf('Time Taken = %d months ',i+1);
fprintf('Last payment = $%.2f ',a);
% Part b
b = 4200000;
j = 0;
intb=0;
while (b>=3000);
intb = b*((1+6/100)^(1/12)) - b;
b = b+intb-3000; % unpaid balance at the end of each month
j=j+1;
end
fprintf('Time Taken = %d months ',j+1);
fprintf('Last payment = $%.2f ',b);
% It is observed that the amount to be paid keeps increasing while the rate
% of repayment is $3000/month. The while loop execution is stopped once the
% amount to be repayed increases to a value that is beyond the storage
% capacity of 'double' data type.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.