Question: Write two m - file functions that will allow you to compare mortgage calculations for the monthly payment and compare mortgages with different loan values.

Write two m-file functions that will allow you to compare mortgage calculations for the monthly
payment and compare mortgages with different loan values.
The monthly payment M, is calculated using:
M=P*(r12)1-(1+r12)-12y
Where P is the principal loan amount, r is the interest rate (in decimal form not percent form), and y Is the number of years of the loan.
a. Create an m-file function called "mortgage_a.m" that will serve as a loan calculator (like the
ones you might find online). This function will have three inputs and two outputs. The three
inputs in order are mortgage amount (in Dollars), interest rate (in %), and years to pay off the
loan (in years). The outputs will be in the order returned: monthly payment and total of all
payments. If the Term is not input, it is assumed to be 30 years. An example output of the
function is shown in Figure 2. Note: Your function will be checked with other input values whe graded.
>[mp,tp]= mortgage a(200000,7.5,30)
mp=
1398.43
tp=
503434.45
Figure 2: Loan Calculator Script Input and Output
b. Create a second m-file function called "mor ryage_b.m" that will allow you to compare
different loan amounts. This function will have two inputs and no outputs. The two inputs in
order are: the maximum mortgage amount (in Dollars), and interest rate (in %). You can modif your file from part a for this script. Although the function does not return any values, it will
output a Table in the Command Window. Your script needs to create a loan amount vector with
a range of loan amounts (principal) from the maximum mortgage amount down to $50,000 less in principal in $5,000 increments. Calculate the monthly payments for both 15 and 30 year
payback plans based on the varying initial amounts for the principal. An example of the
truncated output is shown in Figure 3 for a maximum mortgage amount of $200000 and an
interest rate of 7%.(This is example output and your function should give correct values for
other inputs.)
Figure 3: Loan Calculator Table Script Input and Output Format
Note: The output should continue subtracting $5000 from the principal on each new row until it
has subtracted $50000 from the cost of the house. The . decimals on principals and payments should all line up for principals up to $99,999,999. Your function should still have all the dollar signs in the Table aligned for larger or smaller loan amounts.
Write two m - file functions that will allow you

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!