import cam.symfun.*; public class SFtest2 { // //###################################################################### // // Create and then evaluate a user specified function of one variable. // // INPUT : // ------ // User is prompted to specify a function f(x). // // Example : Typing x*x +2 followed by a carriage return would input // the function x squared plus 2. The syntax for function specification // is that of the syntax for a Java expression. // // User is prompted to specify the evaluation point // // OUTPUT : // ------ // The value of the function at the evaluation point // //###################################################################### // public static void main(String[] args) { // query user for function specification java.io.BufferedReader userInput = new java.io.BufferedReader (new java.io.InputStreamReader(System.in)); String E = null; System.out.print("Enter f(x) : "); try{ E = userInput.readLine();} catch(Exception e){System.out.println(e.getMessage());} // // query user for x value (note that the value is read in as a string // and then converted to a double value // String xVal; double x = 0.0; System.out.print("Enter evaluation point : "); try{ xVal = userInput.readLine(); x = (new Double(xVal)).doubleValue(); } catch(Exception e){System.out.println(e.getMessage());} // // create the symbolic function and evaluate it // SymbolicFunction Sym = new SymbolicFunction(); String[] V = new String[1]; V[0] = new String("x"); // x = ind. variable try { Sym.initialize(V,E); } catch(Exception e) { System.out.println(e.getMessage()); } double val = Sym.evaluate(x); System.out.println(" SymbolicFunction F = " + Sym.getConstructorString()); System.out.println(" Evaluated at x = " + x + " is : " + val); // // Pause command window // System.out.println(" "); System.out.println(" Program End : Hit Return to Continue "); try{userInput.readLine();}catch(Exception e){}; } }