5
5
import android .support .v7 .app .AppCompatActivity ;
6
6
import android .support .v7 .widget .Toolbar ;
7
7
import android .view .View ;
8
- import android . widget . Button ;
8
+ import Jama . Matrix ;
9
9
import android .widget .EditText ;
10
10
import android .widget .TextView ;
11
11
import android .widget .Toast ;
@@ -60,6 +60,10 @@ protected void onCreate(Bundle savedInstanceState) {
60
60
Btv = findViewById (R .id .B );
61
61
Ctv = findViewById (R .id .C );
62
62
63
+ A = 90000 ;
64
+ B = 80000 ;
65
+ C = 60000 ;
66
+
63
67
File cache = new File ((Environment .getExternalStoragePublicDirectory (Environment .DIRECTORY_DOWNLOADS )) + ("/CalibratorAppData/cache" ));
64
68
try {
65
69
FileReader cacheRead = new FileReader (cache );
@@ -112,6 +116,12 @@ void load(File ftl){
112
116
113
117
}
114
118
119
+ public void testPressed (View v ){
120
+ TextView answer = findViewById (R .id .tempTest );
121
+ EditText resText = findViewById (R .id .ResTest );
122
+ if (A <8000 ) answer .setText (getTemp (Integer .parseInt (resText .getText ().toString ())));
123
+ }
124
+
115
125
public void enterPressed (View v ){
116
126
name = name_et .getText ().toString ();
117
127
R1 = (Double .parseDouble (Res1 .getText ().toString ()));
@@ -122,63 +132,44 @@ public void enterPressed(View v){
122
132
T3 = (Double .parseDouble (Tem3 .getText ().toString ()));
123
133
124
134
//Do Some cool Math to get ABC
125
- double []ABC = coolMathGames (R1 ,R2 ,R3 ,T1 ,T2 ,T3 );
126
- A =ABC [0 ];
127
- B =ABC [1 ];
128
- C =ABC [2 ];
129
- Atv .setText ("A = " + A +"" );
130
- Btv .setText ("B = " + B +"" );
131
- Ctv .setText ("C = " + C +"" );
135
+ if (R1 !=R2 &&R2 !=R3 &&R1 !=R3 &&T1 !=T2 &&T2 !=T3 &&T1 !=T3 ) {
136
+ double [] ABC = coolMathGames (R1 , R2 , R3 , T1 , T2 , T3 );
137
+ A = ABC [0 ];
138
+ B = ABC [1 ];
139
+ C = ABC [2 ];
140
+ Atv .setText ("A = " + A + "" );
141
+ Btv .setText ("B = " + B + "" );
142
+ Ctv .setText ("C = " + C + "" );
143
+ } else {
144
+ Toast .makeText (this ,"Temp or Res Values are same" ,Toast .LENGTH_LONG );
145
+ }
132
146
}
133
147
134
148
public double [] coolMathGames (double R1 ,double R2 ,double R3 ,double T1 ,double T2 ,double T3 ){
135
149
T1 = T1 + 273.15 ;
136
150
T2 = T2 + 273.15 ;
137
151
T3 = T3 + 273.15 ;
138
- //M1*M2 = M3 And M2 = M3*(M1/d)
139
- // /** ************My sad attempt at doing Matrices
140
152
double [][] M1 = {
141
153
{1 ,ln (R1 ),cb (ln (R1 ))},
142
154
{1 ,ln (R2 ),cb (ln (R2 ))},
143
155
{1 ,ln (R3 ),cb (ln (R3 ))}
144
156
};
145
157
double [] M3 = {1 /T1 ,1 /T2 ,1 /T3 };
146
- // A1 *( B2 * C3 - C2 * B3 ) + B1 *( C2 * A3 - C3 * A2 ) + C1 *( A2 * B3 - B2 * A3 )
147
- //double det = M1[0][0]*((M1[1][1]*M1[2][2])-(M1[1][2]*M1[2][1])) + M1[0][1]*((M1[1][2]*M1[2][0])-(M1[2][2]*M1[1][0])) + M1[0][2]*((M1[1][0]*M1[2][1])-(M1[1][1]*M1[0][2]));
148
- double det = (M1 [0 ][0 ]*M1 [0 ][2 ]*M1 [2 ][2 ])+(M1 [0 ][1 ]*M1 [1 ][2 ]*M1 [2 ][0 ])+(M1 [0 ][2 ]*M1 [1 ][0 ]*M1 [1 ][2 ])-(M1 [0 ][2 ]*M1 [1 ][1 ]*M1 [0 ][2 ])-(M1 [0 ][1 ]*M1 [1 ][0 ]*M1 [2 ][2 ])-(M1 [0 ][0 ]*M1 [1 ][2 ]*M1 [2 ][1 ]);
149
- double [][]M1Inv = {
150
- {(M1 [0 ][0 ]/det ),(M1 [0 ][1 ]/det ),(M1 [0 ][2 ]/det )},
151
- {(M1 [1 ][0 ]/det ),(M1 [1 ][1 ]/det ),(M1 [1 ][2 ]/det )},
152
- {(M1 [2 ][0 ]/det ),(M1 [2 ][1 ]/det ),(M1 [2 ][2 ]/det )}
153
- };
154
-
155
- double [] tr = {
156
- M1Inv [0 ][0 ]*M3 [0 ]+M1Inv [0 ][1 ]*M3 [1 ]+M1Inv [0 ][2 ]*M3 [2 ],
157
- M1Inv [1 ][0 ]*M3 [0 ]+M1Inv [1 ][1 ]*M3 [1 ]+M1Inv [1 ][2 ]*M3 [2 ],
158
- M1Inv [2 ][0 ]*M3 [0 ]+M1Inv [2 ][1 ]*M3 [1 ]+M1Inv [2 ][2 ]*M3 [2 ]};
159
-
160
- // Ends here ************ **
161
- // Using Wikipedia γ(Gamma) replaced with G
162
-
163
- /**double L1 = ln(R1),L2 = ln(R2), L3 = ln(R3);
164
- double Y1 = 1 / T1,Y2 = 1 / T2, Y3 = 1 / T3;
165
- double G2 = ((Y2-Y1)/L2-L1), G3 = ((Y3-Y1)/(L3-L1));
166
- double C = (((G3-G2)/(L3-L2)*(1/(L1+L2+L3))));
167
- double B = G2 - C * (sq(L1) + (L1*L2) + sq(L2));
168
- double A = Y1 - (L1*(B+ sq(L1)*C));
169
- double[] tr = {A,B,C};**/
158
+ Matrix lhs = new Matrix (M1 );
159
+ Matrix rhs = new Matrix (M3 ,3 );
160
+ Matrix toReturn = lhs .solve (rhs );
161
+ double [] tr = {toReturn .get (0 ,0 ),toReturn .get (1 ,0 ),toReturn .get (2 ,0 )};
170
162
return tr ;
171
163
}
172
164
165
+ public String getTemp (double R ){
166
+ return (1 /(A + (B *ln (R )) + (C *cb (ln (R )))))+"" ;
167
+ }
168
+
173
169
174
170
public double ln (double numb ){
175
171
return Math .log (numb )/Math .log (Math .E );
176
172
}
177
-
178
- public double sq (double numb ){
179
- return numb *numb ;
180
- }
181
-
182
173
public double cb (double numb ){
183
174
return numb *numb *numb ;
184
175
}
0 commit comments