-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaylor.java
More file actions
107 lines (87 loc) · 2.26 KB
/
Copy pathTaylor.java
File metadata and controls
107 lines (87 loc) · 2.26 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
98
99
100
101
102
103
104
105
106
107
public class Taylor {
public static int factioal(int par1) {
int ans = 1;
for(int i =1; i<par1; i++) {
ans *=i;
}
return ans;
}
/**
*
* @param par1 - points set
* @param par2 - null at beginning
* @param i = 0 at beginning
* @return
*/
public static double[] generateFromPoints(double[] par1, double[] par2, int i) {
if(par2 == null || par2.length == 0) {
par2 = new double[par1.length];
if(par1.length % 2 == 1) {
par2[0] = par1[(par1.length / 2)];
}
if(par1.length % 2 == 0) {
double sum = par1[(par1.length / 2)] + par1[(par1.length / 2) - 1];
par2[0] = sum/2;
}
i++;
return generateFromPoints(par1, par2, i);
}
if(par1.length == 0 || par1.length == 1) {
return par2;
}
int mod = (par1.length-1) % 2;
double[] par3 = new double[par1.length-1];
for(int j = 0; j < par3.length; j++) {
par3[j] = par1[j+1]-par1[j];
}
if(mod == 1) {
par2[i] = par3[(par3.length / 2)];
i++;
}
else {
double sum = par3[(par3.length / 2) - 1] + par3[(par3.length / 2)];//might have some errors on this line need to test this before i send it out
par2[i] = sum/2;
i++;
}
return generateFromPoints(par3, par2, i);
}
/**
* gets the distance squared for the line
* @param par1 data set1
* @param par2 data set2
* @return the distance squared
*/
public static double DistanceSquared(double[] par1, double[] par2) {
double d = 0;
for(int i =0; i < par1.length; i++) {
d += Math.pow(par1[i] - par2[i], 2);
}
return d;
}
/**
* gets the distance squared for each point
* @param par1 data set1
* @param par2 data set2
* @return the distance squared
*/
public static double[] DistanceSquaredPoints(double[] par1, double[] par2) {
double[] d = new double[par1.length];
for(int i =0; i < par1.length; i++) {
d[i]= Math.pow(par1[i] - par2[i], 2);
}
return d;
}
/**
* Generates Points from Taylor Series
* @param t Taylor Series
* @param par1 the orginal data
* @return points
*/
public static double[] dataSetFromTaylorSeries(TaylorSeries t) {
double[] d = new double[t.getCoeff().length];
for(int i = 0; i < t.getCoeff().length; i++) {
d[i] = t.evaluteAt(i, (t.getCoeff().length-1) / 2.0);
}
return d;
}
}