Menu

your application

Chris DeGreef

Include the JAR file

Only one JAR file is needed to support the Algebrain features: algebrain-1.0.2.jar. The version will change over time. Use what ever JAR you downloaded. This JAR contains all of the .class files. It does not contain the source (.java).

Interacting with Equ

This is the main class for Algebrain. Create an instance of this class and
send it an evaluate() message. The result is either a Double or a String
depending on the final function that was executed - almost always it will be
a double.

final Equ equ = Equ.getInstance();
final Double sine = (Double) equ.evaluate("sin(0.15)");</pre>

Registering your own functions

Many functions are provided in Algebrain and nothing special needs to be done in order to use them.

You can also register your own functions and operators by calling the static methods registerFunction and registerOperator. These add to a static Map so there are then available for the duration of your application.

final Equ equ = Equ.getInstance();
equ.registerFunction("min", MIN.class);
// The following answer is 1.
final Double sine = (Double) equ.evaluate("min(1,2,3)");</pre>

Variable support for your equations

A support instance can be handed to an instance of Equ with the setSupport() method. This must be done prior to calling evaluate. When a variable is found in the equation (i.e.: not a known function, like x or myvar) then the support instance is asked to instantiate the variable. It is expected that it will do what is necessary to come up with it. The test cases show a support instance that maintains a local Map of variable name / value pairs. But a database could be used as well, for instance.


MongoDB Logo MongoDB