forked from cstrahan/aduni
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFuncTest3.java
More file actions
97 lines (68 loc) · 2.22 KB
/
FuncTest3.java
File metadata and controls
97 lines (68 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
class FuncTest3{
static class SinFunc implements Function{
public double evaluate(double x){
return(Math.sin(x));
}
}
static class ExpFunc implements Function{
public double evaluate(double x){
return(Math.exp(x) - 2.0);
}
}
static class LogFunc implements Function{
public double evaluate(double x){
return(Math.log(x) - 1);
}
}
public static void main(String[] args){
Function sin = new SinFunc();
Function exp = new ExpFunc();
Function log = new LogFunc();
double x;
x = RFuncLib.bracketRoot(1.0,4.0,0.0000000001,sin);
System.out.println((float)x);
x = RFuncLib.bracketRoot(0.0,4.0,0.0000000001,exp);
System.out.println((float)x);
x = RFuncLib.bracketRoot(1.0,4.0,0.0000000001,log);
System.out.println((float)x);
x = RFuncLib.defIntegral(0.0,Math.PI/2,1024*1024,sin);
System.out.println((float)x);
x = RFuncLib.defIntegral(0.0,2.0,1024*1024,exp);
System.out.println((float)x);
x = RFuncLib.defIntegral(1.0,2.0,1024*1024,log);
System.out.println((float)x);
testPoly();
}
public static void testPoly(){
int[] coefs1 = {-3,1};
Function p1 = new Poly(coefs1);
double x = RFuncLib.bracketRoot(0.0,4.0,0.0000000001,p1);
System.out.println((float)x);
System.out.println((int)(x*x));
int[] coefs2 = {-3,0,1};
p1 = new Poly(coefs2);
x = RFuncLib.bracketRoot(0.0,4.0,0.0000000001,p1);
System.out.println((float)x);
System.out.println((float)(x*x));
int[] coefs3 = {-5,0,1};
p1 = new Poly(coefs3);
x = RFuncLib.bracketRoot(0.0,4.0,0.0000000001,p1);
System.out.println((float)x);
System.out.println((float)(x*x));
int[] coefs3a = {-10,17,-8,1};
p1 = new Poly(coefs3a);
x = RFuncLib.bracketRoot(4.0,8.0,0.0000000001,p1);
System.out.println((float)x);
int[] coefs4 = {-1,-1,1};
p1 = new Poly(coefs4);
x = RFuncLib.bracketRoot(0.0,4.0,0.0000000001,p1);
System.out.println((float)x);
System.out.println((float)(1/x));
System.out.println((float)(x - 1));
p1 = new Poly(new int[] {4,0,-1});
x = RFuncLib.defIntegral(0.0,2.0,1024*1024,p1);
System.out.println((float)x);
x = ((Poly)p1).defIntegral(0.0,2.0,1024*1024);
System.out.println((float)x);
}
}