Your code predicts a 4 year tuition of 5500. Clearly that is not correct. How would I solve this, even if I was not using a loop?
increase = [10 8 10 16 15 4 6 7 8 10 8 12 14 15 8 7 6 5 7 8 9 8];
tuition = 5000*cumprod(1 + [0,increase]/100)
tuition =
1.0e+00 *
5000 5500 5940 6534 7579.4 8716.4 9065 9608.9 10282 11104 12214 13192 14775 16843 19370 20919 22383 23726 24913 26657 28789 31380 33891
That is the YEARLY tuition. If you want 4 years, then we could do this:
fouryeartuition = conv(tuition,[1 1 1 1],'valid')
fouryeartuition =
1.0e+00 *
22974 25553 28770 31895 34970 37672 40060 43209 46792 51285 57024 64179 71906 79515 86398 91942 97679 1.0408e+05 1.1174e+05 1.2072e+05
And my guess is you were being asked to produce the total tuition, as if you started this year, or any year for the next 20 years.
plot(fouryeartuition,'o')
Anyway, 5500 is clearly not correct, although I think the question is far too vague to have a good answer. A good, well-posed question would have been explicit. Why do I think the request was to see a prediction of the total 4 year tuition over the next 20 years? Because they gave you 20 years of yearly tuition hikes as information!
Anway, why did your loop fail? LOOK AT WHAT YOU WROTE!
for x = increase(:,1):increase(:,3)
What is increase(:,1)? increase(:,3)
So what did your loop do? For example, try this:
Do you see the loop only runs for ONE iteration?