How to calculate compound interest?
Show older comments
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
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.
Kevin
on 16 Oct 2022
Ok I'll try that
Answers (5)
Alexandra Harkai
on 5 Oct 2016
0 votes
Vectorizing it would be smart, this page says it all: https://uk.mathworks.com/help/matlab/matlab_prog/vectorization.html
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
on 1 May 2020
0 votes
1000 * (1.01)^120 = 3300.39
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
on 18 Aug 2021
0 votes
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
1 Comment
Walter Roberson
on 18 Aug 2021
No, this is not a solution to the problem.
Categories
Find more on Loops and Conditional Statements 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!