MATLAB Answers

For Loop Problem (Compound Interest with linked Savings and CD Account)

29 views (last 30 days)
John Finley
John Finley on 28 Oct 2016
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 Comments

Sign in to comment.

Answers (1)

Asad (Mehrzad)  Khoddam
Asad (Mehrzad) Khoddam on 28 Oct 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 Comments

Sign in to comment.

Sign in to answer this question.

Tags