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 个评论

So, what efforts have you made towards writing the 6 lines or so required to solve this extremely easy homework?
i've tried but i can't seem to get the loop right. the code when run goes all the way to infinity.
Show us what you've written and we may be able to point out the problem that's causing your loop to run infinitely.
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.

请先登录,再进行评论。

回答(1 个)

Guillaume
Guillaume 2017-3-31
编辑:Guillaume 2017-3-31

0 个投票

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 个评论

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
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.
Use the plot function.
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.

请先登录,再进行评论。

类别

在 帮助中心 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by