In: Computer Science
Language: matlab
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 (N), and the annual interest rate (I) 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:
m o n t h l y − p a y m e n t = L /(( 1 − ( 1 + I/ 12 ) ^(− N)} /( I /12 ) )
t o t a l − p a y m e n t = m o n t h l y − p a y m e n t ( N )
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, N, I, monthly_payment, and total_payment should be written to a file as shown below (payments should have only two decimal places):
Loan Amount Interest Months Monthly Payment Total Payment
10000 0.06 36 …. ….
120000 0.05 108 …. ….
85000 0.07 48 …. ….
257000 0.08 240 …. ….
320000 0.05 120 …. ….
Submit a copy of the script file, the function file, and the output file containing the above tabular output.
could you type code for each file(script,function, and output)
`Hey,
Note: If you have any queries related to the answer please do comment. I would be very happy to resolve all your queries.
clc
clear all
close all
format long
L=input('Enter loan amount: ');
R=input('Enter rate of interest: ');
N=input('Enter number of months: ');
M=getMonthly(L,R,N)
fid = fopen('out.txt', 'a+');
fprintf(fid, '%d\t%.2f\t%d\t%.2f\t%.2f\n', L,R/100,N,M,M*N);
fclose(fid);
function M=getMonthly(L,R,N)
r=R/N;
M=L/((1-(1+r/12)^(-N))/(r/12));
end
Kindly revert for any queries
Thanks.