For Loop Problem (Compound Interest with linked Savings and CD Account)
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am having issues with this problem that involves for loops. The problem starts with monthly deposits of (300,350,350,350,400), each being deposited into a savings account every month for a year. The account compounds the interest monthly at a rate of 4%. Every time the savings account reaches over 3000, 2000 is withdrawn into the CD account which is compounded yearly at a rate of 6%. I am having difficulty having the Savings Balance compound every month. I also can't get figure out why my if statement isn't working correctly. I realize I'm probably far off from a functioning script but this is what I have. Can anybody lend a hand or offer some hints?
Deposits=[300,350,350,350,400];
SavRate=1.04; CDRate=1.06;
for year=1:5
for month=1:12
k=1:5;
SavBal=sum(Deposits(k)*month*SavRate);
end
if SavBal>=3000
SavBal=SavBal-2000;
CDBal=CDBal+2000*CDRate;
end
end
disp(SavBal)
disp(CDBal)
0 Commenti
Risposte (1)
Asad (Mehrzad) Khoddam
il 28 Ott 2016
Here is the code. As you assumed, for the first year we add monthly values to the saving account
MonthlyDeposit=sum([300,350,350,350,400]);
SaveBal=MonthlyDeposit;
Deposits=MonthlyDeposit;
SaveRate=1.04; CDRate=1.06;
CDBal=0;
for year=1:5
for month=1:12
if year<2
SaveBal=SaveRate*SaveBal + MonthlyDeposit;
else
SaveBal=SaveRate*SaveBal;
end
if SaveBal >= 3000
SaveBal=SaveBal-2000;
CDBal=CDBal+2000;
end
end
CDBal=CDBal*CDRate;
end
disp(SavBal)
disp(CDBal)
0 Commenti
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!