compound interest using for loop
Ältere Kommentare anzeigen
£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 Kommentare
Guillaume
am 31 Mär. 2017
So, what efforts have you made towards writing the 6 lines or so required to solve this extremely easy homework?
Harry Chichi
am 31 Mär. 2017
Guillaume
am 31 Mär. 2017
Then show us the code that you wrote.
Steven Lord
am 31 Mär. 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
am 31 Mär. 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.
Antworten (1)
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 Kommentare
Harry Chichi
am 31 Mär. 2017
Guillaume
am 31 Mär. 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
am 31 Mär. 2017
Use the plot function.
Elisabeth Quan
am 27 Sep. 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.
Kategorien
Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!