Calculating compound interest using a for loop
이전 댓글 표시
-Someone saves a sum of 100 Euro on the bank against an interest rate of 5%. The interest is paid at the end of each year. Calculate the total sum after 16 years using a for-loop.
-Calculate the total sum when in the 7th year the interest rate is increased to 6%. To do this, insert an if-statement inside the for-next loop.
댓글 수: 5
David Fletcher
2018년 3월 4일
Sounds a bit like a homework question. At the very least it might be worth showing that you've had a crack at writing something to solve the problem, even if it doesn't work.
Noa Leijdesdorff
2018년 3월 4일
David Fletcher
2018년 3월 4일
편집: David Fletcher
2018년 3월 4일
What about:
savings=100;
for i=1:16
savings=savings*1.05
end
After all, you don't need to keep a record of the savings after every year
Noa Leijdesdorff
2018년 3월 4일
David Fletcher
2018년 3월 4일
You could store it in a matrix if you felt the need (though the question posed originally does not require the value to be stored, only the result after 16 years). You've already done something similar in the attempt you made, so think about how would you adapt it to meet your requirements?
답변 (1개)
Deepak Bastola
2020년 8월 16일
x=1000;
y=0.1;
t=2;
d=x*(1+y)^t
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!