Re: dynamic formula evaluation

>how can i use visad to read any formula from a
>textfield and evaluate it for a given point.
>for example ://
>if i have two variables x and y and i want to evaluate
>f(x,y)=x+(y*2); for any x and y values i want.
>//
>i want the formula to be dynamic such that it can be
>changed in the textfield not inside my program.

Hi Bader,

VisAD provides support for formulas with the visad.formula
package.  All you have to do is create a FormulaManager
object.  Here is an example that follows your idea above:

// BEGIN CODE

Data x = ...; // create a VisAD Data object somehow
Data y = ...; // create another VisAD Data object

// create the "formula manager" using built-in defaults
FormulaManager fman = FormulaUtil.createStandardManager();

// add the x and y variables to the manager's database
fman.setThing("x", x);
fman.setThing("y", y);

// define the f function using a formula
fman.assignFormula("f", "x+(y*2)");

// now get the computed value of the function
Data f = (Data) fman.getThing("f");

// END CODE

Alternatively, you can use DataReference objects instead
of Data objects by using fman.createVar() and
fman.getReference() instead of fman.setThing() and
fman.getThing(), respectively.  The advantage to using
DataReferences is that you can then use a VisAD CellImpl
to listen for changes to your data via the DataReference.

The visad.formula package is quite powerful, and there are
many possibilities.  See the VisAD SpreadSheet for an
example of textfield formulas in action.  Another example
that uses textfield formulas is the visad.rabin.Rain
application.  I also recommend reading the visad.formula
package's javadoc.

If you have any more questions about formulas in VisAD,
feel free to ask!

Curtis


  • 2000 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: