Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
Latest commit
34 lines (30 loc) · 1.15 KB
/
Copy pathMain.java
File metadata and controls
34 lines (30 loc) · 1.15 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
publicclassMain {
publicdouble[] y, x;
publicMain(intn, doubledelta, doublex0) {
y = newdouble[n];
x = newdouble[n];
for (inti = 0; i < n; ++i, x0 += delta) {
x[i] = x0;
y[i] = f(x0);
}
}
publicstaticvoidmain(String[] args) throwsException {
System.out.println("Generating data: n=100, d=0.1, x0=1");
Maindata = newMain(100, 0.1, 1);
CubicSplineFitterfitter = newCubicSplineFitter(data.x, data.y);
System.out.println("Interpolating spline");
fitter.interpolate();
System.out.println("Retrieving curve");
CubicSplineInterval[] curve = fitter.getCurve();
System.out.println("Spline pieces: " + curve.length);
for (inti = 0; i < curve.length; ++i) {
System.out.println("Spline" + i + ": " + curve[i]);
}
for (inti = 0; i < curve.length; ++i) {
System.out.printf("F(%f)=%f; S(%f)=%f\n", data.x[i], data.y[i], data.x[i], curve[i].evaluate(data.x[i]));
}
}
publicdoublef(doublex) {
returnMath.pow(x - 3, 3) + Math.pow(x + 2, 2) - x + 9;
}
}