如何在netlogo中将字符串解析为实方程 [英] how to parse a string into real equation in netlogo

查看:142
本文介绍了如何在netlogo中将字符串解析为实方程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用netlogo开发一个模型,用户可以在其中输入方程式来更改某些变量.我的问题是获取方程输入的最佳方法是什么,我应该如何解析它并计算结果.寻找可以在netlogo中使用的"mathml"之类的东西.

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.

推荐答案

一个不涉及MathML或任何形式的简单解决方案是让您的用户直接输入NetLogo表达式并使用

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:

当然,在实际应用中,您必须非常小心有关错误处理.

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

这篇关于如何在netlogo中将字符串解析为实方程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆