compound interest using for loop

£1000 was deposited in a bank account that pays 4% interest annually. The balance will grow as follows: balance = current balance + 0.04*(current balance)
a) use for loop to calculate account balance from year 1 to year 20
b) plot of annual balance from year 1 to year 10, adding axis to the graph
c)print to the screen the balance (2 d.p) at year 10
your message should displace " your account balance after 10 Years is £1480.24"

5 comentarios

Guillaume
Guillaume el 31 de Mzo. de 2017
So, what efforts have you made towards writing the 6 lines or so required to solve this extremely easy homework?
Harry Chichi
Harry Chichi el 31 de Mzo. de 2017
i've tried but i can't seem to get the loop right. the code when run goes all the way to infinity.
Guillaume
Guillaume el 31 de Mzo. de 2017
Steven Lord
Steven Lord el 31 de Mzo. de 2017
Show us what you've written and we may be able to point out the problem that's causing your loop to run infinitely.
Adam
Adam el 31 de Mzo. de 2017
If you are going to edit away your questions after they get answered then don't expect people to be in a hurry to answer your future questions.
People are more than willing to help when you show some effort, but this forum is for people to be able to search and find existing answers to questions they have also. That isn't possible if people just edit away their question as soon as they have been given an answer and it annoys those who gave their time to provide that answer.

Iniciar sesión para comentar.

Respuestas (1)

Guillaume
Guillaume el 31 de Mzo. de 2017
Editada: Guillaume el 31 de Mzo. de 2017

0 votos

1) You were asked to use a for loop, not a while loop.
2) While you could indeed use a while loop, that loops must end after 20 years. Your loop runs while the balance is greater than 20. This is of course forever since the balance start greater than 20 and keeps growing.

4 comentarios

Harry Chichi
Harry Chichi el 31 de Mzo. de 2017
Can you please elaborate on point 2, how would I change the code to alter with reference to the number of years rather than the current balance?
Thanks
Guillaume
Guillaume el 31 de Mzo. de 2017
Well, which variable do you use to count the years? Make sure that it stays under 20 in the while loop by translating while numberofyears is less than or equal to 20 into matlab code. It's not that hard.
Steven Lord
Steven Lord el 31 de Mzo. de 2017
Use the plot function.
Elisabeth Quan
Elisabeth Quan el 27 de Sept. de 2021
why are the "experts" on this site so rude and dismissive?! i.e.: Guillaume saying "it's not that hard." Maybe it's not that hard FOR YOU because this is a subject that you understand, but this language is very counterintuitive and frustrating.

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Preguntada:

el 31 de Mzo. de 2017

Comentada:

el 27 de Sept. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by