Question: Monte Carlo simulation in Maple is running really slow. Can anyone help optimize my code?

I'm using Maple to simulate particle collision and interaction (absorption and scattering) and keep tracking its energy until each particle either get absorbed or leaked (Energy less than predefined minimum energy). I also use Maple statistical pacakge. I also need to call MATLAB link to generate histogram in a logarithmically spaced bin, a feature that I could not find anywhere in Maple and I think it is one of the reasons for calculation performance issue.

The problem is that my code in Maple, although they are easy to read and understand, takes very very long time to finish. For only 10,000 particles and 50 generations of interactions, it takes 5-6 hours to finish. As observed with other classmates, this similar problem takes approximately 30 minutes to run in MATLAB. Any advice to make it run faster? Thanks.

 

Please Wait...