:

## A little financial math with recursion and plotting.

Consider the problem of borrowing \$250,000 to buy a house.  You borrow the money at a fixed interest rate of 4.8% compounded monthly.  The term of the mortgage is for 20 years.  However, you decide against making minimum payments.  Instead you decide to pay an additional \$200 every month.  How long will it take you to pay off the loan and how much have you saved on interest by paying off the loan early?

 > .048/12;
 (1)
 > Typesetting:-RuleAssistant();
 > .048/12;
 (2)
 > with(Finance,annuity);
 (3)
 > 20*12;
 (4)
 > solve(annuity(payment,0.004,240)=250000,payment);
 (5)
 > payment:=(5);
 (6)
 > Payment:=payment+200;
 (7)
 > balance:=[250000];
 (8)
 > Balance:=[250000];
 (9)
 > for n to 240 do a:=nops(balance): b:=1.004*balance[a]-payment: balance:=[op(balance),b]: end do: a:='a': b:='b': nops(balance);
 (10)
 > balance[241];
 (11)
 > for n to 240 do a:=nops(Balance): b:=1.004*Balance[a]-Payment: Balance:=[op(Balance),b]: end do: a:='a': b:='b': nops(Balance);
 (12)
 > balance[241];
 (13)
 > Balance[241];
 (14)
 > balance2:=[seq([n-1,balance[n]],n=1..241)];
 (15)
 > Balance2:=[seq([n-1,Balance[n]],n=1..241)];
 (16)
 > with(plots):
 > plot1:=listplot(balance2,color=black,thickness=3,gridlines=true,tickmarks=[[seq(40*n,n=0..6)],[seq(25000*n,n=-3..10)]],font=[Helvetica,Bold,9]):
 > plot2:=listplot(Balance2,color=red,thickness=3,gridlines=true,tickmarks=[[seq(40*n,n=0..6)],[seq(25000*n,n=-3..10)]],font=[Helvetica,Bold,9]):
 > display(plot1,plot2);
 > payment;
 (17)
 > Payment;
 (18)
 > balance2[241];
 (19)
 > Balance2[201];
 (20)
 > 240*payment-250000;
 (21)
 > 200*Payment-250000;
 (22)
 > (21)-(22);
 (23)

By paying an additional \$200 every month, you have reduced the cost of the loan by almost \$25,000.  Not bad!  That's actually a pretty big savings, especially in today's dubious economy.