how do I write the correct syntax for this for loop
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!