1
2
3
4
5
6
7public
8class FindZeroTest {
9
10 public
11 static
12 void main(String[] args) {
13 RealFunction sin = new Sinus();
14 RealFunction exp = new Exponent();
15 RealFunction sinexp = new MultFunctions(sin,exp);
16
17 RealFunction trcSin = new TraceFunction(sin);
18 RealFunction trcSinExp = new TraceFunction(sinexp);
19
20 SearchZero z1 = new IntervallNesting();
21 SearchZero z2 = new Interpolation();
22
23 printZero(1.0,4.0,trcSin,z1);
24 System.out.println("");
25
26 printZero(1.0,4.0,trcSin,z2);
27 System.out.println("");
28
29 printZero(1.0,4.0,trcSinExp,z1);
30 System.out.println("");
31
32 printZero(1.0,4.0,trcSinExp,z2);
33 System.out.println("");
34 }
35
36
37
38 public
39 static
40 void printZero(double x1,
41 double x2,
42 RealFunction f,
43 SearchZero z) {
44 System.out.println(
45 "search a zero of " + f + " in: " + x1 + " <= x <= " + x2
46 + "\nwith method: " + z + "\n");
47
48 try {
49 double x = z.searchZero(x1,x2,f);
50 int nc = z.getNoOfCalls();
51
52 System.out.println(
53 "result x: " + x);
54
55 System.out.println(
56 nc + " calls needed");
57 }
58 catch (NoZeroFoundException e) {
59 System.out.println(e.getMessage());
60 }
61 }
62
63}
64