/** * Copyright (c): Uwe Schmidt, FH Wedel * * You may study, modify and distribute this source code * FOR NON-COMMERCIAL PURPOSES ONLY. * This copyright message has to remain unchanged. * * Note that this document is provided 'as is', * WITHOUT WARRANTY of any kind either expressed or implied. */ /** * simple test of SearchZero and RealFunction */ //-------------------- public class FindZeroTest { public static void main(String[] args) { RealFunction sin = new Sinus(); RealFunction exp = new Exponent(); RealFunction sinexp = new MultFunctions(sin,exp); // sin(x) * exp(x) RealFunction trcSin = new TraceFunction(sin); RealFunction trcSinExp = new TraceFunction(sinexp); SearchZero z1 = new IntervallNesting(); SearchZero z2 = new Interpolation(); printZero(1.0,4.0,trcSin,z1); System.out.println(""); printZero(1.0,4.0,trcSin,z2); System.out.println(""); printZero(1.0,4.0,trcSinExp,z1); System.out.println(""); printZero(1.0,4.0,trcSinExp,z2); System.out.println(""); } //-------------------- public static void printZero(double x1, double x2, RealFunction f, SearchZero z) { System.out.println( "search a zero of " + f + " in: " + x1 + " <= x <= " + x2 + "\nwith method: " + z + "\n"); try { double x = z.searchZero(x1,x2,f); int nc = z.getNoOfCalls(); System.out.println( "result x: " + x); System.out.println( nc + " calls needed"); } catch (NoZeroFoundException e) { System.out.println(e.getMessage()); } } }