How to calculate compound interest?

22 views (last 30 days)
Alex Bragg
Alex Bragg on 4 Oct 2016
Commented: Kevin on 16 Oct 2022
A person deposits $1000 in a bank. Interest is compounded monthly at the rate of 1% per month. I'm trying to write a program that will compute the monthly balance, but only on an annual basis, for 10 years. I want too vectorize it if possible. I've heard about using nest loops but I don't know how. I
  2 Comments
Adam
Adam on 5 Oct 2016
Work out any solution first, then when it works improve it afterwards. For people experienced in that going straight for a vectorised approach makes sense, but for others doing a solution with for loops and understanding how that works before converting it to a vectorised approach is easier.

Sign in to comment.

Answers (5)

Alexandra Harkai
Alexandra Harkai on 5 Oct 2016
Vectorizing it would be smart, this page says it all: https://uk.mathworks.com/help/matlab/matlab_prog/vectorization.html

Thorsten
Thorsten on 5 Oct 2016
If you have amount A at an interest rate of r, you have after one month
A + rA = A(1 + r)
after two months
A(1+r) + rA(1+r) = A(1+r)(1+r) = A(1+r)^2
after three months
A(1+r)^2 + rA(1+r)^2 = A(1+r)^2(1+r) = A(1+r)^3
So after n month you have
A(1+r)^n
And after N years you have
A(1+r)^(N*12)
in your case
1000 * (1.01)^120 = 3300.39
So with some basic math you can directly compute the solution without any need for loops or vectorisation.

SUDHARSHAN REDDY MARUDI
SUDHARSHAN REDDY MARUDI on 1 May 2020
1000 * (1.01)^120 = 3300.39

SURAJ PATIL
SURAJ PATIL on 16 May 2020
Edited: Walter Roberson on 16 May 2020
x=1000;
y=0.1;
t=2;
d=x*(1+y)^t;

Fardin Khan
Fardin Khan on 18 Aug 2021
A person places $20,000 in a savings account which pays 5 percent interest perannum, compounded continuously. Find
(a) the solution of the dollar balance in the account at any time

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!