how do I write the correct syntax for this for loop

3 vues (au cours des 30 derniers jours)
Adam Essex
Adam Essex le 8 Jan 2018
Commenté : Adam Essex le 9 Jan 2018
The current Year 1 enrolment at MATLAB University is 1500 students. The University VC, Professor For, decides to admit 3000 Year 1 students from now on. The University estimates that 10 percent of the Year 1 students will repeat the year. Hence the following year, the Year 1 students will be 0.1 × 1500 + 3000 = 3150, then they will be 0.1×3150+3000, and so on. Then in year k+1 the number x1 of Year 1 students will be
x1(k + 1) = 0.1 x1(k) + 3000 (4)
where x1(k) is the number of Year 1 students in year k.
Now, let x2(k) be the number of Year 2 students in year k. We already know that 10 percent of the Year 1 students will repeat the year, so they will not progress to Year 2. We also know that that every year 15 percent of the Year 1 students leave MATLAB University and so do not enrol in Year 2. Hence 100 − 10 − 15 = 75 percent of the Year 1 students in year k return as Year 2 students in year k + 1. Suppose also that 5 percent of Year 2 students will repeat the year and that 300 Year 2 students each year transfer from other Universities. Then in year k + 1 the number x2 of Year 2 students will be
x2(k + 1) = 0.75 x1(k) + 0.05 x2(k) + 300 (5)
Finally, suppose that 90 percent of the Year 2 students advance to Year 3, and that 5 percent of Year 3 students will repeat the year. Then the number of Year 3 students in year k + 1 is
x3(k + 1) = 0.9 x2(k) + 0.05 x3(k) (6)
(a) Suppose that the initial total enrolment consists of 1500 Year 1 students, 1400 Year 2 students and 1300 Year 3 students.
(i) Using a for loop and equations (4), (5) and (6), calculate the number of Year 1, 2 and 3 students over a period of 15 years.
x1(1) = 1500 x2(1) = 1400 x3(1) = 1300
for
k = 1:1:14
x1(k+1) = 0.1 x1(k) + 3000
x2(k + 1) = 0.75 x1(k) + 0.05 x2(k) + 300
x3(k + 1) = 0.9 x2(k) + 0.05 x3(k)
end
This is what I have managed so far but this particular format gives me the correct answers for each year group but repeated 15 times
  4 commentaires
Adam Essex
Adam Essex le 9 Jan 2018
Modifié(e) : Walter Roberson le 9 Jan 2018
x1(1) = 1500
x2(1) = 1400
x3(1) = 1300
for k = 1:1:14
x1(k+1) = 0.1*x1(k)+3000
x2(k+1) = 0.75*x1(k)+0.05*x2(k)+300
x3(k+1) = 0.9*x2(k)+0.05*x3(k)
end
this was as far as I got but when I run this, the answers are correct but repeated 15 times and I've been trying to change it slightly but it still comes out with 15 sets of answers
Adam Essex
Adam Essex le 9 Jan 2018
or at one point I managed to get the answers but it came out as just the first year answers then 1st and 2nd then 1st 2nd and 3rd and so on up to having all 15 but once again I couldn't work out how to re3duce this to just having 15 answers for each year group

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 9 Jan 2018
Modifié(e) : Walter Roberson le 9 Jan 2018
for k = 1 : 15
%... some code goes here
end
  2 commentaires
Adam Essex
Adam Essex le 9 Jan 2018
I got something similar to start off with but I used 1:1:14 as I used k+1 in the code in the middle so that it would go up to 15 only
Adam Essex
Adam Essex le 9 Jan 2018
I also know that I'm gonna need to have k = 1:15 not 14 because I need to plot the years against the values of k over the 15 years but I'm not sure how I can work that into the code without it trying to find an answer for x1(0) or giving me an answer for x1(16) which I don't need

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by