I am not familiar with MathLab, but I believe it can be done.
You need to define your model (variables/relations/constraints) and write the code to deal with it.
If you are familiar with MathLab, you should be able to learn EJS very quickly!
You can check out [url=http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=656.0]SWF movie show step by step instructions to create java simulation with EJS[/url] to know what EJS can help you.