N
N
Nikita Filatov2015-12-01 08:57:27
Java
Nikita Filatov, 2015-12-01 08:57:27

How to convert a mathematical function of type String to a regular function in Java?

There is a mathematical function like String function = "12*x^2-132*x^3" how can such a function be converted so that it can be calculated

Answer the question

In order to leave comments, you need to log in

3 answer(s)
B
bromzh, 2015-12-01
@M0NSTERC4T

Algorithm and its implementation

P
Puma Thailand, 2015-12-01
@opium

to make lexical analysis
as a whole they teach at school
more thoroughly with theory they teach at the university in the course of the basics of programming languages, where they learn to write their own programming languages ​​and parse the source code of the program.

A
Alexey Cheremisin, 2015-12-01
@leahch

Ha, the easiest way is to pick up some kind of interpreted language. For example run this in jython, groovy or even javascript!
In other words. Link your application with your favorite interpreter library and call

BSFManager manager = new BSFManager();
Vector<String> ignoreParamNames = null;
Vector<Integer> args = new Vector<Integer>();
args.add(2);
args.add(5);
args.add(1);
Integer actual = (Integer) manager.apply("groovy", "applyTest", 0, 0,
        "def summer = { a, b, c -> a * 100 + b * 10 + c }", ignoreParamNames, args);
assertEquals(251, actual.intValue());

docs.groovy-lang.org/latest/html/documentation/ind... -
commons.apache.org/proper/commons-bsf/manual.html - scripting language manager
www.groovy-lang.org - groovy itself.
Good luck.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question