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

This is a MATLAB program It is desired to create a mortgage estimator by writing

ID: 3861386 • Letter: T

Question

This is a MATLAB program

It is desired to create a mortgage estimator by writing a program containing a function. The user inputs the amount of loan (L), the loan term in number of months (W, and the annual interest rate (D in the script. The script then makes use of a function that accepts these values as inputs through its argument and calculates and returns the monthly payment and the total payments over the life of the loan. The monthly payment and the total payment could be calculated using the following expressions: monthly payment 1-(1+ 1 112) N I/12 total payment Nxmonthly payment Note that the interest rate must be expressed in decimal; for example, if the interest rate is 8% it must be entered as 0.08 Test your program for several scenarios and submit the results with the program listing. The values of L, I, monthly payment, and total payment should be written to a file as shown below: Loan Amount Interest Months Monthly Payment Total Payment 0.06 10000 36 108 120000 0.05 0.07 85000 48 257000 0.08 240 320000 120 0.05

Explanation / Answer

Matlab function MortgageEstimator.m

function MortgageEstimator()
% Prompting the user to enter a list of values for Loan Amount
   L = str2num(input('Enter the value of Loan Amount (Give a space after each Loan Amount): ','s'));
   n = length(L); % Number of loan amounts in the list
   for k =1:n
       % Prompting the user to enter the Interest rate
       fprintf('Enter the Interest rate for the Loan Amount %d ',L(k));
       I(k) = input(':');
       % Prompt the user to enter a list of values of Months
       fprintf('Enter the Loan term in number of months for the Loan Amount %d ',L(k));
       N(k) = input(': ');
   end
   % Calculate the monthly payment
   Monthly_Payment = L./((1-(1+I./12).^(-N))./(I./12));
   % Caluclate the Total payment
   Total_Payment = N.*Monthly_Payment;
   % Open the file for printing the results
   fp = fopen('MortgageEstimator.txt','w');
   % Printing the details to the file
   fprintf(fp,'Loan Amount Interest Months Monthly payment Total Payment ');
   fprintf(fp,'%d %0.2f %d %0.2f %20.2f ',[L; I; N; Monthly_Payment; Total_Payment]);
   % Open the file MortgageEstimator.txt to view the result
end

Input to the function

>> MortgageEstimator
Enter the value of Loan Amount (Give a space after each Loan Amount): 10000 120000 85000 257000 320000
Enter the Interest rate for the Loan Amount 10000
:0.06
Enter the Loan term in number of months for the Loan Amount 10000
: 36
Enter the Interest rate for the Loan Amount 120000
:0.05
Enter the Loan term in number of months for the Loan Amount 120000
: 108
Enter the Interest rate for the Loan Amount 85000
:0.07
Enter the Loan term in number of months for the Loan Amount 85000
: 48
Enter the Interest rate for the Loan Amount 257000
:0.08
Enter the Loan term in number of months for the Loan Amount 257000
: 240
Enter the Interest rate for the Loan Amount 320000
:0.05
Enter the Loan term in number of months for the Loan Amount 320000
: 120
>>

Content in the file MortgageEstimator.txt after execution of the function

Loan Amount   Interest   Months   Monthly payment   Total Payment
10000       0.06       36   304.22             10951.90
120000       0.05       108   1382.07            149263.86
85000       0.07       48   2035.43             97700.68
257000       0.08       240   2149.65            515916.23
320000       0.05       120   3394.10            407291.58

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote