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

Matlab problem Your roommate has borrowed $100,000 in student loans. The loan ch

ID: 3742878 • Letter: M

Question

Matlab problem

Your roommate has borrowed $100,000 in student loans. The loan charges a 6% annual interest rate, and interest charges are applied each month. In other words, every month the loan charges a 0.5% interest fee on the remaining balance. This means that the amount by which you reduce your balance each month is not the amount you pay, but your payment minus the monthly interest. Your roommate plans to pay your loan off by paying $1,000 per month. Write a program using loops and logic to calculate how long it will take to finish paying off the loan. Don’t get fancy and derive an analytic formula for compound interest payoff time. Just write a loop to track the balance over time, and break out when the balance gets to zero.

Explanation / Answer

Code:

% Defining the initial variables like principle
% amountm, percentage of interest and monthly
% installment to be paid
amount = 100000;
percentage = 0.5;
emi = 1000;
% variable to calculate months
months = 0;
% loop combined with conditional statement
% to check if the balance is zero or not
% if the amount is less than zero the while
% loop will automatically breaks
while(amount > 0)
% calculating the interest
interest = amount*(percentage/100);
% calculating monthly payment after
% deducting the interest
monthly_pay = emi-interest;
% checking the remaining amount and
% updating the amount needed to pay
balance = amount - monthly_pay;
amount = balance;
% Calculating the months it took to
% pay off the loan
months += 1;
end
% outputting the results
fprintf("It took %d months to pay off the loan completely. ",months);

Output:

It took 139 months to pay off the loan completely.