Results 1 to 4 of 4

Math Help - [SOLVED] Maple Programming (1)

  1. #1
    Rhymes with Orange Chris L T521's Avatar
    Joined
    May 2008
    From
    Santa Cruz, CA
    Posts
    2,844
    Thanks
    3

    [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
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Senior Member
    Joined
    Feb 2008
    From
    Berkeley, Illinois
    Posts
    364
    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.
    Last edited by mathceleb; August 26th 2008 at 10:44 AM.
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Rhymes with Orange Chris L T521's Avatar
    Joined
    May 2008
    From
    Santa Cruz, CA
    Posts
    2,844
    Thanks
    3
    Quote Originally Posted by mathceleb View Post
    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
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Senior Member
    Joined
    Feb 2008
    From
    Berkeley, Illinois
    Posts
    364
    You did a nice job with blocking off sections with comments, and the way you organized things. Great work!
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 0
    Last Post: November 30th 2011, 02:25 PM
  2. Maple Programming Problem
    Posted in the Math Software Forum
    Replies: 1
    Last Post: September 16th 2011, 04:30 PM
  3. Maple programming advice
    Posted in the Math Software Forum
    Replies: 0
    Last Post: November 2nd 2009, 12:39 AM
  4. Maple Programming Tutorial
    Posted in the Math Software Forum
    Replies: 0
    Last Post: November 5th 2008, 10:04 PM
  5. [SOLVED] Maple - HELP PLEASE!
    Posted in the Math Software Forum
    Replies: 1
    Last Post: December 22nd 2007, 02:03 PM

Search Tags


/mathhelpforum @mathhelpforum