Storing values in a for loop when input vector is not used in calculation
2 views (last 30 days)
I'm working through examples in "Matlab for Engineers and Scientists" and am having trouble with this problem:
Suppose you deposit $50 in a bank account every month for a year. Every month, after the deposit has been made, interest at the rate of 1% is added to the balance: After one month the balance is $50.50, and after two months it is $101.51. Write a program to compute and print the balance each month for a year. Arrange the output to look something like this:
MONTH MONTH-END BALANCE
Obviously the vector of months shows up fine, but I can't get the balance vector figured out...if I used the months vector in the calculation of balance I know I'd get a vector, but my current code overwrites the previous balance from last month. I don't use the months vector for anything but a counter/index:
disp('MONTH MONTH-END BALANCE')
I know I can do this using the month as an exponent on the rate but just want to know if there's a way to get a vector of balances by modifying the code above.