# I am trying to form a conditional loop that shows the growth of money, I put in \$1000 every year and it grows by 85 for ten years but keep returning one value

1 view (last 30 days)
Matthew on 19 Apr 2024
Edited: Torsten on 19 Apr 2024
I am trying to make it add \$1000 every year and have an 8% return over 10 years but don't know how to access my previous value in my loop
money=1000;
supersaver=1000;
y=zeros(1,10);
for i=1:10
y(i)=(money+supersaver)*1.08
end

Torsten on 19 Apr 2024
Edited: Torsten on 19 Apr 2024
money = zeros(10,1);
supersaver = 1000;
Return = 0.08;
money(1) = supersaver*(1+Return); % Money at end of year 1
for i = 2:10
money(i) = (supersaver + money(i-1))*(1+Return); % Money at end of year i
end
format longEng
money
money = 10x1
1.0e+00 * 1.08000000000000e+003 2.24640000000000e+003 3.50611200000000e+003 4.86660096000000e+003 6.33592903680000e+003 7.92280335974400e+003 9.63662762852352e+003 11.4875578388054e+003 13.4865624659098e+003 15.6454874631826e+003
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

### Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!