while loops with compound interest

조회 수: 3 (최근 30일)
Astha Sharma
Astha Sharma 2015년 11월 2일
댓글: Walter Roberson 2015년 11월 3일
hello, i am trying to work out a problem that i am having with while loops. i have to determine how much to save each month in order to reach a goal of 100836 in 216 months. the interest rate is 5.5 per year. so far, i have written the following script but the number does not seem believable to me.
%minimum deposit in 18 years
n=18*12;
balance= 2000;
deposit=200;
while balance<100836.46
balance=balance*(1+(5.5/1200))+deposit;
deposit=deposit+50+(20*n);
end
disp(deposit)
disp(balance)
i end up getting an odd number which is 35160. i think that the number should be in the 200's assuming that the initial deposit is 200.
  댓글 수: 3
Astha Sharma
Astha Sharma 2015년 11월 2일
i asked both questions
Walter Roberson
Walter Roberson 2015년 11월 2일
When you ask the same question multiple times, the volunteers end up spending their time finding and merging the multiple questions, instead of spending their time answering questions.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2015년 11월 2일
Why are you adding (20*n) each deposit period?
  댓글 수: 2
Astha Sharma
Astha Sharma 2015년 11월 2일
편집: Walter Roberson 2015년 11월 3일
i have reworked the problem to be:
balance(1)=2000;
deposit(1)=250;
while balance(b1)<=100836
deposit=deposit+10;
for b1=1:216
balance(b1)=(balance(b1-1)*(1+(5.5/1200))+deposit);
end
end
but this is still not giving me the answer i am looking for.
Walter Roberson
Walter Roberson 2015년 11월 3일
initialize
while true
do a calculation
if we succeeded
break;
end
change the variables for the next try
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by