0

Is it possible for someone to make this algorithm easy to understand to enter into a calculation for my application.

Algorithm

Thanks

To explain:

Description of Algorithm

3
  • That's a straightforward formula that uses basic arithmetic operations. What part don't you understand? Commented Mar 6, 2011 at 18:25
  • It also depends on what language you're using. Commented Mar 6, 2011 at 18:26
  • I'm going to be coding with Objective C, so if i read it through, well I'm just looking at the equation and can't figure a way to express it in code. Commented Mar 6, 2011 at 18:29

3 Answers 3

1

Yes that algorithm most certainly can be expressed in a programming language, however I will not provide an implementation, but some pseudocode to get you started.
So the first thing we see is x is dealing with money so lets represent that as a double

double monthlyPayment //this is X

next we see that P sub 0 is the total loan amount so lets also represent that as a double

double loanAmount // this is P sub 0  

next we see that i is the interest rate so this will also be a double

double interestRate // this is i

next we see that n is the number of months that remain on the loan this is an integer

int monthsRemaining // this is n

so looking at the formula you proposed we take the following:

monthlyPayment = (loanAmount * interestRate) /  1 - (1 + interestRate) ^ (-1 * monthsRemaining)

Now without actually implementing this I do believe you can take it from here.

Sign up to request clarification or add additional context in comments.

1 Comment

That helps a lot thankyou, I just needed a way to see how the equation can be expressed and this helps a lot. Thanks again.
0

This is how you could represent it using Javascript:

function repayment(amount, months, interest) {
    return (amount * interest) / (1 - Math.pow(1 + interest, -months));
}

1 Comment

Perhaps because I chose to express it in Javascript... OP has since added a comment that he’s looking for Objective C. But it would have been nice to know for certain.
0

Are you looking for an explanation of the equation? It deals with loans. When you take out loans, you take out a certain amount of money (P) for a certain number of months (n). In addition, to make the loan worth while to the loaner, you are charged an interest rate (i). That's a percentage that you are charged every month on the remaining loan amount.

So, you need to calculate how much you have to pay each month (x) in order to have the loan paided off in the set amount of time (n months). It's not as simple as just dividing the loan amount (P) by the number of months (n) because you also have to pay interest.

So, the equation is giving you the amount of money you have to pay each month in order to pay off the original loan plus any interest.

If you're using Java:

public double calculateMonthlyPayment(double originalLoan, double interestRate, double monthsToRepay) {
        return (originalLoan*interestRate)/(1-(Math.pow((1+interestRate), -monthsToRepay)));
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.