-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormula.java
More file actions
104 lines (89 loc) · 2.88 KB
/
Formula.java
File metadata and controls
104 lines (89 loc) · 2.88 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
public abstract class Formula extends Object
{
protected double[] Params;
public Formula()
{
}
public Formula( double[] params )
{
Params = params;
}
public double[] getParams()
{
return Params;
}
public abstract double getY( double x );
public static double sigma( Double[] list )
{
double temp = 0;
for( int i = 0; i < list.length; i++ )
temp += list[i].doubleValue();
return temp;
}
public static double sigma( Double[] list, double exp )
{
double temp = 0;
for( int i = 0; i < list.length; i++ )
temp += Math.pow( list[i].doubleValue(), exp );
return temp;
}
public static double sigma( Double[] listx, Double[] listy )
{
double temp = 0;
for( int i = 0; i < listx.length; i++ )
temp += listx[i].doubleValue() * listy[i].doubleValue();
return temp;
}
public static double sigma( Double[] listx, Double[] listy, double exp )
{
double temp = 0;
for( int i = 0; i < listx.length; i++ )
temp += Math.pow( listx[i].doubleValue(), exp ) * listy[i].doubleValue();
return temp;
}
public static double powerFormA( Double[] x, Double[] y )
{
return ( x.length * sigma( x, y) - sigma( x ) * sigma( y ) ) /
( x.length * sigma( x, 2.0 ) - Math.pow( sigma( x ), 2.0 ) );
}
public static double powerFormB( Double[] x, Double[] y )
{
return ( sigma( x, 2.0 ) * sigma( y ) - sigma( x, y ) * sigma( x ) ) /
( x.length * sigma( x, 2.0 ) - Math.pow( sigma( x ), 2.0 ) );
}
public static double powerFormA2( Double[] x, Double[] y, double exp )
{
return sigma( x, y, exp ) / sigma( x, exp * 2.0 );
}
public static double[] backSolve( double system[][] )
{
int i = 0, j = 0, k = 0;
double multiplier = 0;
for( i = 0; i < system.length - 1; i++ )
for( j = i + 1; j < system.length; j++ )
{
if( system[j][i] != 0 )
{
multiplier = system[j][i] / system[i][i];
for( k = i; k < system[j].length; k++ )
system[j][k] -= system[i][k] * multiplier;
}
}
double result[] = new double[ system.length ];
for( i = system.length - 1; i >= 0; i-- )
{
for( j = i + 1; j < system[i].length - 1; j++ )
system[i][ system[i].length - 1 ] -= system[i][j] * result[j];
if( system[i][i] != 0 ) result[i] = system[i][ system[i].length - 1 ] / system[i][i];
else result[i] = 0;
}
return result;
}
public static Double[] log( Double[] x )
{
Double[] y = new Double[ x.length ];
for( int i = 0; i < x.length; i++ )
y[i] = new Double( Math.log( x[i].doubleValue() ) );
return y;
}
}