how to parse a string into real equation in netlog

2019-08-04 16:03发布

I am trying to develop a model in netlogo, in which user can enter the equation for change in some variables. My question is what could be the best way to get equation input and how should i parse it and calculate results. looking for something like "mathml" which could work in netlogo.

1条回答
放我归山
2楼-- · 2019-08-04 16:33

A simple solution that doesn't involve MathML or anything of the sort would be to have your users directly enter NetLogo expressions and run those using runresult, which can take a string of NetLogo code and execute it.

Here is a simple example that uses an input box widget (with the type "String (reporter)") to allow the user to enter an arbitrary mathematical expression. The button prints the result of running the expression in the output box:

enter image description here

In a real world application, of course, you would have to be very careful about error handling.

查看更多
登录 后发表回答