How to calculate compound interest?

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

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.
Ok I'll try that

Sign in to comment.

Answers (5)

Vectorizing it would be smart, this page says it all: https://uk.mathworks.com/help/matlab/matlab_prog/vectorization.html
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.
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 Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 4 Oct 2016

Commented:

on 16 Oct 2022

Community Treasure Hunt

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

Start Hunting!