forked from lballabio/quantlib-old
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnaryFunctions.java
More file actions
32 lines (26 loc) · 923 Bytes
/
Copy pathUnaryFunctions.java
File metadata and controls
32 lines (26 loc) · 923 Bytes
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
package examples;
import org.quantlib.GaussKronrodAdaptive;
import org.quantlib.UnaryFunctionDelegate;
import org.quantlib.Brent;
public class UnaryFunctions {
static {
try {
System.loadLibrary("QuantLibJNI");
} catch (RuntimeException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws java.lang.InterruptedException {
long beginTime = System.currentTimeMillis();
System.out.println("Integration result " +
new GaussKronrodAdaptive(1e-8).calculate(
new UnaryFunctionDelegate() {
public double value(double x) { return Math.sin(x); }
}, 0.0, Math.PI));
System.out.println("Brent Solver result " +
new Brent().solve(
new UnaryFunctionDelegate() {
public double value(double x) { return Math.cos(x)-x; }
}, 1e-8, 0.5, 0.0, Math.PI));
}
}