Re: dynamic formula evaluation for a point

>what if i want to evaluate this dynamic formula for a
>point (for example x=3.8 , y=4.5)such that it will
>return to me f(x,y) as a float number 
>what should i do?
>i'm a beginner with visad and data object please
>explain  the answer to me by a code example for these
>values for x and y

Bader,

I've included a little application below that does what
you want.  To run it using the data and formula you
gave in your example, type "java Eval 3.8 4.5 x+2*y" at
the command line.  Note that you can provide the
program with whatever formula and whatever values of x
and y that you want.

By the way, when writing this little app, I uncovered a
bug in the visad.formula package's waitForFormula()
method.  It's been fixed, but the change probably won't
appear on the VisAD FTP site for a few days.  In the
meantime, you can get the updated FormulaVar.java file
from http://palm.ssec.wisc.edu/FormulaVar.java.
Alternatively, you could replace the waitForFormula()
command below with a call to Thread.sleep(500).

Let me know if you have any more questions.

Curtis

---------------
// Eval.java

import java.rmi.RemoteException;
import visad.*;
import visad.formula.*;

public class Eval {

   public static void main(String[] argv)
     throws VisADException, RemoteException
   {
     // get arguments from command line
     if (argv.length < 3) {
       System.out.println("Please enter three arguments: " +
         "two numbers and a formula.");
       System.exit(1);
     }
     double d1 = 0;
     double d2 = 0;
     try {
       d1 = Double.parseDouble(argv[0]);
       d2 = Double.parseDouble(argv[1]);
     }
     catch (NumberFormatException exc) {
       System.out.println("First two arguments must be numbers.");
       System.exit(2);
     }
     String formula = argv[2];

     // create two VisAD Data objects that store floating point values
     Real x = new Real(d1);
     Real y = new Real(d2);

     // create formula manager
     FormulaManager fman = FormulaUtil.createStandardManager();

     // register Data objects with formula manager
     fman.setThing("x", x);
     fman.setThing("y", y);

     // assign formula to new variable
     fman.assignFormula("f", formula);

     // wait for formula to finish computing, just to be safe
     fman.waitForFormula("f");

     // get value of function from formula manager
     Real f = (Real) fman.getThing("f");

     // print out results
     System.out.println("x = " + x.getValue() + ", y = " + y.getValue());
     System.out.println("f(x,y) = " + formula + " = " + f.getValue());
   }

}


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