//Task1
float data1A[3][4] = {
{9.26, 9.38, 12.11, 10.81}, // x1
{1.37, 1.49, 1.44, 1.42}, // x2
{0.23, 0.39, 0.43, 0.18} // x3
};
float data1B[3][4] = {
{5.49, 6.61, 4.32, 7.37}, // x1
{1.10, 1.23, 1.39, 1.38}, // x2
{0.05, 0.48, 0.41, 0.62} // x3
};
float data1z[2][3] = {
{6.70, 0.79, 0.39},
{9.42, 0.70, 0.72}
};
//Task2
float data2A[3][4] = {
{9.26, 9.38, 12.11, 10.81}, // x1
{1.37, 1.49, 1.44, 1.42}, // x2
{1.45, 1.30, 1.37, 1.65} // x3
};
float data2B[3][4] = {
{5.49, 6.61, 4.32, 7.37}, // x1
{1.10, 1.23, 1.39, 1.38}, // x2
{1.02, 0.88, 0.62, 1.09} // x3
};
float data2z[2][3] = {
{6.70, 0.79, 1.24},
{9.42, 0.70, 2.03}
};
//Task3
float data3A[3][4] = {
{9.26, 9.37, 10.02, 10.81}, // x1
{0.78, 0.79, 0.76, 0.70}, // x2
{1.37, 1.24, 1.22, 1.42} // x3
};
float data3B[3][4] = {
{5.49, 6.64, 5.22, 7.37}, // x1
{0.74, 0.77, 0.79, 0.77}, // x2
{1.10, 1.35, 1.33, 1.38} // x3
};
float data3z[2][3] = {
{12.11, 0.68, 1.44},
{4.32, 0.68, 1.39}
};
//Task4
float data4A[3][4] = {
{4.0, 4.9, 6.1, 5.3}, // x1
{80.0, 78.6, 75.9, 74.0}, // x2
{6.0, 6.3, 7.0, 7.1} // x3
};
float data4B[3][4] = {
{8.7, 10.3, 11.6, 10.8}, // x1
{90.7, 94.6, 94.0, 92.5}, // x2
{9.0, 10.5, 10.9, 11.0} // x3
};
float data4z[2][3] = {
{5.5, 74.0, 6.1},
{9.7, 92.5, 11.1}
};
//Task5
float data5A[3][4] = {
{170.5, 200.0, 186.4, 154.2}, // x1
{10.0, 18.2, 15.8, 10.3}, // x2
{250.95, 380.6, 300.2, 280.36} // x3
};
float data5B[3][4] = {
{60.6, 90.8, 100.4, 85.2}, // x1
{9.0, 9.7, 8.3, 7.9}, // x2
{100.5, 147.6, 194.3, 170.2} // x3
};
float data5z[2][3] = {
{165.3, 17.2, 290.5},
{170.5, 10.0, 250.95}
};
void setup() {
Serial.begin(9600);
//Task1
DiscrAnaliz(data1A,data1B,data1z);
Serial.println();
DiscrAnaliz(data2A,data2B,data2z);
Serial.println();
DiscrAnaliz(data3A,data3B,data3z);
Serial.println();
DiscrAnaliz(data4A,data4B,data4z);
Serial.println();
DiscrAnaliz(data5A,data5B,data5z);
}
void DiscrAnaliz(float A[3][4], float B[3][4], float Z[2][3]){
float aveA[3], aveB[3], cov1[3][3], cov2[3][3],zvor[3][3], vector[3];
average(A, aveA);
average(B, aveB);
covar(A, aveA, cov1);
covar(B, aveB, cov2);
zvorot(cov1,cov2,zvor);
vectorCof(zvor,aveA,aveB,vector);
float c1 = ocinca(A, vector);
float c2 = ocinca(B, vector);
float C=(c1 + c2) / 2;
Serial.print(C);
Serial.print(" ");
ocincaZ(Z,vector);
}
void average(float arr[3][4], float res[3]){
for(int i=0; i<3; i++){
float sum = 0;
for(int j=0; j<4; j++){
sum += arr[i][j];
}
res[i] = sum / 4;
}
}
void covar(float arr[3][4], float ave[3],float res[3][3]){
for(int i=0; i<3; i++){
for(int j=0; j<3; j++){
float sum = 0;
for(int k=0; k<4; k++){
sum += (arr[i][k] - ave[i]) * (arr[j][k] - ave[j]);
}
res[i][j] = sum*0.25;
}
}
}
void zvorot(float cov1[3][3],float cov2[3][3],float res[3][3]){
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
cov1[i][j]=(cov1[i][j]*4+cov2[i][j]*4)/6;
}
}
float det=0,
a = cov1[0][0], b = cov1[0][1], c = cov1[0][2],
d = cov1[1][0], e = cov1[1][1], f = cov1[1][2],
g = cov1[2][0], h = cov1[2][1], i = cov1[2][2];
det=a*(e*i-f*h)-b*(d*i-f*g)+c*(d*h-e*g);
res[0][0] = (e*i - f*h);
res[0][1] = -(b*i - c*h);
res[0][2] = (b*f - c*e);
res[1][0] = -(d*i - f*g);
res[1][1] = (a*i - c*g);
res[1][2] = -(a*f - c*d);
res[2][0] = (d*h - e*g);
res[2][1] = -(a*h - b*g);
res[2][2] = (a*e - b*d);
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
res[i][j]/=det;
}
}
}
void vectorCof(float zvorot[3][3], float ave1[3],float ave2[3],float res[3]){
float rizn[3];
for(int i=0;i<3;i++){
rizn[i]=ave1[i]-ave2[i];
}
for(int i=0;i<3;i++){
float sum=0;
for(int j=0;j<3;j++){
sum+=(zvorot[i][j]*rizn[j]);
}
res[i]=sum;
}
}
float ocinca(float arr[3][4], float V[3]) {
float res = 0;
for(int i=0; i<4; i++) {
float sum = 0;
for(int j=0; j<3; j++) {
sum += arr[j][i] * V[j];
}
res += sum;
}
return res/4;
}
void ocincaZ(float arr[2][3],float V[3]){
float res = 0;
float sum = 0;
for(int i=0; i<2; i++) {
for(int j=0; j<3; j++) {
sum += arr[i][j] * V[j];
}
}
Serial.print(sum/2);
}
void loop() {}