# Math Help - [SOLVED] Maple Programming (1)

1. ## [SOLVED] Maple Programming (1)

I'm not sure this is the proper place to post this, but I may have Maple programming questions in the future...where should I post them?

I'm taking a math class where Maple programming is taught. I love the class, and I'm currently working on the first assignment, but I just want to make sure I interpreted the question properly and coded this correctly.

Here is the question.

A mortgage problem Let $$A$ be the amount of a mortgage, $n$ the total number of payments, $i$ the interest rate per period of payment. Then the mortgage payment$ $R$ per period is given by the formula:

$R =\frac{A i}{1 - (1 + i)^{(-n)}}$.

• Write a program that, for input: $p$, $r$, $y$, $d$ as price of the purchase,
annual percentage interest rate, number of years, and down payment
percentage respectively, calculates and prints the monthly payment
amount.

The only thing I wasn't sure about was how to apply the initial down payment. I took a guess at it, and this is how I programmed it:

Code:
mortgage := proc(p,r,y,d)

local mon_pay, in_down;   # Declaring Local variables for initial
# down payment and monthly payment

# Defining in_down

in_down := evalf( p * d );  # initial down payment with a rate of d%

# Defining mon_payment

mon_payment := evalf( in_down + ( (p*r) / (1-(1+r)^(-y) ) );

# Display monthly payment

return mon_payment;

end proc;
Does this look right to you?

Thanks for any input!

--Chris

2. I'd do 2 things. First, the formula for a payment on a standard mortgage is

Loan Amount / a[n] where a[n] = (1 - (1/1+i)^n)/i

I'd set a variable v where v = 1/(1+i). Make every portion of the equation a variable so if you have to change things, 1 change makes all changes.

Secondly, Your Loan amount should be the inital price of the house minus the down payment. You could have a variable for initial loan and then down payment, number of months from the # of years input you have. Make interest rate a variable as well as months. See here:
Mortgage Payment Calculator

That will show you the entire math behind a standard monthly mortgage. It's written in javascript, but we could always convert that quickly to Maple. Let me know if you have questions.

If others besides yourself will be using this, you may want to account for user error on inputs, such as text and negative inputs since no input on a home loan should be negative. How is your interest rate coming down? Is 5.5% going to be entered like 5.5%, 5.5, or 0.055? In general, if others are using this, it's best to make it as simple as possible for them, and you handle the automation.

I'm not sure if Maple has code that respects Regex; If they do, that's something that would take care of most of the above in one quick move.

3. Originally Posted by mathceleb
I'd do 2 things. First, the formula for a payment on a standard mortgage is

Loan Amount / a[n] where a[n] = (1 - (1/1+i)^n)/i

I'd set a variable v where v = 1/(1+i). Make every portion of the equation a variable so if you have to change things, 1 change makes all changes.

Secondly, Your Loan amount should be the inital price of the house minus the down payment. You could have a variable for initial loan and then down payment, number of months from the # of years input you have. Make interest rate a variable as well as months. See here:
Mortgage Payment Calculator

That will show you the entire math behind a standard monthly mortgage. It's written in javascript, but we could always convert that quickly to Maple. Let me know if you have questions.

If others besides yourself will be using this, you may want to account for user error on inputs, such as text and negative inputs since no input on a home loan should be negative. How is your interest rate coming down? Is 5.5% going to be entered like 5.5%, 5.5, or 0.055? In general, if others are using this, it's best to make it as simple as possible for them, and you handle the automation.

I'm not sure if Maple has code that respects Regex; If they do, that's something that would take care of most of the above in one quick move.
That solves my problem!

Also, no one will be using this. My professor assigned this as an assignment so we can get used to programming in maple. The only thing I wasn't quite sure about in the program was how to apply the down payment.

As the semester progresses, he will start being picky with errors and the such. For now, he just wants to see if we understand programming

[...and yes, I could make the code more complex to include your suggestions, but I don't want to wow him...yet...]

--Chris

4. You did a nice job with blocking off sections with comments, and the way you organized things. Great work!