Completely agree. However, this is a stochastic process course (for non-programmers and non-mathematicians) and most of the students will only be able to use maple as a "symbolic calculator". We're trying to be very verbose with our code so they know exactly what happens. Although I think functional (or semi-functional in the case of maple) is more elegant; it is notoriously difficult to decipher.
I did something like this instead:
states := [ "S", "C", "R" ]:
#The probability distributions from transitioning OUT of a state
dist["S"] := ProbabilityTable([0.6, 0.3, 0.1]):
dist["C"] := ProbabilityTable([0.4, 0.5, 0.1]):
dist["R"] := ProbabilityTable([0.3, 0.4, 0.3]):
TransitionFrom := state -> states[ Sample( dist[state], 1) ];
#starting from the 'sunny' state is arbritrary
TodaysWeather := "S";
WeatherHistory := NULL;
for i from 1 to 50 do
NextWeather := TransitionFrom( TodaysWeather );
WeatherHistory := WeatherHistory, NextWeather;
TodaysWeather := NextWeather;
As a side note. I'm having a lot of difficulty posting code into these windows. It doesn't format properly, and everything seems to want to double space. Advise?