Question

PLEASE HELP, MATLAB, answers are very appreciated need to study
2. Write two m-file functions that will allow you to compare mortgages cakculations for the monthly payment and compare mortgage with different loan values. The monthly payment M, is calculated using 1-2)1 Where Pis 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. Create an m-file function called mortgage_a.m that will serve as a loan calculator like the ones that you might find on-line). This function will have three inputs and two outputs. The three inputs in order need to be: mortgage amount (in Dollars), years to payoff loan (in years, and interest rate (in %). The outputs will be in the order returned: monthly payment and total of all payments. It should also output to the Command Window the text shown in Figure 2 for the following inputs: 150000, 30 and 4.25. (This is example output and your function should give correct values for other inputs.) Your monthly loan payment is $737.91 You wi1 have to make 360 monthl for a total cost of $265647.54 Figure 2: Loan Calculator Script Input and Output Format a. Create a second m-file function called mortgage bm will allow you to compare different loan amounts. This function will have two inputs and no outputs. The two inputs in order need to be: maximum mortgage amount (in Dollars), and interest rate (in %). You can modify your file from part a for this script. Although the function does not return any values, the function will output text to 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 payment 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 $105000 and an interest rate of 8%.(This is example output and your function should give correct values for other inputs Principal 15 year Payment 30 year Fayment 105000 100000 $95000 $2003.43 770.45 733.7 697.08 907.87 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 $ on principals and payments should all line up and there should be no space between the S and the number pl

0 0
Add a comment Improve this question Transcribed image text
Answer #1

2.

%Define the function mortgage_a
function [mlP, tCost] = mortgage_a(P, r, y)
%Calculate monthly payment
mlP = P*((r*(1+r)^(12*y)/((1+r)^(12*y)-1)));
  
%Calculate total payments
%Total number of months
tMonth = 12*y;
tCost = tMonth*mlP;
  
%Display the results
fprintf("Your monthly loan payment is $%0.2f\n", mlP);
fprintf("You will have to make %d monthly payment for a total cost of $%0.2f\n", tMonth, tCost);
end

Output:

MATLAB R2017a HOME PLOTS APPS Search Documentation Log In O Preferences Set Path Parallel ▼ New Variable Analyze Code Find Files Open Variable Run and Time Request Support Simulink Layout Add-Ons Hep New New Open Script ▼ Compare ImportSave Dato WorkspaceClear Workspace Clear Commands Clear Commands ▼ Learn MATLAB FILE ÷ ÷ H L. C:、Program Command Window FilesトMATLAB R2017a >type mCall Inputs for the calculation p = 100000; Y15 r = 0.005; Call for function mortgage - [H, tCost] = mortgageale, r, y); >>[M, tCost]-mortgage a (P, x, y): Your monthly loan payment is $843.86 You will have to make 180 monthly payment for a total cost of 151894.23 - O Type here to search то 21-09-2018 1)

b.

%Define the function mortgage_b
function mortgage_b(P, r)
j = 1;
y = 15;
for i = P:-5000:50000
%Calculate monthly payment
m(j) = i;
mlP15(j) = i*(r/12)/(1-(1+(r/12))^(-12*y));
j = j+1;
end
k = 1;
y = 30;
for i = P:-5000:50000
%Calculate monthly payment
mlP30(k) = i*(r/12)/(1-(1+(r/12))^(-12*y));
k =k+1;
end
  
%Display the results
fprintf("Principal\t15 year Payment\t30 year Payment\n");
for k=1:j-1
fprintf("$%d\t\t $%0.2f\t\t $%0.2f\n", m(k), mlP15(k), mlP30(k));
end

Output:

Add a comment
Know the answer?
Add Answer to:
PLEASE HELP, MATLAB, answers are very appreciated need to study pl 2. Write two m-file functions...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • USE MATLAB TO WRITE A CODE FOR THIS 2. Writ example 4.5% as 4.5) and the...

    USE MATLAB TO WRITE A CODE FOR THIS 2. Writ example 4.5% as 4.5) and the number of monthly payments (use the Calculate the down payment using the percent down payment e e a program that gets a cost, percent down payment, annual interest rate as a percent (for ntered, the loan amount (cost - own payment) and monthly interest rate as a decimal number -not a percent. Call your payment function to calculate the payment on the loan amount....

  • MATLAB!!! CAN SOMEONE SOLVE THIS PROBLEM ON MATLAB?? THANK YOU PART B: HOUSING LOAN CALCULATOR In this part of the assignment, you are expected to develop a program that calculates housing loan pay-...

    MATLAB!!! CAN SOMEONE SOLVE THIS PROBLEM ON MATLAB?? THANK YOU PART B: HOUSING LOAN CALCULATOR In this part of the assignment, you are expected to develop a program that calculates housing loan pay- ments based on compound interest formulas The program should prompt a user to input the amount borrowed (principal), p, the number of monthly payments, n, and an annual interest rate in R percent. The program should convert the annual interest rate R into a monthly interest rate...

  • %%Python Question%% get_min_payment() • Parameters ◦ the total amount of the mortgage (called the principal; should...

    %%Python Question%% get_min_payment() • Parameters ◦ the total amount of the mortgage (called the principal; should be a positive number) ◦ the annual interest rate (should be a float between 0 and 1) ◦ the term of the mortgage, in years (should be a positive integer; default value: 30) ◦ the number of payments per year (should be a positive integer; default value: 12) • Functionality ◦ Compute the minimum mortgage payment. Should use the formula A= Pr(1+r) n (1+r)...

  • i would like someto check these answers and see if they are right or wrong. if...

    i would like someto check these answers and see if they are right or wrong. if wrong please help 250,000 Mortgage Calculator Mortgage Interest Rate Periods Per year 6 % Mortgage Type (Year) 10 o Payment per period $2,775.51 1 Total principal and interest $333,061.51 12 Total Interest Paid $83,061.51 1 5 $2,109.64 $379,735.57 $129,735.57 3 0 $1,498.88 $539,595.47 $289,595.47 13 15 Mortgage Calculator 1250000 5 Mortgage 6 Interest Rate 7 Periods Per year 10.06 9 Mortgage Type (Year) 10...

  • Problem 1 In this problem, you will write two functions. The first function takes in a...

    Problem 1 In this problem, you will write two functions. The first function takes in a string and returns that string without any dashes. The second function takes in the first and last name and returns a string that is lastname_firstname and uses the previous function to remove any dashes (-) in the name. Note that you’ll be testing it by calling it from the command line; you’ll call it from a script in problem 3. Deliverables: Function file that...

  • Please help with this code For the following problem write a Matlab® script file with clear...

    Please help with this code For the following problem write a Matlab® script file with clear commentary for each line of code. Your script should: Load the data in the problem as a text file. Calculate the statistics using Matlab  functions. Solicit input from the user of the reading (for example, 137 degrees as stated in the problem). In another word, the reading should not be fixed in the script and has to be entered and saved from the command window...

  • I just need help with the last two answers. I am not sure why they were...

    I just need help with the last two answers. I am not sure why they were counted as incorrect? Thanks. Five years ago, Diane secured a bank loan of $380,000 to help finance the purchase of a loft in the San Francisco Bay area. The term of the mortgage was 30 years, and the interest rate was 9% per year compounded monthly on the unpaid balance. Because the interest rate for a conventional 30-year home mortgage has now dropped to...

  • Can you please solve this and show the steps Im using a financial calculator, so please...

    Can you please solve this and show the steps Im using a financial calculator, so please list the inputs. 2. Mr. and Mrs. Spirit purchased a $35,000 house 20 years ago. They took a 30-year mortgage for $30,000 at a 3% annual interest rate. Their bank, the First Amityville National Bank, has recently offered the Spirits two alternatives by which they could prepay their mortgage. The Spirits have just made their 20th annual payment. [A] Under the first alternative, the...

  • My library>CptS 111 home> 2.9: zyLab PA #1: Student Loan R oks zyBooks cat @Help/FAQ θ...

    My library>CptS 111 home> 2.9: zyLab PA #1: Student Loan R oks zyBooks cat @Help/FAQ θ Mohammed Al Shukaili 2.9 zyLabPA#1:Student Loan RepaymentCalculator For this assignment you wil write a program to calculate the monthly payments required to pay back a student loan You vill need to prompt the user for the following values Annual interest rate (as a percentage) Number of years to repay loan . and display the output in a readable form. Output should include Amount of...

  • Mortgage Analysis Part I You are planning to purchase a house that costs $480,000. You plan...

    Mortgage Analysis Part I You are planning to purchase a house that costs $480,000. You plan to put 20% down and borrow the remainder. Based on your credit score, you believe that you will pay 3.99% on a 30-year mortgage. Use the function “PMT” to calculate your mortgage payment. Calculate the total cost of the home purchase. (Down payment plus principal (loan amount) plus interest.) Calculate how much interest you will pay in total? Assume that you plan to pay...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT