How to calculate compound interest?
Afficher commentaires plus anciens
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 commentaires
Adam
le 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
le 16 Oct 2022
Ok I'll try that
Réponses (5)
Alexandra Harkai
le 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
le 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
le 1 Mai 2020
0 votes
1000 * (1.01)^120 = 3300.39
SURAJ PATIL
le 16 Mai 2020
Modifié(e) : Walter Roberson
le 16 Mai 2020
x=1000;
y=0.1;
t=2;
d=x*(1+y)^t;
Fardin Khan
le 18 Août 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 commentaire
Walter Roberson
le 18 Août 2021
No, this is not a solution to the problem.
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!