how to parse a string into real equation in netlogo - netlogo

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.

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.

Related

How to build 2-layer fuzzy inference system

I am implementing a fuzzy logic based decision support system that uses nine variables but group each three together to form an output then take these three output to make the final output of the system.
I am using fuzzy logic toolbox in matlab, I made each one of these three outputs but I can't figure out how I can make these outputs as inputs again for the final output.
The system is shown in this picture:
system picture
Correct me if I'm wrong, but I think you would need two FIS separately , where the inputs from the second one will be the outputs from the first one.
Sorry If I didn't help much :/

How do I input variables into a Simulink model through MATLAB script (SimDriveline)

For my coursework project in MATLAB, I have decided to build a drive-line model within Simulink, using the SimDriveline toolbox. The idea is to get the user to input values for the various parameters that are associated with each part of the model, such as the engine or the transmission. I would like to able to write this in a MATLAB script, but I'm not sure how to assign the values that are input to the Simulink model. For instance, the stock sdl_vehicle example that comes with SimDriveline. I am aware of the sim() command, but I am still confused on how to use it properly.
Also at the end of the simulation, the program is supposed to display the graphs that are collected in the scope window. I know that in the window itself that the scope can be printed to a figure, but is it possible to print that scope to a figure through MATLAB script?
This is the first time I have ever used a program like MATLAB. I would appreciate any help I could get, many thanks in advance!
There is a simulink block called simin:
http://de.mathworks.com/help/simulink/slref/fromworkspace.html?searchHighlight=simin
I used it some days back and it worked quite well. You can use the block in your model and define some signals/varibles as input.
After that you may write a Matlab-Script with an input function to set all the previous defined input values.

Matlab parametric plotting gui - vary parameters via sliders

I often have function such as:
sin(a*w*t + p)
where:
w = natural frequency
t = time
a,p = parameters (which I can vary)
As you can see if you want to vary a,p, you can do so via the standard interface but it's not very convenient. So I thought I'd look for a GUI which has a slider for each parameter. Does such a thing exist?
I've never seen one so I thought I'd quickly write one. However, I'm worried that due to lack of time and knowledge of matlab I will cause problems such as generating too many plot commands when the slider is moved instead of just one. Of course I also have the problem that I want to specify a field where the user can specify the function e.g. by typing sin(a*w*t +p) in a text field and then specify what each variable means which I currently don't know how to do (it looks like a parsing task). Can I do this or should I go with a predefined set of functions?
You can find similar projects in Matlab File Exchange as example.
For instance:
Integral Tool
Function Parameter Slider
I didn't have a look at the code but according to the screenshots, it should help you.
Regarding the function input feature, you can use the function eval (with a few checks on the input if you need reliability). If you want to allow any parametric variable, it may be harder.

Converting a math expression (String) to usable variables

I am trying to make an iPhone-app that does the Monte Carlo simulation on
equations given by the user. I want the user to be able to input something like:
"2x+(y^2)" and then recieve a result.
Is there a way to parse this string and get usable variables that i can do calculations on (a library u know of perhaps)?
Take a look on compiler tools. although it might be a bit bloated, it is easy to write any "language" in it even if its just for simple mathematical expressions.

iPhone - how can I insert a mathematical function through a textfield?

I want to make an iphone program that makes the graph of a mathematic function, like sin(x).
So, I want to put the mathematical expression sin(x) in a UITextfield and then take it and use it like a function.
Does anyone know how to do this?
You have two problems:
You need to evaluate an NSString as if it were a mathematical equation and obtain a number from it.
You need to plot some numbers on a graph.
Fortunately, there are projects out there to help you with this:
DDMathParser - a library I wrote for evaluating strings as mathematical expressions. There are other alternatives, such as ANExpressionParser and GCMathParser, but ANEP doesn't always parse things correctly (ex: -2 ** -2 should be -0.25, and it parses it as 0.25) and GCMathParser isn't extensible and is no longer under development. However, GCMathParser is insanely fast. It is much faster than DDMathParser (by a couple orders of magnitude), but DDMathParser will still parse things in a fraction of a second.
Core Plot - A pretty awesome graphing framework. I haven't had occasion to use it myself, but it's also under active development and has a pretty solid community of users. I've heard nothing but good things about it.
You could convert the text expression into Javascript ("sin" -> "Math.sin", etc.), run the Javascript code inside a UIWebView, get a string result back, and convert it into numeric data.
A UILabel with text "sin(" followed by UITextFied (with placeholder text) where user enters the value of x, followed by another UILabel with closing brace ")".