Paying off an installment

Using Annuity:

pmt /.Solve[TimeValue[Annuity[pmt, 52, 1], .02, 0] == 5000, pmt]

155.545

Exercise left for the reader...

Mathematica graphics


The general formula can be derived as follows.

First@RSolve[{prin[n] == (1 + int) prin[n - 1] - pay, prin[0] == loan}, prin[n], n];
First@Solve[(prin[n] /. %) == 0, pay]
(* {pay -> (int (1 + int)^n loan)/(-1 + (1 + int)^n)} *)

where pay is the payment per period, int is the interest per period, and loan is the original principal.

For the example given in the question,

pay /. % /. {n -> 52, loan -> 5000, int -> .02}
(* 155.545 *)

and the total amount needed to pay off the loan is 8088.36.


Just to show how to fix the origional loop:

amt = 5000;
interestrate = .02;
nlast = 52;
Do[interest = amt*interestrate;
  amt = Simplify[amt + interest - inst], {n, 1, nlast, 1}];
Solve[amt == 0, inst]

inst -> 155.545

Note the Simplify is important here, without it amt looks like this after just 4 weeks..

     5100. + 0.02 (5100. + 0.02 (5100. + 0.02 (5100. - inst) - 2 inst) + 
0.02 (5100. - inst) - 3 inst) +  0.02 (5100. + 0.02 (5100. - inst) - 2 inst) + 0.02 (5100. - inst) -  4 inst

It is correct but will be horribly slow even if you don't try to print it.