Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit 86d2b57

Browse files
committed
Update viewActivity.java
1 parent 6d4ed38 commit 86d2b57

File tree

1 file changed

+30
-39
lines changed

1 file changed

+30
-39
lines changed

app/src/main/java/io/github/sanjit1/calibrator/viewActivity.java

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import android.support.v7.app.AppCompatActivity;
66
import android.support.v7.widget.Toolbar;
77
import android.view.View;
8-
import android.widget.Button;
8+
import Jama.Matrix;
99
import android.widget.EditText;
1010
import android.widget.TextView;
1111
import android.widget.Toast;
@@ -60,6 +60,10 @@ protected void onCreate(Bundle savedInstanceState) {
6060
Btv = findViewById(R.id.B);
6161
Ctv = findViewById(R.id.C);
6262

63+
A = 90000;
64+
B = 80000;
65+
C = 60000;
66+
6367
File cache = new File((Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)) + ("/CalibratorAppData/cache"));
6468
try {
6569
FileReader cacheRead = new FileReader(cache);
@@ -112,6 +116,12 @@ void load(File ftl){
112116

113117
}
114118

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+
115125
public void enterPressed(View v){
116126
name = name_et.getText().toString();
117127
R1 = (Double.parseDouble(Res1.getText().toString()));
@@ -122,63 +132,44 @@ public void enterPressed(View v){
122132
T3 = (Double.parseDouble(Tem3.getText().toString()));
123133

124134
//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+
}
132146
}
133147

134148
public double[] coolMathGames(double R1,double R2,double R3,double T1,double T2,double T3){
135149
T1 = T1 + 273.15;
136150
T2 = T2 + 273.15;
137151
T3 = T3 + 273.15;
138-
//M1*M2 = M3 And M2 = M3*(M1/d)
139-
// /** ************My sad attempt at doing Matrices
140152
double [][] M1 = {
141153
{1,ln(R1),cb(ln(R1))},
142154
{1,ln(R2),cb(ln(R2))},
143155
{1,ln(R3),cb(ln(R3))}
144156
};
145157
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)};
170162
return tr;
171163
}
172164

165+
public String getTemp(double R){
166+
return (1/(A + (B*ln(R)) + (C*cb(ln(R)))))+"";
167+
}
168+
173169

174170
public double ln(double numb){
175171
return Math.log(numb)/Math.log(Math.E);
176172
}
177-
178-
public double sq(double numb){
179-
return numb*numb;
180-
}
181-
182173
public double cb(double numb){
183174
return numb*numb*numb;
184175
}

0 commit comments

Comments
 (0)