For Loop - Homework Question

조회 수: 1 (최근 30일)
Nathan Brannan
Nathan Brannan 2021년 3월 11일
댓글: Nathan Brannan 2021년 3월 11일
I have a homework problem that I've been working on, but I've come to a section that I believe requires a for loop. The section that I'm dealing with is below.
The matlab code that I've tried is this:
n=0;
for n=i-1 && n<=40
income = initial_income*(1+inflation)^n
end
From my understanding, this will only find the value at n=0. I believe I need each value of income at n = 1:40.
Any and all help would be appreciated!
I'll place the rest of the problem below for the sake of context. The retirement year that I found was 1959, but I don't believe that will be relevant to this section.
  댓글 수: 3
Cris LaPierre
Cris LaPierre 2021년 3월 11일
I'd also suggets completing Ch 13 of MATLAB Onramp, as that covers for loops.
Nathan Brannan
Nathan Brannan 2021년 3월 11일
I'll go through that. Thank you!
Loops have been the bane of me so far. Having a better understanding would be great.

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

채택된 답변

David Hill
David Hill 2021년 3월 11일
income = initial_income*(1+inflation).^(0:40);
  댓글 수: 1
Nathan Brannan
Nathan Brannan 2021년 3월 11일
If this is the desired answer, then I suppose I got lost in the idea that n = i-1.
I figured that played an immediate role in calculating the income. Thanks for the answer!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by